
This commit includes updates that affects the build, testing, and deployment of Tile38. - The root level build.sh has been broken up into multiple scripts and placed in the "scripts" directory. - The vendor directory has been updated to follow the Go modules rules, thus `make` should work on isolated environments. Also some vendored packages may have been updated to a later version, if needed. - The Makefile has been updated to allow for making single binaries such as `make tile38-server`. There is some scaffolding during the build process, so from now on all binaries should be made using make. For example, to run a development version of the tile38-cli binary, do this: make tile38-cli && ./tile38-cli not this: go run cmd/tile38-cli/main.go - Travis.CI docker push script has been updated to address a change to Docker's JSON repo meta output, which in turn fixes a bug where new Tile38 versions were not being properly pushed to Docker
95 lines
2.0 KiB
Go
95 lines
2.0 KiB
Go
package amqp
|
|
|
|
import "sync"
|
|
|
|
// confirms resequences and notifies one or multiple publisher confirmation listeners
|
|
type confirms struct {
|
|
m sync.Mutex
|
|
listeners []chan Confirmation
|
|
sequencer map[uint64]Confirmation
|
|
published uint64
|
|
expecting uint64
|
|
}
|
|
|
|
// newConfirms allocates a confirms
|
|
func newConfirms() *confirms {
|
|
return &confirms{
|
|
sequencer: map[uint64]Confirmation{},
|
|
published: 0,
|
|
expecting: 1,
|
|
}
|
|
}
|
|
|
|
func (c *confirms) Listen(l chan Confirmation) {
|
|
c.m.Lock()
|
|
defer c.m.Unlock()
|
|
|
|
c.listeners = append(c.listeners, l)
|
|
}
|
|
|
|
// publish increments the publishing counter
|
|
func (c *confirms) Publish() uint64 {
|
|
c.m.Lock()
|
|
defer c.m.Unlock()
|
|
|
|
c.published++
|
|
return c.published
|
|
}
|
|
|
|
// confirm confirms one publishing, increments the expecting delivery tag, and
|
|
// removes bookkeeping for that delivery tag.
|
|
func (c *confirms) confirm(confirmation Confirmation) {
|
|
delete(c.sequencer, c.expecting)
|
|
c.expecting++
|
|
for _, l := range c.listeners {
|
|
l <- confirmation
|
|
}
|
|
}
|
|
|
|
// resequence confirms any out of order delivered confirmations
|
|
func (c *confirms) resequence() {
|
|
for c.expecting <= c.published {
|
|
sequenced, found := c.sequencer[c.expecting]
|
|
if !found {
|
|
return
|
|
}
|
|
c.confirm(sequenced)
|
|
}
|
|
}
|
|
|
|
// one confirms one publishing and all following in the publishing sequence
|
|
func (c *confirms) One(confirmed Confirmation) {
|
|
c.m.Lock()
|
|
defer c.m.Unlock()
|
|
|
|
if c.expecting == confirmed.DeliveryTag {
|
|
c.confirm(confirmed)
|
|
} else {
|
|
c.sequencer[confirmed.DeliveryTag] = confirmed
|
|
}
|
|
c.resequence()
|
|
}
|
|
|
|
// multiple confirms all publishings up until the delivery tag
|
|
func (c *confirms) Multiple(confirmed Confirmation) {
|
|
c.m.Lock()
|
|
defer c.m.Unlock()
|
|
|
|
for c.expecting <= confirmed.DeliveryTag {
|
|
c.confirm(Confirmation{c.expecting, confirmed.Ack})
|
|
}
|
|
c.resequence()
|
|
}
|
|
|
|
// Close closes all listeners, discarding any out of sequence confirmations
|
|
func (c *confirms) Close() error {
|
|
c.m.Lock()
|
|
defer c.m.Unlock()
|
|
|
|
for _, l := range c.listeners {
|
|
close(l)
|
|
}
|
|
c.listeners = nil
|
|
return nil
|
|
}
|