Created
January 18, 2012 01:40
-
-
Save bigtoast/1630254 to your computer and use it in GitHub Desktop.
coordination example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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