Class EffectfulActorContext<T>
- java.lang.Object
-
- akka.actor.testkit.typed.internal.StubbedActorContext<T>
-
- akka.actor.testkit.typed.internal.EffectfulActorContext<T>
-
- All Implemented Interfaces:
ClassicActorContextProvider
,ActorContextImpl<T>
,ActorContext<T>
,ActorContext<T>
,TypedActorContext<T>
public final class EffectfulActorContext<T> extends StubbedActorContext<T>
INTERNAL API
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface akka.actor.typed.internal.ActorContextImpl
ActorContextImpl.LoggingContext, ActorContextImpl.LoggingContext$
-
-
Constructor Summary
Constructors Constructor Description EffectfulActorContext(ActorPath path, scala.Function0<Behavior<T>> currentBehaviorProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelReceiveTimeout()
Cancel the sending of receive timeout notifications.java.util.concurrent.ConcurrentLinkedQueue<Effect>
effectQueue()
<U> ActorRef<U>
messageAdapter(java.lang.Class<U> messageClass, Function<U,T> f)
Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.<U> ActorRef<U>
messageAdapter(scala.Function1<U,T> f, scala.reflect.ClassTag<U> evidence$1)
Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.<U> Cancellable
scheduleOnce(scala.concurrent.duration.FiniteDuration delay, ActorRef<U> target, U message)
Schedule the sending of the given message to the given target Actor after the given time period has elapsed.void
setReceiveTimeout(scala.concurrent.duration.FiniteDuration d, T message)
Schedule the sending of a notification in case no other message is received during the given period of time.<U> ActorRef<U>
spawn(Behavior<U> behavior, java.lang.String name, Props props)
Create a child Actor from the givenBehavior
and with the given name.<U> Props
spawn$default$3()
Create a child Actor from the givenBehavior
and with the given name.<U> ActorRef<U>
spawnAnonymous(Behavior<U> behavior, Props props)
Create a child Actor from the givenBehavior
under a randomly chosen name.<U> Props
spawnAnonymous$default$2()
<U> ActorRef<U>
spawnMessageAdapter(scala.Function1<U,T> f)
INTERNAL API: SeespawnMessageAdapter
with name parameter<U> ActorRef<U>
spawnMessageAdapter(scala.Function1<U,T> f, java.lang.String name)
INTERNAL API: It is currently internal because it's too easy to create resource leaks by spawning adapters without stopping them.<U> void
stop(ActorRef<U> child)
Do not actually stop the child inbox, only simulate the liveness check.<U> void
unwatch(ActorRef<U> other)
Revoke the registration established bywatch
.<U> void
watch(ActorRef<U> other)
Register forTerminated
notification once the Actor identified by the givenActorRef
terminates.<U> void
watchWith(ActorRef<U> other, T message)
Register for termination notification with a custom message once the Actor identified by the givenActorRef
terminates.-
Methods inherited from class akka.actor.testkit.typed.internal.StubbedActorContext
child, childInbox, childInbox, children, childrenNames, childTestKit, classicActorContext, clearLog, clearUnhandled, currentBehavior, executionContext, internalSpawnMessageAdapter, log, logEntries, onUnhandled, path, removeChildInbox, self, selfInbox, setLoggerName, setLoggerName, system, toString, unhandledMessages
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface akka.actor.typed.internal.ActorContextImpl
_currentActorThread_$eq, _logging_$eq, _messageAdapters_$eq, _timer_$eq, asJava, ask, ask, asScala, cancelAllTimers, checkCurrentActorThread, clearCurrentActorThread, clearMdc, getChild, getChildren, getExecutionContext, getLog, getSelf, getSystem, hasCustomLoggerName, hasTimer, internalMessageAdapter, loggingContext, messageAdapterRef_$eq, messageAdapters, pipeToSelf, pipeToSelf, scheduleOnce, setCurrentActorThread, setReceiveTimeout, spawn, spawnAnonymous, timer
-
-
-
-
Method Detail
-
cancelReceiveTimeout
public void cancelReceiveTimeout()
Description copied from interface:ActorContext
Cancel the sending of receive timeout notifications.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.- Specified by:
cancelReceiveTimeout
in interfaceActorContext<T>
- Specified by:
cancelReceiveTimeout
in interfaceActorContext<T>
- Overrides:
cancelReceiveTimeout
in classStubbedActorContext<T>
-
effectQueue
public java.util.concurrent.ConcurrentLinkedQueue<Effect> effectQueue()
-
messageAdapter
public <U> ActorRef<U> messageAdapter(scala.Function1<U,T> f, scala.reflect.ClassTag<U> evidence$1)
Description copied from interface:ActorContext
Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.You can register several message adapters for different message classes. It's only possible to have one message adapter per message class to make sure that the number of adapters are not growing unbounded if registered repeatedly. That also means that a registered adapter will replace an existing adapter for the same message class.
A message adapter will be used if the message class matches the given class or is a subclass thereof. The registered adapters are tried in reverse order of their registration order, i.e. the last registered first.
A message adapter (and the returned
ActorRef
) has the same lifecycle as this actor. It's recommended to register the adapters in a top levelBehaviors.setup
or constructor ofAbstractBehavior
but it's possible to register them later also if needed. Message adapters don't have to be stopped since they consume no resources other than an entry in an internalMap
and the number of adapters are bounded since it's only possible to have one per message class. * The function is running in this actor and can safely access state of it.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
Future
callbacks.
-
messageAdapter
public <U> ActorRef<U> messageAdapter(java.lang.Class<U> messageClass, Function<U,T> f)
Description copied from interface:ActorContext
Create a message adapter that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor.You can register several message adapters for different message classes. It's only possible to have one message adapter per message class to make sure that the number of adapters are not growing unbounded if registered repeatedly. That also means that a registered adapter will replace an existing adapter for the same message class.
A message adapter will be used if the message class matches the given class or is a subclass thereof. The registered adapters are tried in reverse order of their registration order, i.e. the last registered first.
A message adapter (and the returned
ActorRef
) has the same lifecycle as this actor. It's recommended to register the adapters in a top levelBehaviors.setup
or constructor ofAbstractBehavior
but it's possible to register them later also if needed. Message adapters don't have to be stopped since they consume no resources other than an entry in an internalMap
and the number of adapters are bounded since it's only possible to have one per message class.The function is running in this actor and can safely access state of it.
*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.
-
scheduleOnce
public <U> Cancellable scheduleOnce(scala.concurrent.duration.FiniteDuration delay, ActorRef<U> target, U message)
Description copied from interface:ActorContext
Schedule the sending of the given message to the given target Actor after the given time period has elapsed. The scheduled action can be cancelled by invokingCancellable.cancel()
on the returned handle.This method is thread-safe and can be called from other threads than the ordinary actor message processing thread, such as
Future
callbacks.- Specified by:
scheduleOnce
in interfaceActorContext<T>
- Overrides:
scheduleOnce
in classStubbedActorContext<T>
-
setReceiveTimeout
public void setReceiveTimeout(scala.concurrent.duration.FiniteDuration d, T message)
Description copied from interface:ActorContext
Schedule the sending of a notification in case no other message is received during the given period of time. The timeout starts anew with each received message. UsecancelReceiveTimeout
to switch off this mechanism.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
Future
callbacks.- Specified by:
setReceiveTimeout
in interfaceActorContext<T>
- Overrides:
setReceiveTimeout
in classStubbedActorContext<T>
-
spawn
public <U> ActorRef<U> spawn(Behavior<U> behavior, java.lang.String name, Props props)
Description copied from interface:ActorContext
Create a child Actor from the givenBehavior
and with the given name.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.- Specified by:
spawn
in interfaceActorContext<T>
- Specified by:
spawn
in interfaceActorContext<T>
- Overrides:
spawn
in classStubbedActorContext<T>
-
spawn$default$3
public <U> Props spawn$default$3()
Description copied from interface:ActorContext
Create a child Actor from the givenBehavior
and with the given name.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
Future
callbacks.- Specified by:
spawn$default$3
in interfaceActorContext<T>
- Overrides:
spawn$default$3
in classStubbedActorContext<T>
-
spawnAnonymous
public <U> ActorRef<U> spawnAnonymous(Behavior<U> behavior, Props props)
Description copied from interface:ActorContext
Create a child Actor from the givenBehavior
under a randomly chosen name. It is good practice to name Actors wherever practical.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.- Specified by:
spawnAnonymous
in interfaceActorContext<T>
- Specified by:
spawnAnonymous
in interfaceActorContext<T>
- Overrides:
spawnAnonymous
in classStubbedActorContext<T>
-
spawnAnonymous$default$2
public <U> Props spawnAnonymous$default$2()
- Specified by:
spawnAnonymous$default$2
in interfaceActorContext<T>
- Overrides:
spawnAnonymous$default$2
in classStubbedActorContext<T>
-
spawnMessageAdapter
public <U> ActorRef<U> spawnMessageAdapter(scala.Function1<U,T> f)
Description copied from interface:ActorContext
INTERNAL API: SeespawnMessageAdapter
with name parameter
-
spawnMessageAdapter
public <U> ActorRef<U> spawnMessageAdapter(scala.Function1<U,T> f, java.lang.String name)
Description copied from interface:ActorContext
INTERNAL API: It is currently internal because it's too easy to create resource leaks by spawning adapters without stopping them.messageAdapter
is the public API.Create a "lightweight" child actor that will convert or wrap messages such that other Actor’s protocols can be ingested by this Actor. You are strongly advised to cache these ActorRefs or to stop them when no longer needed.
The name of the child actor will be composed of a unique identifier starting with a dollar sign to which the given
name
argument is appended, with an inserted hyphen between these two parts. Therefore the givenname
argument does not need to be unique within the scope of the parent actor.The function is applied inside the "parent" actor and can safely access state of the "parent".
-
stop
public <U> void stop(ActorRef<U> child)
Description copied from class:StubbedActorContext
Do not actually stop the child inbox, only simulate the liveness check. Removal is asynchronous, explicit removeInbox is needed from outside afterwards.- Specified by:
stop
in interfaceActorContext<T>
- Specified by:
stop
in interfaceActorContext<T>
- Overrides:
stop
in classStubbedActorContext<T>
-
unwatch
public <U> void unwatch(ActorRef<U> other)
Description copied from interface:ActorContext
Revoke the registration established bywatch
. ATerminated
notification will not subsequently be received for the referenced Actor.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.- Specified by:
unwatch
in interfaceActorContext<T>
- Specified by:
unwatch
in interfaceActorContext<T>
- Overrides:
unwatch
in classStubbedActorContext<T>
-
watch
public <U> void watch(ActorRef<U> other)
Description copied from interface:ActorContext
Register forTerminated
notification once the Actor identified by the givenActorRef
terminates. This message is also sent when the watched actor is on a node that has been removed from the cluster when using Akka Cluster.watch
is idempotent if it is not mixed withwatchWith
.It will fail with an
IllegalStateException
if the same subject was watched before usingwatchWith
. To clear the termination message, unwatch first.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.- Specified by:
watch
in interfaceActorContext<T>
- Specified by:
watch
in interfaceActorContext<T>
- Overrides:
watch
in classStubbedActorContext<T>
-
watchWith
public <U> void watchWith(ActorRef<U> other, T message)
Description copied from interface:ActorContext
Register for termination notification with a custom message once the Actor identified by the givenActorRef
terminates. This message is also sent when the watched actor is on a node that has been removed from the cluster when using Akka Cluster.watchWith
is idempotent if it is called with the samemsg
and not mixed withwatch
.It will fail with an
IllegalStateException
if the same subject was watched before usingwatch
orwatchWith
with another termination message. To change the termination message, unwatch first.*Warning*: This method is not thread-safe and must not be accessed from threads other than the ordinary actor message processing thread, such as
CompletionStage
callbacks.- Specified by:
watchWith
in interfaceActorContext<T>
- Specified by:
watchWith
in interfaceActorContext<T>
- Overrides:
watchWith
in classStubbedActorContext<T>
-
-