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

netflix.ocelli.executor.SimpleExecutor Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.2
Show newest version
package netflix.ocelli.executor;

import netflix.ocelli.LoadBalancer;
import rx.Observable;
import rx.functions.Func1;
import rx.functions.Func2;

/**
 * Very simple implementation of invoker that simply executes the operations 
 * without any additional retry or failover logic
 * 
 * @author elandau
 *
 * @param 
 */
public class SimpleExecutor implements Executor {

    private Observable lb;
    private final Func2> operation;
    
    public static  Func2, Func2>, Executor> factory() {
        return new Func2, Func2>, Executor>() {
            @Override
            public Executor call(LoadBalancer t1, Func2> t2) {
                return new SimpleExecutor(t1, t2);
            }
        };
    }
    public SimpleExecutor(final LoadBalancer lb, final Func2> operation) {
        this.lb = lb;
        this.operation = operation;
    }

    @Override
    public Observable call(final I request) {
        return lb.concatMap(new Func1>() {
            @Override
            public Observable call(C client) {
                return operation.call(client, request);
            }
        });
    }
    
    public static  SimpleExecutor create(LoadBalancer lb, final Func2> operation) {
        return new SimpleExecutor(lb, operation);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy