Created
February 6, 2014 08:12
-
-
Save patriknw/8840129 to your computer and use it in GitHub Desktop.
Suggestion of Java API for EventBus, see https://groups.google.com/d/msg/akka-dev/GojW1CZYXOE/fFotK9myddIJ
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
/** | |
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> | |
*/ | |
package akka.event.japi | |
/** | |
* Java API: See documentation for [[akka.event.EventBus]] | |
* E is the Event type | |
* S is the Subscriber type | |
* C is the Classifier type | |
*/ | |
trait EventBus[E, S, C] { | |
/** | |
* Attempts to register the subscriber to the specified Classifier | |
* @return true if successful and false if not (because it was already subscribed to that Classifier, or otherwise) | |
*/ | |
def subscribe(subscriber: S, to: C): Boolean | |
/** | |
* Attempts to deregister the subscriber from the specified Classifier | |
* @return true if successful and false if not (because it wasn't subscribed to that Classifier, or otherwise) | |
*/ | |
def unsubscribe(subscriber: S, from: C): Boolean | |
/** | |
* Attempts to deregister the subscriber from all Classifiers it may be subscribed to | |
*/ | |
def unsubscribe(subscriber: S): Unit | |
/** | |
* Publishes the specified Event to this bus | |
*/ | |
def publish(event: E): Unit | |
} | |
/** | |
* Java API: See documentation for [[akka.event.LookupClassification]] | |
* E is the Event type | |
* S is the Subscriber type | |
* C is the Classifier type | |
*/ | |
abstract class LookupEventBus[E, S, C] extends EventBus[E, S, C] { | |
private val bus = new akka.event.EventBus with akka.event.LookupClassification { | |
type Event = E | |
type Subscriber = S | |
type Classifier = C | |
override protected def mapSize: Int = LookupEventBus.this.mapSize | |
override protected def compareSubscribers(a: S, b: S): Int = | |
LookupEventBus.this.compareSubscribers(a, b) | |
override protected def classify(event: E): C = | |
LookupEventBus.this.classify(event) | |
override protected def publish(event: E, subscriber: S): Unit = | |
LookupEventBus.this.publish(event, subscriber) | |
} | |
/** | |
* This is a size hint for the number of Classifiers you expect to have (use powers of 2) | |
*/ | |
protected def mapSize(): Int | |
/** | |
* Provides a total ordering of Subscribers (think java.util.Comparator.compare) | |
*/ | |
protected def compareSubscribers(a: S, b: S): Int | |
/** | |
* Returns the Classifier associated with the given Event | |
*/ | |
protected def classify(event: E): C | |
/** | |
* Publishes the given Event to the given Subscriber | |
*/ | |
protected def publish(event: E, subscriber: S): Unit | |
override def subscribe(subscriber: S, to: C): Boolean = bus.subscribe(subscriber, to) | |
override def unsubscribe(subscriber: S, from: C): Boolean = bus.unsubscribe(subscriber, from) | |
override def unsubscribe(subscriber: S): Unit = bus.unsubscribe(subscriber) | |
override def publish(event: E): Unit = bus.publish(event) | |
} |
My Pleasure to write you,
My name is Favor Williams,
My email address is
( Favor24@live.com)
Am interested to know
more about you,
Contact me for my
photo and other
important issue via,
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My Pleasure to write you,
My name is Favor Williams,
My email address is
( Favor24@live.com)
Am interested to know
more about you,
Contact me for my
photo and other
important issue via,
Favor24@live.com