Created
April 18, 2010 05:26
-
-
Save debasishg/370020 to your computer and use it in GitHub Desktop.
This file contains 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
def callback(pubsub: PubSubMessage) = pubsub match { | |
case S(channel, no) => println("subscribed to " + channel + " and count = " + no) | |
case U(channel, no) => println("unsubscribed from " + channel + " and count = " + no) | |
case M(channel, msg) => | |
msg match { | |
// exit will unsubscribe from all channels and stop subscription service | |
case "exit" => | |
println("unsubscribe all ..") | |
r.unsubscribe | |
// message "+x" will subscribe to channel x | |
case x if x startsWith "+" => | |
val s: Seq[Char] = x | |
s match { | |
case Seq('+', rest @ _*) => r.subscribe(rest.toString){ m => } | |
} | |
// message "-x" will unsubscribe from channel x | |
case x if x startsWith "-" => | |
val s: Seq[Char] = x | |
s match { | |
case Seq('-', rest @ _*) => r.unsubscribe(rest.toString) | |
} | |
// other message receive | |
case x => | |
println("received message on channel " + channel + " as : " + x) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment