All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.droidkit.actors.dispatch.AbstractDispatcher Maven / Gradle / Ivy

Go to download

DroidKit Actors is simple actor model implementation for java and Android

There is a newer version: 0.6.1
Show newest version
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() {

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy