2013-11-10 09:31:50 +00:00
|
|
|
package sequence
|
|
|
|
|
2014-04-17 06:43:27 +00:00
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
)
|
2013-11-10 09:31:50 +00:00
|
|
|
|
|
|
|
// just for testing
|
|
|
|
type MemorySequencer struct {
|
2014-04-17 06:43:27 +00:00
|
|
|
counter uint64
|
|
|
|
sequenceLock sync.Mutex
|
2013-11-10 09:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewMemorySequencer() (m *MemorySequencer) {
|
|
|
|
m = &MemorySequencer{counter: 1}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MemorySequencer) NextFileId(count int) (uint64, int) {
|
2014-04-17 06:43:27 +00:00
|
|
|
m.sequenceLock.Lock()
|
|
|
|
defer m.sequenceLock.Unlock()
|
2013-11-10 09:31:50 +00:00
|
|
|
ret := m.counter
|
|
|
|
m.counter += uint64(count)
|
|
|
|
return ret, count
|
|
|
|
}
|
2014-04-17 06:43:27 +00:00
|
|
|
|
|
|
|
func (m *MemorySequencer) SetMax(seenValue uint64) {
|
|
|
|
m.sequenceLock.Lock()
|
|
|
|
defer m.sequenceLock.Unlock()
|
|
|
|
if m.counter <= seenValue {
|
|
|
|
m.counter = seenValue + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MemorySequencer) Peek() uint64 {
|
|
|
|
return m.counter
|
|
|
|
}
|