org.nustaq.kontraktor.routers.Routing Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kontraktor Show documentation
Show all versions of kontraktor Show documentation
a light weight, efficient actor lib
The newest version!
package org.nustaq.kontraktor.routers;
import org.nustaq.kontraktor.Actor;
import org.nustaq.kontraktor.IPromise;
import org.nustaq.kontraktor.Promise;
import org.nustaq.kontraktor.remoting.base.ActorPublisher;
import org.nustaq.kontraktor.remoting.base.ConnectableActor;
import java.util.function.Consumer;
import static org.nustaq.kontraktor.Actors.AsActor;
import static org.nustaq.kontraktor.Actors.promise;
import static org.nustaq.kontraktor.routers.AbstractKrouter.CLIENT_PING_INTERVAL_MS;
/**
* main entrance point for sarting Krouters, clients and services
*/
public class Routing {
//////////////////////////////////////////////////// static API /////////////////////////////////////////////
//
//
/**
* start a Krouter
* @param krouterClass
* @param publisher
* @param
* @return
*/
public static T start(Class krouterClass, ActorPublisher... publisher) {
T res = AsActor(krouterClass);
res.init();
for (int i = 0; i < publisher.length; i++) {
ActorPublisher actorPublisher = publisher[i].facade(res);
actorPublisher.publish( act -> {
res.handleServiceDiscon(act);
});
}
return res;
}
/**
* connect a client to a remote Krouter
*
* @param connectable - the krouter to connect
* @param disconnectCallback
* @return
*/
protected static Actor pinger;
protected static Actor getPinger() {
synchronized (AbstractKrouter.class) {
if ( pinger == null ) {
pinger = AsActor(Actor.class);
}
return pinger;
}
}
public static IPromise