github.com/Cloud-Foundations/Dominator@v0.3.4/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  	data                Stats
    35  	newest              *objectType // For unused objects only.
    36  	objects             map[hash.Hash]*objectType
    37  	oldest              *objectType // For unused objects only.
    38  }
    39  
    40  type Stats struct {
    41  	CachedBytes      uint64 // Includes LruBytes.
    42  	DownloadingBytes uint64 // Objects being downloaded and cached.
    43  	LruBytes         uint64 // Cached but not in-use objects.
    44  
    45  }
    46  
    47  func NewObjectServer(baseDir string, maxCachedBytes uint64,
    48  	objectServerAddress string, logger log.DebugLogger) (*ObjectServer, error) {
    49  	return newObjectServer(baseDir, maxCachedBytes, objectServerAddress, logger)
    50  }
    51  
    52  func (objSrv *ObjectServer) FetchObjects(hashes []hash.Hash) error {
    53  	return objSrv.fetchObjects(hashes)
    54  }
    55  
    56  func (objSrv *ObjectServer) GetObjects(hashes []hash.Hash) (
    57  	objectserver.ObjectsReader, error) {
    58  	return objSrv.getObjects(hashes)
    59  }
    60  
    61  func (objSrv *ObjectServer) GetStats() Stats {
    62  	return objSrv.getStats(true)
    63  }
    64  
    65  func (objSrv *ObjectServer) LinkObject(filename string,
    66  	hashVal hash.Hash) (bool, error) {
    67  	return objSrv.linkObject(filename, hashVal)
    68  }
    69  
    70  func (objSrv *ObjectServer) WriteHtml(writer io.Writer) {
    71  	objSrv.writeHtml(writer)
    72  }