org.jetlang.channels.BaseSubscription Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jetlang Show documentation
Show all versions of jetlang Show documentation
Jetlang provides a high performance java threading library. It is a complement to the java.util.concurrent
package introduced in 1.5 and should be used for message based concurrency similar to event based actors in
Scala.
The newest version!
package org.jetlang.channels;
import org.jetlang.core.DisposingExecutor;
import org.jetlang.core.Filter;
/**
* Base implementation for all producer thread subscriptions.
*/
public abstract class BaseSubscription implements Subscribable {
private final Filter _filter;
private final DisposingExecutor fiber;
public BaseSubscription(DisposingExecutor fiber) {
this.fiber = fiber;
_filter = null;
}
protected BaseSubscription(DisposingExecutor fiber, Filter _filter) {
this._filter = _filter;
this.fiber = fiber;
}
public DisposingExecutor getQueue() {
return fiber;
}
/**
* Receives the event, filters, and passes to handler.
*/
public void onMessage(T msg) {
if (_filter == null || _filter.passes(msg)) {
onMessageOnProducerThread(msg);
}
}
protected abstract void onMessageOnProducerThread(T msg);
}