public class AkkaUtils extends Object
Constructor and Description |
---|
AkkaUtils() |
Modifier and Type | Method and Description |
---|---|
static akka.actor.ActorSystem |
createActorSystem(com.typesafe.config.Config akkaConfig)
Creates an actor system with the given akka config.
|
static akka.actor.ActorSystem |
createActorSystem(Configuration configuration,
scala.Option<scala.Tuple2<String,Object>> listeningAddress)
Creates an actor system.
|
static akka.actor.ActorSystem |
createDefaultActorSystem()
Creates an actor system with the default config and listening on a random port of the
localhost.
|
static akka.actor.ActorSystem |
createLocalActorSystem(Configuration configuration)
Creates a local actor system without remoting.
|
static akka.actor.ActorRef |
getActorRef(String path,
akka.actor.ActorSystem system,
scala.concurrent.duration.FiniteDuration timeout)
Returns an
ActorRef for the actor specified by the path parameter. |
static scala.concurrent.Future<akka.actor.ActorRef> |
getActorRefFuture(String path,
akka.actor.ActorSystem system,
scala.concurrent.duration.FiniteDuration timeout)
Returns a
Future to the ActorRef of an actor. |
static akka.actor.Address |
getAddress(akka.actor.ActorSystem system)
Returns the address of the given
ActorSystem . |
static com.typesafe.config.Config |
getAkkaConfig(Configuration configuration,
scala.Option<scala.Tuple2<String,Object>> listeningAddress)
Creates an akka config with the provided configuration values.
|
static String |
getAkkaURL(akka.actor.ActorSystem system,
akka.actor.ActorRef actor)
Returns the given
ActorRef 's path string representation with host and port of the
ActorSystem in which the actor is running. |
static String |
getAkkaURL(akka.actor.ActorSystem system,
String path)
Returns the AkkaURL for a given
ActorSystem and a path describing a running Actor in
the actor system. |
static scala.concurrent.Future<akka.actor.ActorRef> |
getChild(akka.actor.ActorRef parent,
String child,
akka.actor.ActorSystem system,
scala.concurrent.duration.FiniteDuration timeout)
Returns a
Future to the ActorRef of the child of a given actor. |
static scala.concurrent.duration.FiniteDuration |
getClientTimeout(Configuration config) |
static com.typesafe.config.Config |
getDefaultAkkaConfig()
Creates the default akka configuration which listens on a random port on the local machine.
|
static scala.concurrent.duration.FiniteDuration |
getDefaultClientTimeout() |
static scala.concurrent.duration.FiniteDuration |
getDefaultLookupTimeout() |
static scala.concurrent.duration.FiniteDuration |
getDefaultTimeout() |
static InetSocketAddress |
getInetSockeAddressFromAkkaURL(String akkaURL)
Extracts the hostname and the port of the remote actor system from the given Akka URL.
|
static String |
getLogLevel() |
static scala.concurrent.duration.FiniteDuration |
getLookupTimeout(Configuration config) |
static scala.concurrent.duration.FiniteDuration |
getTimeout(Configuration config) |
static scala.concurrent.duration.FiniteDuration |
INF_TIMEOUT() |
static org.slf4j.Logger |
LOG() |
static scala.concurrent.Future<Object> |
retry(akka.actor.ActorRef target,
Object message,
int tries,
scala.concurrent.ExecutionContext executionContext,
scala.concurrent.duration.FiniteDuration timeout)
Utility function to construct a future which tries multiple times to execute itself if it
fails.
|
static <T> scala.concurrent.Future<T> |
retry(Callable<T> callable,
int tries,
scala.concurrent.ExecutionContext executionContext)
Utility function to construct a future which tries multiple times to execute itself if it
fails.
|
static <T> scala.concurrent.Future<T> |
retry(scala.Function0<T> body,
int tries,
scala.concurrent.ExecutionContext executionContext)
Utility function to construct a future which tries multiple times to execute itself if it
fails.
|
public static org.slf4j.Logger LOG()
public static scala.concurrent.duration.FiniteDuration INF_TIMEOUT()
public static akka.actor.ActorSystem createLocalActorSystem(Configuration configuration)
configuration
- instance containing the user provided configuration valuespublic static akka.actor.ActorSystem createActorSystem(Configuration configuration, scala.Option<scala.Tuple2<String,Object>> listeningAddress)
configuration
- instance containing the user provided configuration valueslisteningAddress
- an optional tuple containing a hostname and a port to bind to. If the
parameter is None, then a local actor system will be created.public static akka.actor.ActorSystem createActorSystem(com.typesafe.config.Config akkaConfig)
akkaConfig
- configuration for the actor systempublic static akka.actor.ActorSystem createDefaultActorSystem()
public static com.typesafe.config.Config getAkkaConfig(Configuration configuration, scala.Option<scala.Tuple2<String,Object>> listeningAddress)
configuration
- instance containing the user provided configuration valueslisteningAddress
- optional tuple of hostname and port to listen on. If None is given,
then an Akka config for local actor system will be returnedpublic static com.typesafe.config.Config getDefaultAkkaConfig()
public static String getLogLevel()
public static scala.concurrent.Future<akka.actor.ActorRef> getChild(akka.actor.ActorRef parent, String child, akka.actor.ActorSystem system, scala.concurrent.duration.FiniteDuration timeout)
Future
to the ActorRef
of the child of a given actor. The child is specified
by providing its actor name.
parent
- ActorRef
to the parent of the child to be retrievedchild
- Name of the child actorsystem
- ActorSystem
to be usedtimeout
- Maximum timeout for the futureFuture
to the ActorRef
of the child actorpublic static scala.concurrent.Future<akka.actor.ActorRef> getActorRefFuture(String path, akka.actor.ActorSystem system, scala.concurrent.duration.FiniteDuration timeout)
Future
to the ActorRef
of an actor. The actor is specified by its path.
path
- Path to the actor to be retrievedsystem
- ActorSystem
to be usedtimeout
- Maximum timeout for the futureFuture
to the ActorRef
of the actorpublic static akka.actor.ActorRef getActorRef(String path, akka.actor.ActorSystem system, scala.concurrent.duration.FiniteDuration timeout)
ActorRef
for the actor specified by the path parameter.
path
- Path to the actor to be retrievedsystem
- ActorSystem
to be usedtimeout
- Maximum timeout for the futureActorRef
of the requested Actor
IOException
public static <T> scala.concurrent.Future<T> retry(scala.Function0<T> body, int tries, scala.concurrent.ExecutionContext executionContext)
body
- function describing the future actiontries
- number of maximum tries before the future failsexecutionContext
- which shall execute the futurepublic static <T> scala.concurrent.Future<T> retry(Callable<T> callable, int tries, scala.concurrent.ExecutionContext executionContext)
callable
- future actiontries
- maximum number of tries before the future failsexecutionContext
- which shall execute the futurepublic static scala.concurrent.Future<Object> retry(akka.actor.ActorRef target, Object message, int tries, scala.concurrent.ExecutionContext executionContext, scala.concurrent.duration.FiniteDuration timeout)
target
- actor which receives the messagemessage
- to be sent to the target actortries
- maximum number of tries before the future failsexecutionContext
- which shall execute the futuretimeout
- of the futurepublic static scala.concurrent.duration.FiniteDuration getTimeout(Configuration config)
public static scala.concurrent.duration.FiniteDuration getDefaultTimeout()
public static scala.concurrent.duration.FiniteDuration getLookupTimeout(Configuration config)
public static scala.concurrent.duration.FiniteDuration getDefaultLookupTimeout()
public static scala.concurrent.duration.FiniteDuration getClientTimeout(Configuration config)
public static scala.concurrent.duration.FiniteDuration getDefaultClientTimeout()
public static akka.actor.Address getAddress(akka.actor.ActorSystem system)
ActorSystem
. The Address
object contains
the port and the host under which the actor system is reachable
system
- ActorSystem
for which the Address
shall be retrievedAddress
of the given ActorSystem
public static String getAkkaURL(akka.actor.ActorSystem system, akka.actor.ActorRef actor)
ActorRef
's path string representation with host and port of the
ActorSystem
in which the actor is running.
system
- ActorSystem
in which the given ActorRef
is runningactor
- ActorRef
of the Actor
for which the URL has to be generatedActorSystem
independent URL of the Actor
public static String getAkkaURL(akka.actor.ActorSystem system, String path)
ActorSystem
and a path describing a running Actor
in
the actor system.
system
- ActorSystem
in which the given Actor
is runningpath
- Path describing an Actor
for which the URL has to be generatedActorSystem
independent URL of an Actor
specified by
path.public static InetSocketAddress getInetSockeAddressFromAkkaURL(String akkaURL)
InetSocketAddress
instance containing the extracted hostname and port. If
the Akka URL does not contain the hostname and port information, e.g. a local Akka URL is
provided, then an Exception
is thrown.
akkaURL
- The URL to extract the host and port from.Exception
- Thrown, if the given string does not represent a proper urlCopyright © 2014–2017 The Apache Software Foundation. All rights reserved.