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:
  • Field Details

    • SERVICE_UNAVAILABLE

      public static final String SERVICE_UNAVAILABLE
      See Also:
    • CLIENT_PING_INTERVAL_MS

      public static long CLIENT_PING_INTERVAL_MS
      client connection loss detection can be slow (just needed for resource cleanup)
    • timeoutMap

      protected HashMap<Object,Long> timeoutMap
    • clients

      protected HashMap<String,ConnectionRegistry> clients
    • nextAliveRemoteActors

      protected Set<Long> nextAliveRemoteActors
    • lastSwitch

      protected long lastSwitch
  • Constructor Details

    • AbstractKrouter

      public AbstractKrouter()
  • Method Details

    • router$RegisterService

      public IPromise router$RegisterService(Actor remoteRef, boolean stateful)
    • isStateful

      protected boolean isStateful()
    • router$handleServiceDisconnect

      public abstract void router$handleServiceDisconnect(Actor disconnected)
    • router$clientPing

      public IPromise<Long> router$clientPing(long tim, long[] publishedActorIds)
      Description copied from class: Actor
      a krouter client should ping using this method.
      Overrides:
      router$clientPing in class Actor<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: Actor
      called if a message invokation from remote is received
      Overrides:
      __dispatchRemoteCall in class Actor<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

      protected void sendFailoverNotification(ConnectionRegistry clientRemoteRegistry)
    • sendFailoverNotificationInternal

      protected void sendFailoverNotificationInternal(ConnectionRegistry registry)
    • getServices

      protected abstract List<Actor> 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

      protected void handleServiceDiscon(Actor remoteRef)
    • hasBeenUnpublished

      public void hasBeenUnpublished(String connectionIdentifier)
      Description copied from interface: RemotedActor
      notification 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:
      hasBeenUnpublished in interface RemotedActor
    • clientConnected

      public void clientConnected(ConnectionRegistry connectionRegistry, String connectionIdentifier)
      Specified by:
      clientConnected in interface ServingActor
    • clientDisconnected

      public void clientDisconnected(ConnectionRegistry connectionRegistry, String connectionIdentifier)
      Specified by:
      clientDisconnected in interface ServingActor