Package org.nustaq.kontraktor.routers
Class AbstractKrouter<T extends AbstractKrouter>
java.lang.Object
org.nustaq.kontraktor.Actors
org.nustaq.kontraktor.Actor<T>
org.nustaq.kontraktor.routers.AbstractKrouter<T>
- All Implemented Interfaces:
Serializable,Executor,Monitorable,RemotedActor,ServingActor
- Direct Known Subclasses:
HotHotFailoverKrouter,Krouter,SingleActiveServiceKrouter
public abstract class AbstractKrouter<T extends AbstractKrouter>
extends Actor<T>
implements RemotedActor, ServingActor
base class for load balancers and failover proxies.
Krouters are designed to run as standalone processes (similar e.g. nginx).
ServiceActors connect and register actively to be available. Clients connect to
the Krouter which then forwards/dispatches remote messages and results depending
on implemented strategy.
This way services are protected against any malicious attacks as they don't even
accept connections from the network (they are clients of the Krouter, the Krouter has no
prior knowledge of address of the krouter's address. E.g. its possible to have a public Krouter
running in the cloud and run the service behind a firewall (or even http proxy).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.nustaq.kontraktor.Actor
Actor.ActorReport -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic longclient connection loss detection can be slow (just needed for resource cleanup)protected HashMap<String,ConnectionRegistry> protected longstatic final StringFields inherited from class org.nustaq.kontraktor.Actor
__cbQueue, __clientConnection, __connections, __currentDispatcher, __mailbox, __mailboxCapacity, __mbCapacity, __publishTarget, __remoteId, __scheduler, __self, __stopped, __ticketMachine, connection, sender, userData, zzRoutingGCEnabled, zzServerMsgCallbackFields inherited from class org.nustaq.kontraktor.Actors
CONT, DEFAULT_TIMOUT, defaultScheduler, delayedCalls, exec, instance, MAX_EXTERNAL_THREADS_POOL_SIZE, version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean__dispatchRemoteCall(ObjectSocket objSocket, RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry, List<IPromise> createdFutures, Object authContext, BiFunction<Actor, String, Boolean> callInterceptor, long delayCode) called if a message invokation from remote is receivedvoidvoidclientConnected(ConnectionRegistry connectionRegistry, String connectionIdentifier) voidclientDisconnected(ConnectionRegistry connectionRegistry, String connectionIdentifier) protected RemoteCallEntrycreateErrorPromiseResponse(RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry) protected abstract booleandispatchRemoteCall(RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry) dispatch call to a service.protected voidforwardCall(RemoteCallEntry rce, Actor remoteRef, ConnectionRegistry clientRemoteRegistry) protected voidforwardCallInternal(RemoteCallEntry rce, Actor remoteRef, ConnectionRegistry clientRemoteRegistry) protected voidforwardMultiCall(RemoteCallEntry rce, Actor remoteRef, ConnectionRegistry clientRemoteRegistry, boolean[] done, Callback[] selected) protected voidforwardMultiCallInternal(RemoteCallEntry rceIn, Actor remoteRef, ConnectionRegistry clientRemoteRegistry, boolean[] done, Callback[] selected) protected longprotected longprotected voidhandleServiceDiscon(Actor remoteRef) voidhasBeenUnpublished(String connectionIdentifier) notification method called once an actor has been unpublished.voidinit()protected booleanvoidrouter$clientPing(long tim, long[] publishedActorIds) a krouter client should ping using this method.abstract voidrouter$handleServiceDisconnect(Actor disconnected) router$RegisterService(Actor remoteRef, boolean stateful) protected voidsendFailoverNotification(ConnectionRegistry clientRemoteRegistry) protected voidMethods inherited from class org.nustaq.kontraktor.Actor
__addDeadLetter, __addRemoteConnection, __addStopHandler, __enqueueCall, __getCachedMethod, __removeRemoteConnection, __stop, __stopImpl, __submit, ask, askMsg, asyncstop, checkThread, close, closeCurrentClient, current, cyclic, debounce, delayed, execInThreadPool, execute, getActor, getActorRef, getCallbackSize, getConnections, getCurrentDispatcher, getFactory, getMailboxSize, getQSizes, getReport, getScheduler, getSubMonitorables, getUntypedRef, hasStopped, inside, inThread, isCallbackQPressured, isEmpty, isMailboxPressured, isProxy, isPublished, isRemote, isStopped, ping, self, serialOn, setServerMsgCallback, stop, stopSafeClose, tell, tellMsg, unpublish, zzkrouterLostClient, zzRoutingRefGCMethods inherited from class org.nustaq.kontraktor.Actors
AddDeadLetter, all, all, all, allMapped, AsActor, AsActor, AsActor, AsActor, AsUntypedActor, awaitAll, awaitAll, awaitAll, awaitAll, complete, complete, DeadLetters, flow, InThread, isComplete, isCont, isError, isErrorOrComplete, isResult, isTimeout, kYield, kYield, promise, race, race, reject, resolve, resolve, stream, SubmitDelayed, yieldCallbacksMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.nustaq.kontraktor.remoting.base.RemotedActor
hasBeenPublished
-
Field Details
-
SERVICE_UNAVAILABLE
- See Also:
-
CLIENT_PING_INTERVAL_MS
public static long CLIENT_PING_INTERVAL_MSclient connection loss detection can be slow (just needed for resource cleanup) -
timeoutMap
-
clients
-
nextAliveRemoteActors
-
lastSwitch
protected long lastSwitch
-
-
Constructor Details
-
AbstractKrouter
public AbstractKrouter()
-
-
Method Details
-
router$RegisterService
-
isStateful
protected boolean isStateful() -
router$handleServiceDisconnect
-
router$clientPing
Description copied from class:Actora krouter client should ping using this method.- Overrides:
router$clientPingin classActor<T extends AbstractKrouter>publishedActorIds- - published actors of sender- Returns:
-
init
public void init() -
__dispatchRemoteCall
public boolean __dispatchRemoteCall(ObjectSocket objSocket, RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry, List<IPromise> createdFutures, Object authContext, BiFunction<Actor, String, Boolean> callInterceptor, long delayCode) Description copied from class:Actorcalled if a message invokation from remote is received- Overrides:
__dispatchRemoteCallin classActor<T extends AbstractKrouter>- Returns:
- true if a new promise has been created
-
pingServices
public void pingServices() -
checkPingOnClients
public void checkPingOnClients() -
getServicePingTimeout
protected long getServicePingTimeout() -
getClientPingTimeout
protected long getClientPingTimeout() -
sendFailoverNotification
-
sendFailoverNotificationInternal
-
getServices
-
createErrorPromiseResponse
protected RemoteCallEntry createErrorPromiseResponse(RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry) -
forwardMultiCall
protected void forwardMultiCall(RemoteCallEntry rce, Actor remoteRef, ConnectionRegistry clientRemoteRegistry, boolean[] done, Callback[] selected) -
forwardMultiCallInternal
protected void forwardMultiCallInternal(RemoteCallEntry rceIn, Actor remoteRef, ConnectionRegistry clientRemoteRegistry, boolean[] done, Callback[] selected) -
dispatchRemoteCall
protected abstract boolean dispatchRemoteCall(RemoteCallEntry rce, ConnectionRegistry clientRemoteRegistry) dispatch call to a service. (use forwardXX to send)- Parameters:
rce-clientRemoteRegistry-- Returns:
- return false in case call could not be dispatched
-
forwardCall
protected void forwardCall(RemoteCallEntry rce, Actor remoteRef, ConnectionRegistry clientRemoteRegistry) -
forwardCallInternal
protected void forwardCallInternal(RemoteCallEntry rce, Actor remoteRef, ConnectionRegistry clientRemoteRegistry) -
handleServiceDiscon
-
hasBeenUnpublished
Description copied from interface:RemotedActornotification method called once an actor has been unpublished. E.g. in case of a ClientSession role actor, this will be called once the client disconnects or times out- Specified by:
hasBeenUnpublishedin interfaceRemotedActor
-
clientConnected
- Specified by:
clientConnectedin interfaceServingActor
-
clientDisconnected
- Specified by:
clientDisconnectedin interfaceServingActor
-