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

com.zipwhip.concurrent.DifferentExecutorObserverAdapter Maven / Gradle / Ivy

The newest version!
package com.zipwhip.concurrent;

import com.zipwhip.events.Observer;
import com.zipwhip.executors.SimpleExecutor;

import java.util.concurrent.Executor;

/**
 * Created with IntelliJ IDEA.
 * User: Michael
 * Date: 9/8/12
 * Time: 11:36 AM
 *
 * For converting to a different executor.
 */
public class DifferentExecutorObserverAdapter implements Observer {

    final Observer observer;
    final Executor executor;

    public DifferentExecutorObserverAdapter(Observer observer) {
        this.executor = SimpleExecutor.getInstance();
        this.observer = observer;
    }

    public DifferentExecutorObserverAdapter(Executor executor, Observer observer) {
        this.observer = observer;

        if (executor == null){
            executor = SimpleExecutor.getInstance();
        }
        this.executor = executor;
    }

    @Override
    public void notify(final Object sender, final T item) {
        executor.execute(new Runnable() {
            @Override
            public void run() {
                observer.notify(sender, item);
            }

            @Override
            public String toString() {
                return observer.toString();
            }
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy