2019-07-17 22:25:42 +00:00
|
|
|
package publisher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2019-08-27 12:04:15 +00:00
|
|
|
type persistence struct {
|
2019-07-17 22:25:42 +00:00
|
|
|
lastAcksMutex sync.Mutex
|
2019-08-27 12:04:15 +00:00
|
|
|
lastPublished int64
|
2019-07-17 22:25:42 +00:00
|
|
|
lastAcks map[string]int64
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:04:15 +00:00
|
|
|
func newPersistence() *persistence {
|
|
|
|
return &persistence{
|
2019-07-17 22:25:42 +00:00
|
|
|
lastAcks: make(map[string]int64),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 12:04:15 +00:00
|
|
|
func (s *persistence) getLastPublished() int64 {
|
|
|
|
return s.lastPublished
|
2019-07-17 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 12:04:15 +00:00
|
|
|
func (s *persistence) setLastPublished(lastPublished int64) {
|
|
|
|
s.lastPublished = lastPublished
|
2019-07-17 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 12:04:15 +00:00
|
|
|
func (s *persistence) lastAck(identity []byte) int64 {
|
2019-07-17 22:25:42 +00:00
|
|
|
s.lastAcksMutex.Lock()
|
|
|
|
defer s.lastAcksMutex.Unlock()
|
2019-08-27 12:04:15 +00:00
|
|
|
return s.lastAcks[hex.EncodeToString(identity)]
|
2019-07-17 22:25:42 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 12:04:15 +00:00
|
|
|
func (s *persistence) setLastAck(identity []byte, lastAck int64) {
|
2019-07-17 22:25:42 +00:00
|
|
|
s.lastAcksMutex.Lock()
|
|
|
|
defer s.lastAcksMutex.Unlock()
|
|
|
|
s.lastAcks[hex.EncodeToString(identity)] = lastAck
|
|
|
|
}
|