Skip to content

Instantly share code, notes, and snippets.

@bigtoast
Created January 18, 2012 01:40
Show Gist options
  • Save bigtoast/1630254 to your computer and use it in GitHub Desktop.
Save bigtoast/1630254 to your computer and use it in GitHub Desktop.
coordination example
class AvailablePool extends Actor {
var coordinationSequence = 0
var allocatorSequence = 0
var pool = 100
def receive = {
case Get(count, coordSeq) if count <= pool =>
if ( coordSeq >= coodinationSequence )
coordinationSequence = coordSeq
coordinationSequence = coordinationSequence + 1
pool = pool - count
self.channel ! Inventory(count, coordinationSequence )
}
}
class InventoryAllocator( availablePool :ActorRef, eventStore :EventStore ) extends Actor {
var coordinationSequence = 0
var allocatorSequence = 0
def receive = {
case AllocateInventory(count) =>
val result = ( availablePool ? Get( count, coordinationSequence ).mapTo[Inventory].get
coordinationSequence = result.coordinationSequence
allocatorSequence = allocatorSequence + 1
eventStore.persist( InventoryAllocated( id, count, coordinationSequence, allocatorSequence )
self.channel ! Response(..., event)// yada yada
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment