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