github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/lib/objectserver/cachingreader/api.go (about)

     1  package cachingreader
     2  
     3  import (
     4  	"io"
     5  	"sync"
     6  	"time"
     7  
     8  	"github.com/Cloud-Foundations/Dominator/lib/hash"
     9  	"github.com/Cloud-Foundations/Dominator/lib/log"
    10  	"github.com/Cloud-Foundations/Dominator/lib/objectserver"
    11  )
    12  
    13  type objectType struct {
    14  	hash               hash.Hash
    15  	size               uint64
    16  	newer              *objectType
    17  	older              *objectType
    18  	usageCount         uint
    19  	downloadingChannel <-chan struct{} // Closed then set to nil when finished.
    20  }
    21  
    22  type downloadingObject struct {
    23  	size uint64
    24  }
    25  
    26  type ObjectServer struct {
    27  	baseDir             string
    28  	flushTimer          *time.Timer
    29  	logger              log.DebugLogger
    30  	lruUpdateNotifier   chan<- struct{}
    31  	maxCachedBytes      uint64
    32  	objectServerAddress string
    33  	rwLock              sync.RWMutex // Protect the following fields.
    34  	cachedBytes         uint64       // Includes lruBytes.
    35  	downloadingBytes    uint64       // Objects being downloaded and cached.
    36  	lruBytes            uint64       // Cached but not in-use objects.
    37  	newest              *objectType  // For unused objects only.
    38  	objects             map[hash.Hash]*objectType
    39  	oldest              *objectType // For unused objects only.
    40  }
    41  
    42  func NewObjectServer(baseDir string, maxCachedBytes uint64,
    43  	objectServerAddress string, logger log.DebugLogger) (*ObjectServer, error) {
    44  	return newObjectServer(baseDir, maxCachedBytes, objectServerAddress, logger)
    45  }
    46  
    47  func (objSrv *ObjectServer) FetchObjects(hashes []hash.Hash) error {
    48  	return objSrv.fetchObjects(hashes)
    49  }
    50  
    51  func (objSrv *ObjectServer) GetObjects(hashes []hash.Hash) (
    52  	objectserver.ObjectsReader, error) {
    53  	return objSrv.getObjects(hashes)
    54  }
    55  
    56  func (objSrv *ObjectServer) LinkObject(filename string,
    57  	hashVal hash.Hash) (bool, error) {
    58  	return objSrv.linkObject(filename, hashVal)
    59  }
    60  
    61  func (objSrv *ObjectServer) WriteHtml(writer io.Writer) {
    62  	objSrv.writeHtml(writer)
    63  }