Created
August 3, 2011 15:14
-
-
Save seanparsons/1122882 to your computer and use it in GitHub Desktop.
Quick example of a payment process done with Akka.
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
import akka.actor._ | |
import akka.actor.Actor._ | |
case class StartPayment(provider: String) | |
case class CompletePayment(provider: String) | |
case class PaymentProcess(userId: Int) extends Actor { | |
var currentProvider: String = _ | |
def receive = { | |
case StartPayment(provider) => { | |
currentProvider = provider | |
println("Start payment: " + provider) | |
} | |
case CompletePayment(provider) => { | |
if (currentProvider == provider) println("Successfully completed payment with " + provider) | |
else println("You're doing it wrong.") | |
currentProvider = null | |
} | |
} | |
} | |
val user1PaymentActor = actorOf(new PaymentProcess(1)).start() | |
user1PaymentActor ! StartPayment("Bank Awesome"); user1PaymentActor ! CompletePayment("Dave's Bank"); user1PaymentActor ! StartPayment("Bank Awesome"); user1PaymentActor ! CompletePayment("Bank Awesome") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment