com.droidkit.actors.dispatch.AbstractDispatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of actors Show documentation
Show all versions of actors Show documentation
DroidKit Actors is simple actor model implementation for java and Android
package com.droidkit.actors.dispatch;
/**
* Abstract thread dispatcher for messages
*/
public abstract class AbstractDispatcher> {
final private Q queue;
final Dispatch dispatch;
protected AbstractDispatcher(Q queue, Dispatch dispatch) {
this.queue = queue;
this.dispatch = dispatch;
this.queue.setListener(new QueueListener() {
@Override
public void onQueueChanged() {
notifyDispatcher();
}
});
}
/**
* Queue used for dispatching
*
* @return queue
*/
public Q getQueue() {
return queue;
}
/**
* Actual execution of action
*
* @param message action
*/
protected void dispatchMessage(T message) {
if (dispatch != null) {
dispatch.dispatchMessage(message);
}
}
/**
* Notification about queue change
*/
protected void notifyDispatcher() {
}
}