ActorContext.getParent for Java API #22413
This commit is contained in:
parent
5ff44194a3
commit
2eb226ed32
213 changed files with 1319 additions and 1523 deletions
|
|
@ -23,13 +23,13 @@ import akka.actor.AbstractActor.Receive;
|
|||
* public Actor() {
|
||||
* receive(ReceiveBuilder.
|
||||
* match(Double.class, d -> {
|
||||
* sender().tell(d.isNaN() ? 0 : d, self());
|
||||
* getSender().tell(d.isNaN() ? 0 : d, self());
|
||||
* }).
|
||||
* match(Integer.class, i -> {
|
||||
* sender().tell(i * 10, self());
|
||||
* getSender().tell(i * 10, self());
|
||||
* }).
|
||||
* match(String.class, s -> s.startsWith("foo"), s -> {
|
||||
* sender().tell(s.toUpperCase(), self());
|
||||
* getSender().tell(s.toUpperCase(), self());
|
||||
* }).build()
|
||||
* );
|
||||
* }
|
||||
|
|
|
|||
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
package akka.actor
|
||||
|
||||
import akka.annotation.ApiMayChange
|
||||
import akka.annotation.{ ApiMayChange, DoNotInherit }
|
||||
import akka.japi.pf.ReceiveBuilder
|
||||
import akka.japi.pf.UnitPFBuilder
|
||||
|
||||
import scala.runtime.BoxedUnit
|
||||
import java.util.Optional
|
||||
|
||||
|
|
@ -39,7 +40,10 @@ object AbstractActor {
|
|||
/**
|
||||
* The actor context - the view of the actor cell from the actor.
|
||||
* Exposes contextual information for the actor and the current message.
|
||||
*
|
||||
* Not intended for public inheritance/implementation
|
||||
*/
|
||||
@DoNotInherit
|
||||
trait ActorContext extends akka.actor.ActorContext {
|
||||
|
||||
/**
|
||||
|
|
@ -60,6 +64,20 @@ object AbstractActor {
|
|||
*/
|
||||
def findChild(name: String): Optional[ActorRef]
|
||||
|
||||
/**
|
||||
* Returns the supervisor of this actor.
|
||||
*
|
||||
* Same as `parent()`.
|
||||
*/
|
||||
def getParent(): ActorRef
|
||||
|
||||
/**
|
||||
* Returns the system this actor is running in.
|
||||
*
|
||||
* Same as `system()`
|
||||
*/
|
||||
def getSystem(): ActorSystem
|
||||
|
||||
/**
|
||||
* Changes the Actor's behavior to become the new 'Receive' handler.
|
||||
* Replaces the current behavior on the top of the behavior stack.
|
||||
|
|
|
|||
|
|
@ -7,19 +7,22 @@ package akka.actor
|
|||
import akka.actor.dungeon.ChildrenContainer
|
||||
import akka.dispatch.Envelope
|
||||
import akka.dispatch.sysmsg._
|
||||
import akka.event.Logging.{ LogEvent, Debug, Error }
|
||||
import akka.event.Logging.{ Debug, Error, LogEvent }
|
||||
import akka.japi.Procedure
|
||||
import java.io.{ ObjectOutputStream, NotSerializableException }
|
||||
import java.io.{ NotSerializableException, ObjectOutputStream }
|
||||
|
||||
import scala.annotation.{ switch, tailrec }
|
||||
import scala.collection.immutable
|
||||
import scala.concurrent.ExecutionContextExecutor
|
||||
import scala.concurrent.duration.Duration
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
|
||||
import scala.util.control.NonFatal
|
||||
import akka.dispatch.MessageDispatcher
|
||||
import akka.util.Reflect
|
||||
import akka.japi.pf.ReceiveBuilder
|
||||
import akka.actor.AbstractActor.Receive
|
||||
import akka.annotation.InternalApi
|
||||
|
||||
/**
|
||||
* The actor context - the view of the actor cell from the actor.
|
||||
|
|
@ -205,6 +208,7 @@ trait UntypedActorContext extends ActorContext {
|
|||
/**
|
||||
* INTERNAL API
|
||||
*/
|
||||
@InternalApi
|
||||
private[akka] trait Cell {
|
||||
/**
|
||||
* The “self” reference which this Cell is attached to.
|
||||
|
|
@ -385,6 +389,11 @@ private[akka] class ActorCell(
|
|||
private var behaviorStack: List[Actor.Receive] = emptyBehaviorStack
|
||||
private[this] var sysmsgStash: LatestFirstSystemMessageList = SystemMessageList.LNil
|
||||
|
||||
// Java API
|
||||
final def getParent() = parent
|
||||
// Java API
|
||||
final def getSystem() = system
|
||||
|
||||
protected def stash(msg: SystemMessage): Unit = {
|
||||
assert(msg.unlinked)
|
||||
sysmsgStash ::= msg
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ package akka.camel
|
|||
import akka.camel.TestSupport.SharedCamelSystem
|
||||
import akka.camel.internal.CamelExchangeAdapter
|
||||
import org.apache.camel.impl.DefaultExchange
|
||||
import org.apache.camel.{Exchange, ExchangePattern}
|
||||
import org.apache.camel.{ Exchange, ExchangePattern }
|
||||
import org.scalatest.FunSuite
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
|
@ -141,4 +141,4 @@ class CamelExchangeAdapterTest extends FunSuite with SharedCamelSystem {
|
|||
}
|
||||
|
||||
private def exchangeToAdapter(e: Exchange) = new CamelExchangeAdapter(e)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ public class ClusterShardingTest {
|
|||
}
|
||||
|
||||
private void passivate() {
|
||||
getContext().parent().tell(
|
||||
getContext().getParent().tell(
|
||||
new ShardRegion.Passivate(PoisonPill.getInstance()), getSelf());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function there is a builder named ``ReceiveBuilder`` that you can use.
|
|||
|
||||
Here is an example:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/MyActor.java
|
||||
.. includecode:: code/jdocs/actor/MyActor.java
|
||||
:include: imports,my-actor
|
||||
|
||||
Please note that the Akka Actor ``receive`` message loop is exhaustive, which
|
||||
|
|
@ -72,8 +72,8 @@ creating an actor including associated deployment information (e.g. which
|
|||
dispatcher to use, see more below). Here are some examples of how to create a
|
||||
:class:`Props` instance.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-props
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#creating-props
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#import-props
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#creating-props
|
||||
|
||||
The second variant shows how to pass constructor arguments to the
|
||||
:class:`Actor` being created, but it should only be used outside of actors as
|
||||
|
|
@ -88,7 +88,7 @@ found.
|
|||
Dangerous Variants
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#creating-props-deprecated
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#creating-props-deprecated
|
||||
|
||||
This method is not recommended to be used within another actor because it
|
||||
encourages to close over the enclosing scope, resulting in non-serializable
|
||||
|
|
@ -120,14 +120,14 @@ associated with using the ``Props.create(...)`` method which takes a by-name
|
|||
argument, since within a companion object the given code block will not retain
|
||||
a reference to its enclosing scope:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#props-factory
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#props-factory
|
||||
|
||||
Another good practice is to declare what messages an Actor can receive
|
||||
as close to the actor definition as possible (e.g. as static classes
|
||||
inside the Actor or using other suitable class), which makes it easier to know
|
||||
what it can receive.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#messages-in-companion
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#messages-in-companion
|
||||
|
||||
Creating Actors with Props
|
||||
--------------------------
|
||||
|
|
@ -136,14 +136,14 @@ Actors are created by passing a :class:`Props` instance into the
|
|||
:meth:`actorOf` factory method which is available on :class:`ActorSystem` and
|
||||
:class:`ActorContext`.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-actorRef
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#system-actorOf
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#import-actorRef
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#system-actorOf
|
||||
|
||||
Using the :class:`ActorSystem` will create top-level actors, supervised by the
|
||||
actor system’s provided guardian actor, while using an actor’s context will
|
||||
create a child actor.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#context-actorOf
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#context-actorOf
|
||||
:exclude: plus-some-behavior
|
||||
|
||||
It is recommended to create a hierarchy of children, grand-children and so on
|
||||
|
|
@ -178,8 +178,8 @@ constructor arguments are determined by a dependency injection framework.
|
|||
|
||||
__ Props_
|
||||
|
||||
.. includecode:: code/docs/actorlambda/DependencyInjectionDocTest.java#import
|
||||
.. includecode:: code/docs/actorlambda/DependencyInjectionDocTest.java
|
||||
.. includecode:: code/jdocs/actor/DependencyInjectionDocTest.java#import
|
||||
.. includecode:: code/jdocs/actor/DependencyInjectionDocTest.java
|
||||
:include: creating-indirectly
|
||||
:exclude: obtain-fresh-Actor-instance-from-DI-framework
|
||||
|
||||
|
|
@ -208,13 +208,13 @@ cannot do: receiving multiple replies (e.g. by subscribing an :class:`ActorRef`
|
|||
to a notification service) and watching other actors’ lifecycle. For these
|
||||
purposes there is the :class:`Inbox` class:
|
||||
|
||||
.. includecode:: code/docs/actor/InboxDocTest.java#inbox
|
||||
.. includecode:: code/jdocs/actor/InboxDocTest.java#inbox
|
||||
|
||||
The :meth:`send` method wraps a normal :meth:`tell` and supplies the internal
|
||||
actor’s reference as the sender. This allows the reply to be received on the
|
||||
last line. Watching an actor is quite simple as well:
|
||||
|
||||
.. includecode:: code/docs/actor/InboxDocTest.java#watch
|
||||
.. includecode:: code/jdocs/actor/InboxDocTest.java#watch
|
||||
|
||||
Actor API
|
||||
=========
|
||||
|
|
@ -231,9 +231,9 @@ actual Debug messages).
|
|||
|
||||
In addition, it offers:
|
||||
|
||||
* :meth:`self()` reference to the :class:`ActorRef` of the actor
|
||||
* :meth:`getSelf()` reference to the :class:`ActorRef` of the actor
|
||||
|
||||
* :meth:`sender()` reference sender Actor of the last received message, typically used as described in :ref:`LambdaActor.Reply`
|
||||
* :meth:`getSender()` reference sender Actor of the last received message, typically used as described in :ref:`LambdaActor.Reply`
|
||||
|
||||
* :meth:`supervisorStrategy()` user overridable definition the strategy to use for supervising child actors
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ In addition, it offers:
|
|||
The remaining visible methods are user-overridable life-cycle hooks which are
|
||||
described in the following:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#lifecycle-callbacks
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#lifecycle-callbacks
|
||||
|
||||
The implementations shown above are the defaults provided by the :class:`AbstractActor`
|
||||
class.
|
||||
|
|
@ -320,8 +320,8 @@ termination (see `Stopping Actors`_). This service is provided by the
|
|||
|
||||
Registering a monitor is easy:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-terminated
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#watch
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#import-terminated
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#watch
|
||||
|
||||
It should be noted that the :class:`Terminated` message is generated
|
||||
independent of the order in which registration and termination occur.
|
||||
|
|
@ -348,7 +348,7 @@ Start Hook
|
|||
|
||||
Right after starting the actor, its :meth:`preStart` method is invoked.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#preStart
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#preStart
|
||||
|
||||
This method is called when the actor is first created. During restarts it is
|
||||
called by the default implementation of :meth:`postRestart`, which means that
|
||||
|
|
@ -427,7 +427,7 @@ actors may look up other actors by specifying absolute or relative
|
|||
paths—logical or physical—and receive back an :class:`ActorSelection` with the
|
||||
result:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#selection-local
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#selection-local
|
||||
|
||||
.. note::
|
||||
|
||||
|
|
@ -453,14 +453,14 @@ structure, i.e. the supervisor.
|
|||
The path elements of an actor selection may contain wildcard patterns allowing for
|
||||
broadcasting of messages to that section:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#selection-wildcard
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#selection-wildcard
|
||||
|
||||
Messages can be sent via the :class:`ActorSelection` and the path of the
|
||||
:class:`ActorSelection` is looked up when delivering each message. If the selection
|
||||
does not match any actors the message will be dropped.
|
||||
|
||||
To acquire an :class:`ActorRef` for an :class:`ActorSelection` you need to send
|
||||
a message to the selection and use the ``sender()`` reference of the reply from
|
||||
a message to the selection and use the ``getSender()`` reference of the reply from
|
||||
the actor. There is a built-in ``Identify`` message that all Actors will
|
||||
understand and automatically reply to with a ``ActorIdentity`` message
|
||||
containing the :class:`ActorRef`. This message is handled specially by the
|
||||
|
|
@ -469,8 +469,8 @@ actors which are traversed in the sense that if a concrete name lookup fails
|
|||
negative result is generated. Please note that this does not mean that delivery
|
||||
of that reply is guaranteed, it still is a normal message.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-identify
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#identify
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#import-identify
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#identify
|
||||
|
||||
You can also acquire an :class:`ActorRef` for an :class:`ActorSelection` with
|
||||
the ``resolveOne`` method of the :class:`ActorSelection`. It returns a
|
||||
|
|
@ -481,7 +481,7 @@ didn't complete within the supplied `timeout`.
|
|||
|
||||
Remote actor addresses may also be looked up, if :ref:`remoting <remoting-java>` is enabled:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#selection-remote
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#selection-remote
|
||||
|
||||
An example demonstrating actor look-up is given in :ref:`remote-sample-java`.
|
||||
|
||||
|
|
@ -494,7 +494,7 @@ convention.
|
|||
|
||||
Here is an example of an immutable message:
|
||||
|
||||
.. includecode:: code/docs/actor/ImmutableMessage.java#immutable-message
|
||||
.. includecode:: code/jdocs/actor/ImmutableMessage.java#immutable-message
|
||||
|
||||
Send messages
|
||||
=============
|
||||
|
|
@ -527,11 +527,11 @@ Tell: Fire-forget
|
|||
This is the preferred way of sending messages. No blocking waiting for a
|
||||
message. This gives the best concurrency and scalability characteristics.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#tell
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#tell
|
||||
|
||||
The sender reference is passed along with the message and available within the
|
||||
receiving actor via its :meth:`sender()` method while processing this
|
||||
message. Inside of an actor it is usually :meth:`self()` who shall be the
|
||||
receiving actor via its :meth:`getSender()` method while processing this
|
||||
message. Inside of an actor it is usually :meth:`getSelf()` who shall be the
|
||||
sender, but there can be cases where replies shall be routed to some other
|
||||
actor—e.g. the parent—in which the second argument to :meth:`tell` would be a
|
||||
different one. Outside of an actor and if no reply is needed the second
|
||||
|
|
@ -546,8 +546,8 @@ Ask: Send-And-Receive-Future
|
|||
The ``ask`` pattern involves actors as well as futures, hence it is offered as
|
||||
a use pattern rather than a method on :class:`ActorRef`:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-ask
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#ask-pipe
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#import-ask
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#ask-pipe
|
||||
|
||||
This example demonstrates ``ask`` together with the ``pipe`` pattern on
|
||||
futures, because this is likely to be a common combination. Please note that
|
||||
|
|
@ -558,7 +558,7 @@ an ``onComplete``-handler on the future to effect the submission of the
|
|||
aggregated :class:`Result` to another actor.
|
||||
|
||||
Using ``ask`` will send a message to the receiving Actor as with ``tell``, and
|
||||
the receiving actor must reply with ``sender().tell(reply, self())`` in order to
|
||||
the receiving actor must reply with ``getSender().tell(reply, getSelf())`` in order to
|
||||
complete the returned :class:`Future` with a value. The ``ask`` operation
|
||||
involves creating an internal actor for handling this reply, which needs to
|
||||
have a timeout after which it is destroyed in order not to leak resources; see
|
||||
|
|
@ -573,7 +573,7 @@ more below.
|
|||
To complete the future with an exception you need send a Failure message to the sender.
|
||||
This is *not done automatically* when an actor throws an exception while processing a message.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#reply-exception
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#reply-exception
|
||||
|
||||
If the actor does not complete the future, it will expire after the timeout period,
|
||||
specified as parameter to the ``ask`` method; this will complete the
|
||||
|
|
@ -604,7 +604,7 @@ original sender address/reference is maintained even though the message is going
|
|||
through a 'mediator'. This can be useful when writing actors that work as
|
||||
routers, load-balancers, replicators etc.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#forward
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#forward
|
||||
|
||||
.. _actors-receive-java:
|
||||
|
||||
|
|
@ -614,7 +614,7 @@ Receive messages
|
|||
An actor has to define its initial receive behavior by implementing
|
||||
the :meth:`createReceive` method in the :class:`AbstractActor`:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#createReceive
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#createReceive
|
||||
|
||||
|
||||
The return type is :class:`AbstractActor.Receive` that defines which messages your Actor can handle,
|
||||
|
|
@ -623,20 +623,20 @@ You can build such behavior with a builder named ``ReceiveBuilder``.
|
|||
|
||||
Here is an example:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/MyActor.java
|
||||
.. includecode:: code/jdocs/actor/MyActor.java
|
||||
:include: imports,my-actor
|
||||
|
||||
In case you want to provide many :meth:`match` cases but want to avoid creating a long call
|
||||
trail, you can split the creation of the builder into multiple statements as in the example:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/GraduallyBuiltActor.java
|
||||
.. includecode:: code/jdocs/actor/GraduallyBuiltActor.java
|
||||
:include: imports,actor
|
||||
|
||||
Using small methods is a good practice, also in actors. It's recommended to delegate the
|
||||
actual work of the message processing to methods instead of defining a huge ``ReceiveBuilder``
|
||||
with lots of code in each lambda. A well structured actor can look like this:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#well-structured
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#well-structured
|
||||
|
||||
That has benefits such as:
|
||||
|
||||
|
|
@ -648,7 +648,7 @@ That has benefits such as:
|
|||
The ``Receive`` can be implemented in other ways than using the ``ReceiveBuilder`` since it in the
|
||||
end is just a wrapper around a Scala ``PartialFunction``. In Java, you can implement ``PartialFunction`` by
|
||||
extending ``AbstractPartialFunction``. For example, one could implement an adapter
|
||||
to `Javaslang Pattern Matching DSL <http://www.javaslang.io/javaslang-docs/#_pattern_matching>`_.
|
||||
to `Javaslang Pattern Matching DSL <http://www.javaslang.io/javaslang-jdocs/#_pattern_matching>`_.
|
||||
|
||||
If the validation of the ``ReceiveBuilder`` match logic turns out to be a bottleneck for some of your
|
||||
actors you can consider to implement it at lower level by extending ``UntypedAbstractActor`` instead
|
||||
|
|
@ -658,7 +658,7 @@ that the JVM can have problems optimizing and the resulting code might not be as
|
|||
untyped version. When extending ``UntypedAbstractActor`` each message is received as an untyped
|
||||
``Object`` and you have to inspect and cast it to the actual message type in other ways, like this:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#optimized
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#optimized
|
||||
|
||||
.. _LambdaActor.Reply:
|
||||
|
||||
|
|
@ -666,13 +666,13 @@ Reply to messages
|
|||
=================
|
||||
|
||||
If you want to have a handle for replying to a message, you can use
|
||||
``sender()``, which gives you an ActorRef. You can reply by sending to
|
||||
that ActorRef with ``sender().tell(replyMsg, self())``. You can also store the ActorRef
|
||||
``getSender()``, which gives you an ActorRef. You can reply by sending to
|
||||
that ActorRef with ``getSender().tell(replyMsg, getSelf())``. You can also store the ActorRef
|
||||
for replying later, or passing on to other actors. If there is no sender (a
|
||||
message was sent without an actor or future context) then the sender
|
||||
defaults to a 'dead-letter' actor ref.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/MyActor.java#reply
|
||||
.. includecode:: code/jdocs/actor/MyActor.java#reply
|
||||
|
||||
|
||||
Receive timeout
|
||||
|
|
@ -690,7 +690,7 @@ timeout there must have been an idle period beforehand as configured via this me
|
|||
Once set, the receive timeout stays in effect (i.e. continues firing repeatedly after inactivity
|
||||
periods). Pass in `Duration.Undefined` to switch off this feature.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#receive-timeout
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#receive-timeout
|
||||
|
||||
Messages marked with ``NotInfluenceReceiveTimeout`` will not reset the timer. This can be useful when
|
||||
``ReceiveTimeout`` should be fired by external inactivity but not influenced by internal activity,
|
||||
|
|
@ -707,7 +707,7 @@ child actors and the system for stopping top level actors. The actual terminatio
|
|||
the actor is performed asynchronously, i.e. :meth:`stop` may return before the actor is
|
||||
stopped.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/MyStoppingActor.java#my-stopping-actor
|
||||
.. includecode:: code/jdocs/actor/MyStoppingActor.java#my-stopping-actor
|
||||
|
||||
Processing of the current message, if any, will continue before the actor is stopped,
|
||||
but additional messages in the mailbox will not be processed. By default these
|
||||
|
|
@ -733,7 +733,7 @@ whole system.
|
|||
The :meth:`postStop()` hook is invoked after an actor is fully stopped. This
|
||||
enables cleaning up of resources:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#postStop
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#postStop
|
||||
:exclude: clean-up-some-resources
|
||||
|
||||
.. note::
|
||||
|
|
@ -754,7 +754,7 @@ stop the actor when the message is processed. ``PoisonPill`` is enqueued as
|
|||
ordinary messages and will be handled after messages that were already queued
|
||||
in the mailbox.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#poison-pill
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#poison-pill
|
||||
|
||||
Graceful Stop
|
||||
-------------
|
||||
|
|
@ -762,11 +762,11 @@ Graceful Stop
|
|||
:meth:`gracefulStop` is useful if you need to wait for termination or compose ordered
|
||||
termination of several actors:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-gracefulStop
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#import-gracefulStop
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#gracefulStop
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#gracefulStop
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#gracefulStop-actor
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#gracefulStop-actor
|
||||
|
||||
When ``gracefulStop()`` returns successfully, the actor’s ``postStop()`` hook
|
||||
will have been executed: there exists a happens-before edge between the end of
|
||||
|
|
@ -809,7 +809,7 @@ The phases are ordered with `topological <https://en.wikipedia.org/wiki/Topologi
|
|||
|
||||
Tasks can be added to a phase with:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#coordinated-shutdown-addTask
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#coordinated-shutdown-addTask
|
||||
|
||||
The returned ``CompletionStage<Done>`` should be completed when the task is completed. The task name parameter
|
||||
is only used for debugging/logging.
|
||||
|
|
@ -828,7 +828,7 @@ added too late will not be run.
|
|||
To start the coordinated shutdown process you can invoke ``runAll`` on the ``CoordinatedShutdown``
|
||||
extension:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#coordinated-shutdown-run
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#coordinated-shutdown-run
|
||||
|
||||
It's safe to call the ``runAll`` method multiple times. It will only run once.
|
||||
|
||||
|
|
@ -853,7 +853,7 @@ If you have application specific JVM shutdown hooks it's recommended that you re
|
|||
``CoordinatedShutdown`` so that they are running before Akka internal shutdown hooks, e.g.
|
||||
those shutting down Akka Remoting (Artery).
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#coordinated-shutdown-jvm-hook
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#coordinated-shutdown-jvm-hook
|
||||
|
||||
For some tests it might be undesired to terminate the ``ActorSystem`` via ``CoordinatedShutdown``.
|
||||
You can disable that by adding the following to the configuration of the ``ActorSystem`` that is
|
||||
|
|
@ -881,7 +881,7 @@ popped.
|
|||
|
||||
To hotswap the Actor behavior using ``become``:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#hot-swap-actor
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#hot-swap-actor
|
||||
|
||||
This variant of the :meth:`become` method is useful for many different things,
|
||||
such as to implement a Finite State Machine (FSM, for an example see `Dining
|
||||
|
|
@ -897,7 +897,7 @@ of “pop” operations (i.e. :meth:`unbecome`) matches the number of “push”
|
|||
in the long run, otherwise this amounts to a memory leak (which is why this
|
||||
behavior is not the default).
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#swapper
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#swapper
|
||||
|
||||
.. _stash-java:
|
||||
|
||||
|
|
@ -923,7 +923,7 @@ order as they have been received originally. An actor that extends
|
|||
|
||||
Here is an example of the ``AbstractActorWithStash`` class in action:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#stash
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#stash
|
||||
|
||||
Invoking ``stash()`` adds the current message (the message that the
|
||||
actor received last) to the actor's stash. It is typically invoked
|
||||
|
|
@ -972,7 +972,7 @@ See :ref:`supervision-directives` for more information.
|
|||
|
||||
Use ``Kill`` like this:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/ActorDocTest.java#kill
|
||||
.. includecode:: code/jdocs/actor/ActorDocTest.java#kill
|
||||
|
||||
Actors and exceptions
|
||||
=====================
|
||||
|
|
@ -1039,7 +1039,7 @@ this behavior, and ensure that there is only one call to ``preStart()``.
|
|||
One useful usage of this pattern is to disable creation of new ``ActorRefs`` for children during restarts. This can be
|
||||
achieved by overriding ``preRestart()``:
|
||||
|
||||
.. includecode:: code/docs/actorlambda/InitializationDocTest.java#preStartInit
|
||||
.. includecode:: code/jdocs/actor/InitializationDocTest.java#preStartInit
|
||||
|
||||
Please note, that the child actors are *still restarted*, but no new ``ActorRef`` is created. One can recursively apply
|
||||
the same principles for the children, ensuring that their ``preStart()`` method is called only at the creation of their
|
||||
|
|
@ -1055,7 +1055,7 @@ for example in the presence of circular dependencies. In this case the actor sho
|
|||
and use ``become()`` or a finite state-machine state transition to encode the initialized and uninitialized states
|
||||
of the actor.
|
||||
|
||||
.. includecode:: code/docs/actorlambda/InitializationDocTest.java#messageInit
|
||||
.. includecode:: code/jdocs/actor/InitializationDocTest.java#messageInit
|
||||
|
||||
If the actor may receive messages before it has been initialized, a useful tool can be the ``Stash`` to save messages
|
||||
until the initialization finishes, and replaying them after the actor became initialized.
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ Creating Agents
|
|||
Agents are created by invoking ``new Agent<ValueType>(value, executionContext)`` – passing in the Agent's initial
|
||||
value and providing an ``ExecutionContext`` to be used for it:
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java
|
||||
:include: import-agent,create
|
||||
:language: java
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ Reading an Agent's value
|
|||
Agents can be dereferenced (you can get an Agent's value) by invoking the Agent
|
||||
with ``get()`` like this:
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java#read-get
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java#read-get
|
||||
:language: java
|
||||
|
||||
Reading an Agent's current value does not involve any message passing and
|
||||
|
|
@ -56,7 +56,7 @@ state of an Agent is synchronous.
|
|||
You can also get a ``Future`` to the Agents value, that will be completed after the
|
||||
currently queued updates have completed:
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java
|
||||
:include: import-future,read-future
|
||||
:language: java
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ the update will be applied but dispatches to an Agent from a single thread will
|
|||
occur in order. You apply a value or a function by invoking the ``send``
|
||||
function.
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java
|
||||
:include: import-function,send
|
||||
:language: java
|
||||
|
||||
|
|
@ -83,18 +83,18 @@ long-running or blocking operations. You do this with the ``sendOff``
|
|||
method. Dispatches using either ``sendOff`` or ``send`` will still be executed
|
||||
in order.
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java
|
||||
:include: import-function,send-off
|
||||
:language: java
|
||||
|
||||
All ``send`` methods also have a corresponding ``alter`` method that returns a ``Future``.
|
||||
See :ref:`futures-java` for more information on ``Futures``.
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java
|
||||
:include: import-future,import-function,alter
|
||||
:language: java
|
||||
|
||||
.. includecode:: code/docs/agent/AgentDocTest.java
|
||||
.. includecode:: code/jdocs/agent/AgentDocTest.java
|
||||
:include: import-future,import-function,alter-off
|
||||
:language: java
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ Consumer
|
|||
--------
|
||||
Here's an example of using Camel's integration components in Akka.
|
||||
|
||||
.. includecode:: code/docs/camel/MyEndpoint.java#Consumer-mina
|
||||
.. includecode:: code/jdocs/camel/MyEndpoint.java#Consumer-mina
|
||||
|
||||
The above example exposes an actor over a TCP endpoint via Apache
|
||||
Camel's `Mina component`_. The actor implements the `getEndpointUri` method to define
|
||||
|
|
@ -55,14 +55,14 @@ Producer
|
|||
Actors can also trigger message exchanges with external systems i.e. produce to
|
||||
Camel endpoints.
|
||||
|
||||
.. includecode:: code/docs/camel/Orders.java#Producer
|
||||
.. includecode:: code/jdocs/camel/Orders.java#Producer
|
||||
|
||||
In the above example, any message sent to this actor will be sent to
|
||||
the JMS queue ``Orders``. Producer actors may choose from the same set of Camel
|
||||
components as Consumer actors do.
|
||||
Below an example of how to send a message to the Orders producer.
|
||||
|
||||
.. includecode:: code/docs/camel/ProducerTestBase.java#TellProducer
|
||||
.. includecode:: code/jdocs/camel/ProducerTestBase.java#TellProducer
|
||||
|
||||
CamelMessage
|
||||
------------
|
||||
|
|
@ -90,7 +90,7 @@ The ``CamelExtension`` object provides access to the `Camel`_ interface.
|
|||
The `Camel`_ interface in turn provides access to two important Apache Camel objects, the `CamelContext`_ and the `ProducerTemplate`_.
|
||||
Below you can see how you can get access to these Apache Camel objects.
|
||||
|
||||
.. includecode:: code/docs/camel/CamelExtensionTest.java#CamelExtension
|
||||
.. includecode:: code/jdocs/camel/CamelExtensionTest.java#CamelExtension
|
||||
|
||||
One ``CamelExtension`` is only loaded once for every one ``ActorSystem``, which makes it safe to call the ``CamelExtension`` at any point in your code to get to the
|
||||
Apache Camel objects associated with it. There is one `CamelContext`_ and one `ProducerTemplate`_ for every one ``ActorSystem`` that uses a ``CamelExtension``.
|
||||
|
|
@ -102,7 +102,7 @@ This interface define a single method ``getContext()`` used to load the `CamelCo
|
|||
|
||||
Below an example on how to add the ActiveMQ component to the `CamelContext`_, which is required when you would like to use the ActiveMQ component.
|
||||
|
||||
.. includecode:: code/docs/camel/CamelExtensionTest.java#CamelExtensionAddComponent
|
||||
.. includecode:: code/jdocs/camel/CamelExtensionTest.java#CamelExtensionAddComponent
|
||||
|
||||
The `CamelContext`_ joins the lifecycle of the ``ActorSystem`` and ``CamelExtension`` it is associated with; the `CamelContext`_ is started when
|
||||
the ``CamelExtension`` is created, and it is shut down when the associated ``ActorSystem`` is shut down. The same is true for the `ProducerTemplate`_.
|
||||
|
|
@ -117,12 +117,12 @@ Publication is done asynchronously; setting up an endpoint may still be in progr
|
|||
requested the actor to be created. Some Camel components can take a while to startup, and in some cases you might want to know when the endpoints are activated and ready to be used.
|
||||
The `Camel`_ interface allows you to find out when the endpoint is activated or deactivated.
|
||||
|
||||
.. includecode:: code/docs/camel/ActivationTestBase.java#CamelActivation
|
||||
.. includecode:: code/jdocs/camel/ActivationTestBase.java#CamelActivation
|
||||
|
||||
The above code shows that you can get a ``Future`` to the activation of the route from the endpoint to the actor, or you can wait in a blocking fashion on the activation of the route.
|
||||
An ``ActivationTimeoutException`` is thrown if the endpoint could not be activated within the specified timeout. Deactivation works in a similar fashion:
|
||||
|
||||
.. includecode:: code/docs/camel/ActivationTestBase.java#CamelDeactivation
|
||||
.. includecode:: code/jdocs/camel/ActivationTestBase.java#CamelDeactivation
|
||||
|
||||
Deactivation of a Consumer or a Producer actor happens when the actor is terminated. For a Consumer, the route to the actor is stopped. For a Producer, the `SendProcessor`_ is stopped.
|
||||
A ``DeActivationTimeoutException`` is thrown if the associated camel objects could not be deactivated within the specified timeout.
|
||||
|
|
@ -143,7 +143,7 @@ messages from the ``file:data/input/actor`` Camel endpoint.
|
|||
|
||||
.. _UntypedConsumerActor: @github@/akka-camel/src/main/scala/akka/camel/javaapi/UntypedConsumer.scala
|
||||
|
||||
.. includecode:: code/docs/camel/Consumer1.java#Consumer1
|
||||
.. includecode:: code/jdocs/camel/Consumer1.java#Consumer1
|
||||
|
||||
Whenever a file is put into the data/input/actor directory, its content is
|
||||
picked up by the Camel `file component`_ and sent as message to the
|
||||
|
|
@ -162,11 +162,11 @@ from localhost on port 8877.
|
|||
.. _Jetty component: http://camel.apache.org/jetty.html
|
||||
.. _Jetty: http://www.eclipse.org/jetty/
|
||||
|
||||
.. includecode:: code/docs/camel/Consumer2.java#Consumer2
|
||||
.. includecode:: code/jdocs/camel/Consumer2.java#Consumer2
|
||||
|
||||
After starting the actor, clients can send messages to that actor by POSTing to
|
||||
``http://localhost:8877/camel/default``. The actor sends a response by using the
|
||||
sender().tell method. For returning a message body and headers to the HTTP
|
||||
``getSender().tell`` method. For returning a message body and headers to the HTTP
|
||||
client the response type should be `CamelMessage`_. For any other response type, a
|
||||
new CamelMessage object is created by akka-camel with the actor response as message
|
||||
body.
|
||||
|
|
@ -193,7 +193,7 @@ In this case, consumer actors must reply either with a
|
|||
special akka.camel.Ack message (positive acknowledgement) or a akka.actor.Status.Failure (negative
|
||||
acknowledgement).
|
||||
|
||||
.. includecode:: code/docs/camel/Consumer3.java#Consumer3
|
||||
.. includecode:: code/jdocs/camel/Consumer3.java#Consumer3
|
||||
|
||||
.. _camel-timeout-java:
|
||||
|
||||
|
|
@ -214,7 +214,7 @@ and the actor replies to the endpoint when the response is ready. The ask reques
|
|||
result in the `Exchange`_ failing with a TimeoutException set on the failure of the `Exchange`_.
|
||||
The timeout on the consumer actor can be overridden with the ``replyTimeout``, as shown below.
|
||||
|
||||
.. includecode:: code/docs/camel/Consumer4.java#Consumer4
|
||||
.. includecode:: code/jdocs/camel/Consumer4.java#Consumer4
|
||||
.. _Exchange: https://svn.apache.org/repos/asf/camel/tags/camel-2.8.0/camel-core/src/main/java/org/apache/camel/Exchange.java
|
||||
.. _ask: @github@/akka-actor/src/main/scala/akka/pattern/Patterns.scala
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ Producer Actors
|
|||
|
||||
For sending messages to Camel endpoints, actors need to inherit from the `UntypedProducerActor`_ class and implement the getEndpointUri method.
|
||||
|
||||
.. includecode:: code/docs/camel/Producer1.java#Producer1
|
||||
.. includecode:: code/jdocs/camel/Producer1.java#Producer1
|
||||
|
||||
Producer1 inherits a default implementation of the onReceive method from the
|
||||
`UntypedProducerActor`_ class. To customize a producer actor's default behavior you must override the `UntypedProducerActor`_.onTransformResponse and
|
||||
|
|
@ -237,7 +237,7 @@ configured endpoint) will, by default, be returned to the original sender. The
|
|||
following example uses the ask pattern to send a message to a
|
||||
Producer actor and waits for a response.
|
||||
|
||||
.. includecode:: code/docs/camel/ProducerTestBase.java#AskProducer
|
||||
.. includecode:: code/jdocs/camel/ProducerTestBase.java#AskProducer
|
||||
|
||||
The future contains the response CamelMessage, or an ``AkkaCamelException`` when an error occurred, which contains the headers of the response.
|
||||
|
||||
|
|
@ -251,14 +251,14 @@ response processing by overriding the onRouteResponse method. In the following e
|
|||
message is forwarded to a target actor instead of being replied to the original
|
||||
sender.
|
||||
|
||||
.. includecode:: code/docs/camel/ResponseReceiver.java#RouteResponse
|
||||
.. includecode:: code/docs/camel/Forwarder.java#RouteResponse
|
||||
.. includecode:: code/docs/camel/OnRouteResponseTestBase.java#RouteResponse
|
||||
.. includecode:: code/jdocs/camel/ResponseReceiver.java#RouteResponse
|
||||
.. includecode:: code/jdocs/camel/Forwarder.java#RouteResponse
|
||||
.. includecode:: code/jdocs/camel/OnRouteResponseTestBase.java#RouteResponse
|
||||
|
||||
Before producing messages to endpoints, producer actors can pre-process them by
|
||||
overriding the `UntypedProducerActor`_.onTransformOutgoingMessage method.
|
||||
|
||||
.. includecode:: code/docs/camel/Transformer.java#TransformOutgoingMessage
|
||||
.. includecode:: code/jdocs/camel/Transformer.java#TransformOutgoingMessage
|
||||
|
||||
Producer configuration options
|
||||
------------------------------
|
||||
|
|
@ -268,7 +268,7 @@ one-way or two-way (by initiating in-only or in-out message exchanges,
|
|||
respectively). By default, the producer initiates an in-out message exchange
|
||||
with the endpoint. For initiating an in-only exchange, producer actors have to override the isOneway method to return true.
|
||||
|
||||
.. includecode:: code/docs/camel/OnewaySender.java#Oneway
|
||||
.. includecode:: code/jdocs/camel/OnewaySender.java#Oneway
|
||||
|
||||
Message correlation
|
||||
-------------------
|
||||
|
|
@ -276,7 +276,7 @@ Message correlation
|
|||
To correlate request with response messages, applications can set the
|
||||
`Message.MessageExchangeId` message header.
|
||||
|
||||
.. includecode:: code/docs/camel/ProducerTestBase.java#Correlate
|
||||
.. includecode:: code/jdocs/camel/ProducerTestBase.java#Correlate
|
||||
|
||||
ProducerTemplate
|
||||
----------------
|
||||
|
|
@ -284,12 +284,12 @@ ProducerTemplate
|
|||
The `UntypedProducerActor`_ class is a very convenient way for actors to produce messages to Camel endpoints.
|
||||
Actors may also use a Camel `ProducerTemplate`_ for producing messages to endpoints.
|
||||
|
||||
.. includecode:: code/docs/camel/MyActor.java#ProducerTemplate
|
||||
.. includecode:: code/jdocs/camel/MyActor.java#ProducerTemplate
|
||||
|
||||
For initiating a two-way message exchange, one of the
|
||||
``ProducerTemplate.request*`` methods must be used.
|
||||
|
||||
.. includecode:: code/docs/camel/RequestBodyActor.java#RequestProducerTemplate
|
||||
.. includecode:: code/jdocs/camel/RequestBodyActor.java#RequestProducerTemplate
|
||||
|
||||
.. _UntypedProducerActor: @github@/akka-camel/src/main/scala/akka/camel/javaapi/UntypedProducerActor.scala
|
||||
.. _ProducerTemplate: https://svn.apache.org/repos/asf/camel/tags/camel-2.8.0/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
|
||||
|
|
@ -304,7 +304,7 @@ designed to be asynchronous. This is the case for both, consumer and producer
|
|||
actors.
|
||||
|
||||
* A consumer endpoint sends request messages to its consumer actor using the ``tell``
|
||||
method and the actor returns responses with ``sender().tell`` once they are
|
||||
method and the actor returns responses with ``getSender().tell`` once they are
|
||||
ready.
|
||||
|
||||
* A producer actor sends request messages to its endpoint using Camel's
|
||||
|
|
@ -426,9 +426,9 @@ Here's an actor endpoint URI example containing an actor path::
|
|||
In the following example, a custom route to an actor is created, using the
|
||||
actor's path.
|
||||
|
||||
.. includecode:: code/docs/camel/Responder.java#CustomRoute
|
||||
.. includecode:: code/docs/camel/CustomRouteBuilder.java#CustomRoute
|
||||
.. includecode:: code/docs/camel/CustomRouteTestBase.java#CustomRoute
|
||||
.. includecode:: code/jdocs/camel/Responder.java#CustomRoute
|
||||
.. includecode:: code/jdocs/camel/CustomRouteBuilder.java#CustomRoute
|
||||
.. includecode:: code/jdocs/camel/CustomRouteTestBase.java#CustomRoute
|
||||
|
||||
The `CamelPath.toCamelUri` converts the `ActorRef` to the Camel actor component URI format which points to the actor endpoint as described above.
|
||||
When a message is received on the jetty endpoint, it is routed to the Responder actor, which in return replies back to the client of
|
||||
|
|
@ -453,7 +453,7 @@ Extensions can be defined with Camel's `Java DSL`_ or `Scala DSL`_. For example,
|
|||
The following examples demonstrate how to extend a route to a consumer actor for
|
||||
handling exceptions thrown by that actor.
|
||||
|
||||
.. includecode:: code/docs/camel/ErrorThrowingConsumer.java#ErrorThrowingConsumer
|
||||
.. includecode:: code/jdocs/camel/ErrorThrowingConsumer.java#ErrorThrowingConsumer
|
||||
|
||||
The above ErrorThrowingConsumer sends the Failure back to the sender in preRestart
|
||||
because the Exception that is thrown in the actor would
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ what clients are connected.
|
|||
|
||||
The message will be delivered to one recipient with a matching path, if any such
|
||||
exists. If several entries match the path the message will be delivered
|
||||
to one random destination. The sender() of the message can specify that local
|
||||
to one random destination. The ``sender`` of the message can specify that local
|
||||
affinity is preferred, i.e. the message is sent to an actor in the same local actor
|
||||
system as the used receptionist actor, if any such exists, otherwise random to any other
|
||||
matching entry.
|
||||
|
|
@ -63,8 +63,8 @@ to the named topic.
|
|||
|
||||
Response messages from the destination actor are tunneled via the receptionist
|
||||
to avoid inbound connections from other cluster nodes to the client, i.e.
|
||||
the ``sender()``, as seen by the destination actor, is not the client itself.
|
||||
The ``sender()`` of the response messages, as seen by the client, is ``deadLetters``
|
||||
the ``sender``, as seen by the destination actor, is not the client itself.
|
||||
The ``sender`` of the response messages, as seen by the client, is ``deadLetters``
|
||||
since the client should normally send subsequent messages via the ``ClusterClient``.
|
||||
It is possible to pass the original sender inside the reply messages if
|
||||
the client is supposed to communicate directly to the actor in the cluster.
|
||||
|
|
|
|||
|
|
@ -125,11 +125,11 @@ Let's take a look at this router in action. What can be more demanding than calc
|
|||
|
||||
The backend worker that performs the factorial calculation:
|
||||
|
||||
.. includecode:: code/docs/cluster/FactorialBackend.java#backend
|
||||
.. includecode:: code/jdocs/cluster/FactorialBackend.java#backend
|
||||
|
||||
The frontend that receives user jobs and delegates to the backends via the router:
|
||||
|
||||
.. includecode:: code/docs/cluster/FactorialFrontend.java#frontend
|
||||
.. includecode:: code/jdocs/cluster/FactorialFrontend.java#frontend
|
||||
|
||||
|
||||
As you can see, the router is defined in the same way as other routers, and in this case it is configured as follows:
|
||||
|
|
@ -160,9 +160,9 @@ other things work in the same way as other routers.
|
|||
|
||||
The same type of router could also have been defined in code:
|
||||
|
||||
.. includecode:: code/docs/cluster/FactorialFrontend.java#router-lookup-in-code
|
||||
.. includecode:: code/jdocs/cluster/FactorialFrontend.java#router-lookup-in-code
|
||||
|
||||
.. includecode:: code/docs/cluster/FactorialFrontend.java#router-deploy-in-code
|
||||
.. includecode:: code/jdocs/cluster/FactorialFrontend.java#router-deploy-in-code
|
||||
|
||||
The `Lightbend Activator <http://www.lightbend.com/platform/getstarted>`_ tutorial named
|
||||
`Akka Cluster Samples with Java <http://www.lightbend.com/activator/template/akka-sample-cluster-java>`_.
|
||||
|
|
@ -173,7 +173,7 @@ Subscribe to Metrics Events
|
|||
|
||||
It is possible to subscribe to the metrics events directly to implement other functionality.
|
||||
|
||||
.. includecode:: code/docs/cluster/MetricsListener.java#metrics-listener
|
||||
.. includecode:: code/jdocs/cluster/MetricsListener.java#metrics-listener
|
||||
|
||||
Custom Metrics Collector
|
||||
------------------------
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ ip-addresses or host names of the machines in ``application.conf`` instead of ``
|
|||
|
||||
An actor that uses the cluster extension may look like this:
|
||||
|
||||
.. literalinclude:: code/docs/cluster/SimpleClusterListener.java
|
||||
.. literalinclude:: code/jdocs/cluster/SimpleClusterListener.java
|
||||
:language: java
|
||||
|
||||
The actor registers itself as subscriber of certain cluster events. It receives events corresponding to the current state
|
||||
|
|
@ -173,9 +173,9 @@ can be performed automatically or manually. By default it must be done manually,
|
|||
It can also be performed programmatically with ``Cluster.get(system).down(address)``.
|
||||
|
||||
A pre-packaged solution for the downing problem is provided by
|
||||
`Split Brain Resolver <http://developer.lightbend.com/docs/akka-commercial-addons/current/split-brain-resolver.html>`_,
|
||||
`Split Brain Resolver <http://developer.lightbend.com/jdocs/akka-commercial-addons/current/split-brain-resolver.html>`_,
|
||||
which is part of the `Lightbend Reactive Platform <http://www.lightbend.com/platform>`_.
|
||||
If you don’t use RP, you should anyway carefully read the `documentation <http://developer.lightbend.com/docs/akka-commercial-addons/current/split-brain-resolver.html>`_
|
||||
If you don’t use RP, you should anyway carefully read the `documentation <http://developer.lightbend.com/jdocs/akka-commercial-addons/current/split-brain-resolver.html>`_
|
||||
of the Split Brain Resolver and make sure that the solution you are using handles the concerns
|
||||
described there.
|
||||
|
||||
|
|
@ -217,7 +217,7 @@ A more graceful exit can be performed if you tell the cluster that a node shall
|
|||
This can be performed using :ref:`cluster_jmx_java` or :ref:`cluster_http_java`.
|
||||
It can also be performed programmatically with:
|
||||
|
||||
.. includecode:: code/docs/cluster/ClusterDocTest.java#leave
|
||||
.. includecode:: code/jdocs/cluster/ClusterDocTest.java#leave
|
||||
|
||||
Note that this command can be issued to any member in the cluster, not necessarily the
|
||||
one that is leaving.
|
||||
|
|
@ -261,7 +261,7 @@ Subscribe to Cluster Events
|
|||
You can subscribe to change notifications of the cluster membership by using
|
||||
``Cluster.get(system).subscribe``.
|
||||
|
||||
.. includecode:: code/docs/cluster/SimpleClusterListener2.java#subscribe
|
||||
.. includecode:: code/jdocs/cluster/SimpleClusterListener2.java#subscribe
|
||||
|
||||
A snapshot of the full state, ``akka.cluster.ClusterEvent.CurrentClusterState``, is sent to the subscriber
|
||||
as the first message, followed by events for incremental updates.
|
||||
|
|
@ -278,7 +278,7 @@ the events corresponding to the current state to mimic what you would have seen
|
|||
listening to the events when they occurred in the past. Note that those initial events only correspond
|
||||
to the current state and it is not the full history of all changes that actually has occurred in the cluster.
|
||||
|
||||
.. includecode:: code/docs/cluster/SimpleClusterListener.java#subscribe
|
||||
.. includecode:: code/jdocs/cluster/SimpleClusterListener.java#subscribe
|
||||
|
||||
The events to track the life-cycle of members are:
|
||||
|
||||
|
|
@ -314,11 +314,11 @@ added or removed to the cluster dynamically.
|
|||
|
||||
Messages:
|
||||
|
||||
.. includecode:: code/docs/cluster/TransformationMessages.java#messages
|
||||
.. includecode:: code/jdocs/cluster/TransformationMessages.java#messages
|
||||
|
||||
The backend worker that performs the transformation job:
|
||||
|
||||
.. includecode:: code/docs/cluster/TransformationBackend.java#backend
|
||||
.. includecode:: code/jdocs/cluster/TransformationBackend.java#backend
|
||||
|
||||
Note that the ``TransformationBackend`` actor subscribes to cluster events to detect new,
|
||||
potential, frontend nodes, and send them a registration message so that they know
|
||||
|
|
@ -326,7 +326,7 @@ that they can use the backend worker.
|
|||
|
||||
The frontend that receives user jobs and delegates to one of the registered backend workers:
|
||||
|
||||
.. includecode:: code/docs/cluster/TransformationFrontend.java#frontend
|
||||
.. includecode:: code/jdocs/cluster/TransformationFrontend.java#frontend
|
||||
|
||||
Note that the ``TransformationFrontend`` actor watch the registered backend
|
||||
to be able to remove it from its list of available backend workers.
|
||||
|
|
@ -376,7 +376,7 @@ You can start the actors in a ``registerOnMemberUp`` callback, which will
|
|||
be invoked when the current member status is changed to 'Up', i.e. the cluster
|
||||
has at least the defined number of members.
|
||||
|
||||
.. includecode:: code/docs/cluster/FactorialFrontendMain.java#registerOnUp
|
||||
.. includecode:: code/jdocs/cluster/FactorialFrontendMain.java#registerOnUp
|
||||
|
||||
This callback can be used for other things than starting actors.
|
||||
|
||||
|
|
@ -574,7 +574,7 @@ Set it to a lower value if you want to limit total number of routees.
|
|||
|
||||
The same type of router could also have been defined in code:
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsService.java#router-lookup-in-code
|
||||
.. includecode:: code/jdocs/cluster/StatsService.java#router-lookup-in-code
|
||||
|
||||
See :ref:`cluster_configuration_java` section for further descriptions of the settings.
|
||||
|
||||
|
|
@ -592,17 +592,17 @@ the average number of characters per word when all results have been collected.
|
|||
|
||||
Messages:
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsMessages.java#messages
|
||||
.. includecode:: code/jdocs/cluster/StatsMessages.java#messages
|
||||
|
||||
The worker that counts number of characters in each word:
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsWorker.java#worker
|
||||
.. includecode:: code/jdocs/cluster/StatsWorker.java#worker
|
||||
|
||||
The service that receives text from users and splits it up into words, delegates to workers and aggregates:
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsService.java#service
|
||||
.. includecode:: code/jdocs/cluster/StatsService.java#service
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsAggregator.java#aggregator
|
||||
.. includecode:: code/jdocs/cluster/StatsAggregator.java#aggregator
|
||||
|
||||
|
||||
Note, nothing cluster specific so far, just plain actors.
|
||||
|
|
@ -657,7 +657,7 @@ Set it to a lower value if you want to limit total number of routees.
|
|||
|
||||
The same type of router could also have been defined in code:
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsService.java#router-deploy-in-code
|
||||
.. includecode:: code/jdocs/cluster/StatsService.java#router-deploy-in-code
|
||||
|
||||
See :ref:`cluster_configuration_java` section for further descriptions of the settings.
|
||||
|
||||
|
|
@ -668,12 +668,12 @@ Let's take a look at how to use a cluster aware router on single master node tha
|
|||
and deploys workers. To keep track of a single master we use the :ref:`cluster-singleton-java`
|
||||
in the cluster-tools module. The ``ClusterSingletonManager`` is started on each node.
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsSampleOneMasterMain.java#create-singleton-manager
|
||||
.. includecode:: code/jdocs/cluster/StatsSampleOneMasterMain.java#create-singleton-manager
|
||||
|
||||
We also need an actor on each node that keeps track of where current single master exists and
|
||||
delegates jobs to the ``StatsService``. That is provided by the ``ClusterSingletonProxy``.
|
||||
|
||||
.. includecode:: code/docs/cluster/StatsSampleOneMasterMain.java#singleton-proxy
|
||||
.. includecode:: code/jdocs/cluster/StatsSampleOneMasterMain.java#singleton-proxy
|
||||
|
||||
The ``ClusterSingletonProxy`` receives text from users and delegates to the current ``StatsService``, the single
|
||||
master. It listens to cluster events to lookup the ``StatsService`` on the oldest node.
|
||||
|
|
@ -771,7 +771,7 @@ Run it without parameters to see instructions about how to use the script::
|
|||
|
||||
|
||||
To be able to use the script you must enable remote monitoring and management when starting the JVMs of the cluster nodes,
|
||||
as described in `Monitoring and Management Using JMX Technology <http://docs.oracle.com/javase/8/docs/technotes/guides/management/agent.html>`_.
|
||||
as described in `Monitoring and Management Using JMX Technology <http://docs.oracle.com/javase/8/jdocs/technotes/guides/management/agent.html>`_.
|
||||
Make sure you understand the security implications of enabling remote monitoring and management.
|
||||
|
||||
.. _cluster_configuration_java:
|
||||
|
|
|
|||
|
|
@ -1,149 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Messages {
|
||||
static
|
||||
//#immutable-message
|
||||
public class ImmutableMessage {
|
||||
private final int sequenceNumber;
|
||||
private final List<String> values;
|
||||
|
||||
public ImmutableMessage(int sequenceNumber, List<String> values) {
|
||||
this.sequenceNumber = sequenceNumber;
|
||||
this.values = Collections.unmodifiableList(new ArrayList<String>(values));
|
||||
}
|
||||
|
||||
public int getSequenceNumber() {
|
||||
return sequenceNumber;
|
||||
}
|
||||
|
||||
public List<String> getValues() {
|
||||
return values;
|
||||
}
|
||||
}
|
||||
//#immutable-message
|
||||
|
||||
public static class DoIt {
|
||||
private final ImmutableMessage msg;
|
||||
|
||||
DoIt(ImmutableMessage msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public ImmutableMessage getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
DoIt doIt = (DoIt) o;
|
||||
|
||||
if (!msg.equals(doIt.msg)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return msg.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DoIt{" +
|
||||
"msg=" + msg +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class Message {
|
||||
final String str;
|
||||
|
||||
Message(String str) {
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public String getStr() {
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Message message = (Message) o;
|
||||
|
||||
if (!str.equals(message.str)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return str.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" +
|
||||
"str='" + str + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Swap {
|
||||
Swap
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
final String x;
|
||||
final String s;
|
||||
|
||||
public Result(String x, String s) {
|
||||
this.x = x;
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((s == null) ? 0 : s.hashCode());
|
||||
result = prime * result + ((x == null) ? 0 : x.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Result other = (Result) obj;
|
||||
if (s == null) {
|
||||
if (other.s != null)
|
||||
return false;
|
||||
} else if (!s.equals(other.s))
|
||||
return false;
|
||||
if (x == null) {
|
||||
if (other.x != null)
|
||||
return false;
|
||||
} else if (!x.equals(other.x))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* Copyright (C) 2016-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs
|
||||
package jdocs
|
||||
|
||||
import org.scalatest.junit.JUnitSuite
|
||||
|
||||
|
|
@ -2,14 +2,15 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
import akka.actor.*;
|
||||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import docs.AbstractJavaTest;
|
||||
import static docs.actorlambda.Messages.Swap.Swap;
|
||||
import static docs.actorlambda.Messages.*;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import static jdocs.actor.Messages.Swap.Swap;
|
||||
import static jdocs.actor.Messages.*;
|
||||
import static akka.japi.Util.immutableSeq;
|
||||
import akka.actor.CoordinatedShutdown;
|
||||
|
||||
import akka.util.Timeout;
|
||||
|
|
@ -41,7 +42,7 @@ import akka.actor.Identify;
|
|||
//#import-ask
|
||||
import static akka.pattern.PatternsCS.ask;
|
||||
import static akka.pattern.PatternsCS.pipe;
|
||||
import akka.util.Timeout;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
//#import-ask
|
||||
//#import-gracefulStop
|
||||
|
|
@ -85,7 +86,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchAny(x -> sender().tell(x, self()))
|
||||
.matchAny(x -> getSender().tell(x, getSelf()))
|
||||
.build();
|
||||
}
|
||||
//#plus-some-behavior
|
||||
|
|
@ -206,7 +207,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Integer.class, i -> {
|
||||
sender().tell(i + magicNumber, self());
|
||||
getSender().tell(i + magicNumber, getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -311,7 +312,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
final String message = "stopped";
|
||||
//#tell
|
||||
// don’t forget to think about who is the sender (2nd argument)
|
||||
target.tell(message, self());
|
||||
target.tell(message, getSelf());
|
||||
//#tell
|
||||
final Object result = "";
|
||||
//#forward
|
||||
|
|
@ -353,9 +354,9 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
//#reply-exception
|
||||
try {
|
||||
String result = operation();
|
||||
sender().tell(result, self());
|
||||
getSender().tell(result, getSelf());
|
||||
} catch (Exception e) {
|
||||
sender().tell(new akka.actor.Status.Failure(e), self());
|
||||
getSender().tell(new akka.actor.Status.Failure(e), getSelf());
|
||||
throw e;
|
||||
}
|
||||
//#reply-exception
|
||||
|
|
@ -383,10 +384,10 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("job", s -> {
|
||||
worker.tell("crunch", self());
|
||||
worker.tell("crunch", getSelf());
|
||||
})
|
||||
.matchEquals(SHUTDOWN, x -> {
|
||||
worker.tell(PoisonPill.getInstance(), self());
|
||||
worker.tell(PoisonPill.getInstance(), getSelf());
|
||||
getContext().become(shuttingDown());
|
||||
})
|
||||
.build();
|
||||
|
|
@ -394,8 +395,8 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
|
||||
private AbstractActor.Receive shuttingDown() {
|
||||
return receiveBuilder()
|
||||
.matchEquals("job", s ->
|
||||
sender().tell("service unavailable, shutting down", self())
|
||||
.matchEquals("job", s ->
|
||||
getSender().tell("service unavailable, shutting down", getSelf())
|
||||
)
|
||||
.match(Terminated.class, t -> t.actor().equals(worker), t ->
|
||||
getContext().stop(self())
|
||||
|
|
@ -530,7 +531,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
//#receive-timeout
|
||||
public class ReceiveTimeoutActor extends AbstractActor {
|
||||
//#receive-timeout
|
||||
ActorRef target = getContext().system().deadLetters();
|
||||
ActorRef target = getContext().getSystem().deadLetters();
|
||||
//#receive-timeout
|
||||
public ReceiveTimeoutActor() {
|
||||
// To set an initial delay
|
||||
|
|
@ -544,15 +545,15 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
// To set in a response to a message
|
||||
getContext().setReceiveTimeout(Duration.create(1, TimeUnit.SECONDS));
|
||||
//#receive-timeout
|
||||
target = sender();
|
||||
target.tell("Hello world", self());
|
||||
target = getSender();
|
||||
target.tell("Hello world", getSelf());
|
||||
//#receive-timeout
|
||||
})
|
||||
.match(ReceiveTimeout.class, r -> {
|
||||
// To turn it off
|
||||
getContext().setReceiveTimeout(Duration.Undefined());
|
||||
//#receive-timeout
|
||||
target.tell("timeout", self());
|
||||
target.tell("timeout", getSelf());
|
||||
//#receive-timeout
|
||||
})
|
||||
.build();
|
||||
|
|
@ -582,7 +583,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
angry =
|
||||
receiveBuilder()
|
||||
.matchEquals("foo", s -> {
|
||||
sender().tell("I am already angry?", self());
|
||||
getSender().tell("I am already angry?", getSelf());
|
||||
})
|
||||
.matchEquals("bar", s -> {
|
||||
getContext().become(happy);
|
||||
|
|
@ -591,7 +592,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
|
||||
happy = receiveBuilder()
|
||||
.matchEquals("bar", s -> {
|
||||
sender().tell("I am already happy :-)", self());
|
||||
getSender().tell("I am already happy :-)", getSelf());
|
||||
})
|
||||
.matchEquals("foo", s -> {
|
||||
getContext().become(angry);
|
||||
|
|
@ -675,10 +676,10 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
return receiveBuilder()
|
||||
.matchEquals("kill", s -> {
|
||||
getContext().stop(child);
|
||||
lastSender = sender();
|
||||
lastSender = getSender();
|
||||
})
|
||||
.match(Terminated.class, t -> t.actor().equals(child), t -> {
|
||||
lastSender.tell("finished", self());
|
||||
lastSender.tell("finished", getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -704,7 +705,7 @@ public class ActorDocTest extends AbstractJavaTest {
|
|||
|
||||
public Follower(){
|
||||
ActorSelection selection = getContext().actorSelection("/user/another");
|
||||
selection.tell(new Identify(identifyId), self());
|
||||
selection.tell(new Identify(identifyId), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2016-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actor;
|
||||
package jdocs.actor;
|
||||
|
||||
//#bytebufserializer-with-manifest
|
||||
import akka.serialization.ByteBufferSerializer;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -35,7 +35,7 @@ public class DependencyInjectionDocTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(String.class, msg -> {
|
||||
sender().tell(s, self());
|
||||
getSender().tell(s, getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
import akka.actor.*;
|
||||
|
||||
|
||||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import java.util.Optional;
|
||||
|
||||
import static akka.pattern.Patterns.ask;
|
||||
|
|
@ -73,7 +73,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Props.class, props -> {
|
||||
sender().tell(getContext().actorOf(props), self());
|
||||
getSender().tell(getContext().actorOf(props), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -104,7 +104,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Props.class, props -> {
|
||||
sender().tell(getContext().actorOf(props), self());
|
||||
getSender().tell(getContext().actorOf(props), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
|
|||
return receiveBuilder()
|
||||
.match(Exception.class, exception -> { throw exception; })
|
||||
.match(Integer.class, i -> state = i)
|
||||
.matchEquals("get", s -> sender().tell(state, self()))
|
||||
.matchEquals("get", s -> getSender().tell(state, getSelf()))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,20 +2,19 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
//#imports
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
import akka.japi.pf.UnitPFBuilder;
|
||||
|
||||
//#imports
|
||||
|
||||
//#actor
|
||||
public class GraduallyBuiltActor extends AbstractActor {
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
|
|
@ -25,7 +24,7 @@ public class GraduallyBuiltActor extends AbstractActor {
|
|||
log.info("Received String message: {}", s);
|
||||
//#actor
|
||||
//#reply
|
||||
sender().tell(s, self());
|
||||
getSender().tell(s, getSelf());
|
||||
//#reply
|
||||
//#actor
|
||||
});
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actor;
|
||||
package jdocs.actor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -2,12 +2,12 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actor;
|
||||
package jdocs.actor;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -9,7 +9,7 @@ import akka.actor.ActorSystem;
|
|||
import akka.actor.Props;
|
||||
import akka.japi.pf.FI;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -75,7 +75,7 @@ public class InitializationDocTest extends AbstractJavaTest {
|
|||
initializeMe = "Up and running";
|
||||
getContext().become(receiveBuilder()
|
||||
.matchEquals("U OK?", m2 -> {
|
||||
sender().tell(initializeMe, self());
|
||||
getSender().tell(initializeMe, getSelf());
|
||||
})
|
||||
.build());
|
||||
})
|
||||
|
|
@ -98,7 +98,7 @@ public class InitializationDocTest extends AbstractJavaTest {
|
|||
return receiveBuilder()
|
||||
.matchUnchecked(GenericMessage.class, (GenericMessage<String> msg) -> {
|
||||
GenericMessage<String> message = msg;
|
||||
sender().tell(message.value.toUpperCase(), self());
|
||||
getSender().tell(message.value.toUpperCase(), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ public class InitializationDocTest extends AbstractJavaTest {
|
|||
|
||||
return receiveBuilder()
|
||||
.matchUnchecked(GenericMessage.class, typedPredicate, (GenericMessage<String> msg) -> {
|
||||
sender().tell(msg.value.toUpperCase(), self());
|
||||
getSender().tell(msg.value.toUpperCase(), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actor;
|
||||
package jdocs.actor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
//#imports
|
||||
import akka.actor.AbstractActor;
|
||||
|
|
@ -13,7 +13,7 @@ import akka.event.LoggingAdapter;
|
|||
|
||||
//#my-actor
|
||||
public class MyActor extends AbstractActor {
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
|
|
@ -22,7 +22,7 @@ public class MyActor extends AbstractActor {
|
|||
log.info("Received String message: {}", s);
|
||||
//#my-actor
|
||||
//#reply
|
||||
sender().tell(s, self());
|
||||
getSender().tell(s, getSelf());
|
||||
//#reply
|
||||
//#my-actor
|
||||
})
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
//#my-bounded-untyped-actor
|
||||
import akka.dispatch.BoundedMessageQueueSemantics;
|
||||
import akka.dispatch.RequiresMessageQueue;
|
||||
|
||||
public class MyBoundedActor extends MyActor
|
||||
public class MyBoundedActor extends MyActor
|
||||
implements RequiresMessageQueue<BoundedMessageQueueSemantics> {
|
||||
}
|
||||
//#my-bounded-untyped-actor
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
//#my-stopping-actor
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -20,7 +20,7 @@ public class MyStoppingActor extends AbstractActor {
|
|||
getContext().stop(child)
|
||||
)
|
||||
.matchEquals("done", m ->
|
||||
getContext().stop(self())
|
||||
getContext().stop(getSelf())
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
|
@ -2,17 +2,16 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
//#sample-actor
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
|
||||
public class SampleActor extends AbstractActor {
|
||||
|
||||
private Receive guarded = receiveBuilder()
|
||||
.match(String.class, s -> s.contains("guard"), s -> {
|
||||
sender().tell("contains(guard): " + s, self());
|
||||
getSender().tell("contains(guard): " + s, getSelf());
|
||||
getContext().unbecome();
|
||||
})
|
||||
.build();
|
||||
|
|
@ -21,13 +20,13 @@ public class SampleActor extends AbstractActor {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Double.class, d -> {
|
||||
sender().tell(d.isNaN() ? 0 : d, self());
|
||||
getSender().tell(d.isNaN() ? 0 : d, getSelf());
|
||||
})
|
||||
.match(Integer.class, i -> {
|
||||
sender().tell(i * 10, self());
|
||||
getSender().tell(i * 10, getSelf());
|
||||
})
|
||||
.match(String.class, s -> s.startsWith("guard"), s -> {
|
||||
sender().tell("startsWith(guard): " + s.toUpperCase(), self());
|
||||
getSender().tell("startsWith(guard): " + s.toUpperCase(), getSelf());
|
||||
getContext().become(guarded, false);
|
||||
})
|
||||
.build();
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda;
|
||||
package jdocs.actor;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Props;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actor;
|
||||
package jdocs.actor;
|
||||
|
||||
//#imports1
|
||||
import akka.actor.Props;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
//#imports1
|
||||
|
|
@ -14,7 +14,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import akka.actor.Cancellable;
|
||||
//#imports2
|
||||
|
||||
import docs.actorlambda.MyActor;
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actor;
|
||||
package jdocs.actor;
|
||||
|
||||
//#imports
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ import akka.actor.*;
|
|||
import akka.japi.*;
|
||||
import akka.dispatch.Futures;
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda.fsm;
|
||||
package jdocs.actor.fsm;
|
||||
|
||||
//#simple-imports
|
||||
import akka.actor.AbstractFSM;
|
||||
|
|
@ -14,11 +14,11 @@ import java.util.List;
|
|||
import scala.concurrent.duration.Duration;
|
||||
//#simple-imports
|
||||
|
||||
import static docs.actorlambda.fsm.Buncher.Data;
|
||||
import static docs.actorlambda.fsm.Buncher.State.*;
|
||||
import static docs.actorlambda.fsm.Buncher.State;
|
||||
import static docs.actorlambda.fsm.Buncher.Uninitialized.*;
|
||||
import static docs.actorlambda.fsm.Events.*;
|
||||
import static jdocs.actor.fsm.Buncher.Data;
|
||||
import static jdocs.actor.fsm.Buncher.State.*;
|
||||
import static jdocs.actor.fsm.Buncher.State;
|
||||
import static jdocs.actor.fsm.Buncher.Uninitialized.*;
|
||||
import static jdocs.actor.fsm.Events.*;
|
||||
|
||||
//#simple-fsm
|
||||
public class Buncher extends AbstractFSM<State, Data> {
|
||||
|
|
@ -2,23 +2,22 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda.fsm;
|
||||
package jdocs.actor.fsm;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.Props;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import docs.actorlambda.fsm.*;
|
||||
import static docs.actorlambda.fsm.Events.Batch;
|
||||
import static docs.actorlambda.fsm.Events.Queue;
|
||||
import static docs.actorlambda.fsm.Events.SetTarget;
|
||||
import static docs.actorlambda.fsm.Events.Flush.Flush;
|
||||
import static jdocs.actor.fsm.Events.Batch;
|
||||
import static jdocs.actor.fsm.Events.Queue;
|
||||
import static jdocs.actor.fsm.Events.SetTarget;
|
||||
import static jdocs.actor.fsm.Events.Flush.Flush;
|
||||
|
||||
//#test-code
|
||||
public class BuncherTest extends AbstractJavaTest {
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda.fsm;
|
||||
package jdocs.actor.fsm;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import java.util.List;
|
||||
|
|
@ -2,12 +2,11 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.actorlambda.fsm;
|
||||
package jdocs.actor.fsm;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import docs.AbstractJavaTest;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -15,8 +14,8 @@ import scala.concurrent.duration.Duration;
|
|||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static docs.actorlambda.fsm.FSMDocTest.StateType.*;
|
||||
import static docs.actorlambda.fsm.FSMDocTest.Messages.*;
|
||||
import static jdocs.actor.fsm.FSMDocTest.StateType.*;
|
||||
import static jdocs.actor.fsm.FSMDocTest.Messages.*;
|
||||
import static java.util.concurrent.TimeUnit.*;
|
||||
|
||||
public class FSMDocTest extends AbstractJavaTest {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.actorlambda.japi;
|
||||
package jdocs.actor.japi;
|
||||
|
||||
//#all
|
||||
//#imports
|
||||
|
|
@ -14,7 +14,6 @@ import akka.actor.*;
|
|||
import akka.dispatch.Mapper;
|
||||
import akka.event.LoggingReceive;
|
||||
import akka.japi.pf.DeciderBuilder;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
import akka.util.Timeout;
|
||||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
|
|
@ -28,10 +27,10 @@ import static akka.actor.SupervisorStrategy.escalate;
|
|||
import static akka.pattern.Patterns.ask;
|
||||
import static akka.pattern.Patterns.pipe;
|
||||
|
||||
import static docs.actorlambda.japi.FaultHandlingDocSample.WorkerApi.*;
|
||||
import static docs.actorlambda.japi.FaultHandlingDocSample.CounterServiceApi.*;
|
||||
import static docs.actorlambda.japi.FaultHandlingDocSample.CounterApi.*;
|
||||
import static docs.actorlambda.japi.FaultHandlingDocSample.StorageApi.*;
|
||||
import static jdocs.actor.japi.FaultHandlingDocSample.WorkerApi.*;
|
||||
import static jdocs.actor.japi.FaultHandlingDocSample.CounterServiceApi.*;
|
||||
import static jdocs.actor.japi.FaultHandlingDocSample.CounterApi.*;
|
||||
import static jdocs.actor.japi.FaultHandlingDocSample.StorageApi.*;
|
||||
|
||||
//#imports
|
||||
|
||||
|
|
@ -77,13 +76,13 @@ public class FaultHandlingDocSample {
|
|||
log().info("Current progress: {} %", progress.percent);
|
||||
if (progress.percent >= 100.0) {
|
||||
log().info("That's all, shutting down");
|
||||
getContext().system().terminate();
|
||||
getContext().getSystem().terminate();
|
||||
}
|
||||
}).
|
||||
matchEquals(ReceiveTimeout.getInstance(), x -> {
|
||||
// No progress within 15 seconds, ServiceUnavailable
|
||||
log().error("Shutting down due to unavailable service");
|
||||
getContext().system().terminate();
|
||||
getContext().getSystem().terminate();
|
||||
}).build(), getContext());
|
||||
}
|
||||
}
|
||||
|
|
@ -138,16 +137,16 @@ public class FaultHandlingDocSample {
|
|||
public Receive createReceive() {
|
||||
return LoggingReceive.create(receiveBuilder().
|
||||
matchEquals(Start, x -> progressListener == null, x -> {
|
||||
progressListener = sender();
|
||||
getContext().system().scheduler().schedule(
|
||||
Duration.Zero(), Duration.create(1, "second"), self(), Do,
|
||||
progressListener = getSender();
|
||||
getContext().getSystem().scheduler().schedule(
|
||||
Duration.Zero(), Duration.create(1, "second"), getSelf(), Do,
|
||||
getContext().dispatcher(), null
|
||||
);
|
||||
}).
|
||||
matchEquals(Do, x -> {
|
||||
counterService.tell(new Increment(1), self());
|
||||
counterService.tell(new Increment(1), self());
|
||||
counterService.tell(new Increment(1), self());
|
||||
counterService.tell(new Increment(1), getSelf());
|
||||
counterService.tell(new Increment(1), getSelf());
|
||||
counterService.tell(new Increment(1), getSelf());
|
||||
// Send current progress to the initial sender
|
||||
pipe(ask(counterService, GetCurrentCount, askTimeout)
|
||||
.mapTo(classTag(CurrentCount.class))
|
||||
|
|
@ -223,7 +222,7 @@ public class FaultHandlingDocSample {
|
|||
}
|
||||
}
|
||||
|
||||
final String key = self().path().name();
|
||||
final String key = getSelf().path().name();
|
||||
ActorRef storage;
|
||||
ActorRef counter;
|
||||
final List<SenderMsgPair> backlog = new ArrayList<>();
|
||||
|
|
@ -258,9 +257,9 @@ public class FaultHandlingDocSample {
|
|||
Props.create(Storage.class), "storage"));
|
||||
// Tell the counter, if any, to use the new storage
|
||||
if (counter != null)
|
||||
counter.tell(new UseStorage(storage), self());
|
||||
counter.tell(new UseStorage(storage), getSelf());
|
||||
// We need the initial value to be able to operate
|
||||
storage.tell(new Get(key), self());
|
||||
storage.tell(new Get(key), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -271,7 +270,7 @@ public class FaultHandlingDocSample {
|
|||
final long value = entry.value;
|
||||
counter = getContext().actorOf(Props.create(Counter.class, key, value));
|
||||
// Tell the counter to use current storage
|
||||
counter.tell(new UseStorage(storage), self());
|
||||
counter.tell(new UseStorage(storage), getSelf());
|
||||
// and send the buffered backlog to the counter
|
||||
for (SenderMsgPair each : backlog) {
|
||||
counter.tell(each.msg, each.sender);
|
||||
|
|
@ -289,10 +288,10 @@ public class FaultHandlingDocSample {
|
|||
// We receive Terminated because we watch the child, see initStorage.
|
||||
storage = null;
|
||||
// Tell the counter that there is no storage for the moment
|
||||
counter.tell(new UseStorage(null), self());
|
||||
counter.tell(new UseStorage(null), getSelf());
|
||||
// Try to re-establish storage after while
|
||||
getContext().system().scheduler().scheduleOnce(
|
||||
Duration.create(10, "seconds"), self(), Reconnect,
|
||||
getContext().getSystem().scheduler().scheduleOnce(
|
||||
Duration.create(10, "seconds"), getSelf(), Reconnect,
|
||||
getContext().dispatcher(), null);
|
||||
}).
|
||||
matchEquals(Reconnect, o -> {
|
||||
|
|
@ -309,7 +308,7 @@ public class FaultHandlingDocSample {
|
|||
if (backlog.size() >= MAX_BACKLOG)
|
||||
throw new ServiceUnavailable("CounterService not available," +
|
||||
" lack of initial value");
|
||||
backlog.add(new SenderMsgPair(sender(), msg));
|
||||
backlog.add(new SenderMsgPair(getSender(), msg));
|
||||
} else {
|
||||
counter.forward(msg, getContext());
|
||||
}
|
||||
|
|
@ -359,7 +358,7 @@ public class FaultHandlingDocSample {
|
|||
storeCount();
|
||||
}).
|
||||
matchEquals(GetCurrentCount, gcc -> {
|
||||
sender().tell(new CurrentCount(key, count), self());
|
||||
getSender().tell(new CurrentCount(key, count), getSelf());
|
||||
}).build(), getContext());
|
||||
}
|
||||
|
||||
|
|
@ -367,7 +366,7 @@ public class FaultHandlingDocSample {
|
|||
// Delegate dangerous work, to protect our valuable state.
|
||||
// We can continue without storage.
|
||||
if (storage != null) {
|
||||
storage.tell(new Store(new Entry(key, count)), self());
|
||||
storage.tell(new Store(new Entry(key, count)), getSelf());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -440,8 +439,8 @@ public class FaultHandlingDocSample {
|
|||
}).
|
||||
match(Get.class, get -> {
|
||||
Long value = db.load(get.key);
|
||||
sender().tell(new Entry(get.key, value == null ?
|
||||
Long.valueOf(0L) : value), self());
|
||||
getSender().tell(new Entry(get.key, value == null ?
|
||||
Long.valueOf(0L) : value), getSelf());
|
||||
}).build(), getContext());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,10 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.agent;
|
||||
package jdocs.agent;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import org.junit.Test;
|
||||
|
||||
import scala.concurrent.Await;
|
||||
|
|
@ -25,7 +24,7 @@ import scala.concurrent.duration.Duration;
|
|||
import scala.concurrent.Future;
|
||||
//#import-future
|
||||
|
||||
public class AgentDocTest extends docs.AbstractJavaTest {
|
||||
public class AgentDocTest extends jdocs.AbstractJavaTest {
|
||||
|
||||
private static ExecutionContext ec = ExecutionContexts.global();
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#CamelActivation
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -7,9 +7,8 @@ package docs.camel;
|
|||
import akka.camel.CamelExtension;
|
||||
import akka.camel.javaapi.UntypedConsumerActor;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.TestKit;
|
||||
import akka.util.Timeout;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.camel.Camel;
|
||||
import akka.camel.CamelExtension;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Consumer1
|
||||
import akka.camel.CamelMessage;
|
||||
import akka.camel.javaapi.UntypedConsumerActor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Consumer2
|
||||
import akka.camel.CamelMessage;
|
||||
import akka.camel.javaapi.UntypedConsumerActor;
|
||||
|
|
@ -12,7 +12,7 @@ public class Consumer2 extends UntypedConsumerActor {
|
|||
if (message instanceof CamelMessage) {
|
||||
CamelMessage camelMessage = (CamelMessage) message;
|
||||
String body = camelMessage.getBodyAs(String.class, getCamelContext());
|
||||
sender().tell(String.format("Received message: %s",body), self());
|
||||
getSender().tell(String.format("Received message: %s",body), getSelf());
|
||||
} else
|
||||
unhandled(message);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Consumer3
|
||||
import akka.actor.Status;
|
||||
import akka.camel.Ack;
|
||||
|
|
@ -18,12 +18,12 @@ public class Consumer3 extends UntypedConsumerActor{
|
|||
|
||||
public void onReceive(Object message) {
|
||||
if (message instanceof CamelMessage) {
|
||||
sender().tell(Ack.getInstance(), self());
|
||||
getSender().tell(Ack.getInstance(), getSelf());
|
||||
// on success
|
||||
// ..
|
||||
Exception someException = new Exception("e1");
|
||||
// on failure
|
||||
sender().tell(new Status.Failure(someException), self());
|
||||
getSender().tell(new Status.Failure(someException), getSelf());
|
||||
} else
|
||||
unhandled(message);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Consumer4
|
||||
import akka.camel.CamelMessage;
|
||||
import akka.camel.javaapi.UntypedConsumerActor;
|
||||
|
|
@ -24,7 +24,7 @@ public class Consumer4 extends UntypedConsumerActor {
|
|||
if (message instanceof CamelMessage) {
|
||||
CamelMessage camelMessage = (CamelMessage) message;
|
||||
String body = camelMessage.getBodyAs(String.class, getCamelContext());
|
||||
sender().tell(String.format("Hello %s",body), self());
|
||||
getSender().tell(String.format("Hello %s",body), getSelf());
|
||||
} else
|
||||
unhandled(message);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#CustomRoute
|
||||
import akka.actor.ActorRef;
|
||||
import akka.camel.internal.component.CamelPath;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#ErrorThrowingConsumer
|
||||
import akka.actor.Status;
|
||||
import akka.camel.CamelMessage;
|
||||
|
|
@ -47,7 +47,7 @@ public class ErrorThrowingConsumer extends UntypedConsumerActor{
|
|||
|
||||
@Override
|
||||
public void preRestart(Throwable reason, Option<Object> message) {
|
||||
sender().tell(new Status.Failure(reason), self());
|
||||
getSender().tell(new Status.Failure(reason), getSelf());
|
||||
}
|
||||
}
|
||||
//#ErrorThrowingConsumer
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
|
||||
//#Producer1
|
||||
import akka.camel.javaapi.UntypedProducerActor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#RouteResponse
|
||||
import akka.actor.ActorRef;
|
||||
import akka.camel.javaapi.UntypedProducerActor;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#ProducerTemplate
|
||||
import akka.actor.UntypedAbstractActor;
|
||||
import akka.camel.Camel;
|
||||
|
|
@ -7,7 +7,7 @@ import org.apache.camel.ProducerTemplate;
|
|||
|
||||
public class MyActor extends UntypedAbstractActor {
|
||||
public void onReceive(Object message) {
|
||||
Camel camel = CamelExtension.get(getContext().system());
|
||||
Camel camel = CamelExtension.get(getContext().getSystem());
|
||||
ProducerTemplate template = camel.template();
|
||||
template.sendBody("direct:news", message);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
|
||||
//#Consumer-mina
|
||||
import akka.camel.CamelMessage;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
|
||||
import akka.actor.*;
|
||||
import akka.testkit.JavaTestKit;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Oneway
|
||||
import akka.camel.javaapi.UntypedProducerActor;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Producer
|
||||
import akka.camel.javaapi.UntypedProducerActor;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#Producer1
|
||||
import akka.camel.javaapi.UntypedProducerActor;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#RequestProducerTemplate
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.camel.Camel;
|
||||
|
|
@ -10,9 +10,9 @@ public class RequestBodyActor extends AbstractActor {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.matchAny(message -> {
|
||||
Camel camel = CamelExtension.get(getContext().system());
|
||||
Camel camel = CamelExtension.get(getContext().getSystem());
|
||||
ProducerTemplate template = camel.template();
|
||||
sender().tell(template.requestBody("direct:news", message), self());
|
||||
getSender().tell(template.requestBody("direct:news", message), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -1,16 +1,15 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#CustomRoute
|
||||
import akka.actor.UntypedAbstractActor;
|
||||
import akka.camel.CamelMessage;
|
||||
import akka.dispatch.Mapper;
|
||||
import akka.japi.Function;
|
||||
|
||||
public class Responder extends UntypedAbstractActor{
|
||||
|
||||
public void onReceive(Object message) {
|
||||
if (message instanceof CamelMessage) {
|
||||
CamelMessage camelMessage = (CamelMessage) message;
|
||||
sender().tell(createResponse(camelMessage), self());
|
||||
getSender().tell(createResponse(camelMessage), getSelf());
|
||||
} else
|
||||
unhandled(message);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#RouteResponse
|
||||
import akka.actor.UntypedAbstractActor;
|
||||
import akka.camel.CamelMessage;
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package docs.camel;
|
||||
package jdocs.camel;
|
||||
//#TransformOutgoingMessage
|
||||
import akka.camel.CamelMessage;
|
||||
import akka.camel.javaapi.UntypedProducerActor;
|
||||
import akka.dispatch.Mapper;
|
||||
import akka.japi.Function;
|
||||
|
||||
public class Transformer extends UntypedProducerActor{
|
||||
private String uri;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
|
@ -26,7 +26,7 @@ public class FactorialFrontend extends AbstractActor {
|
|||
final int upToN;
|
||||
final boolean repeat;
|
||||
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
ActorRef backend = getContext().actorOf(FromConfig.getInstance().props(),
|
||||
"factorialBackendRouter");
|
||||
|
|
@ -64,7 +64,7 @@ public class FactorialFrontend extends AbstractActor {
|
|||
void sendJobs() {
|
||||
log.info("Starting batch of factorials up to [{}]", upToN);
|
||||
for (int n = 1; n <= upToN; n++) {
|
||||
backend.tell(n, self());
|
||||
backend.tell(n, getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import scala.concurrent.Await;
|
||||
import scala.concurrent.duration.Duration;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.io.Serializable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
//#metrics-listener
|
||||
import akka.actor.AbstractActor;
|
||||
|
|
@ -14,11 +14,11 @@ import akka.event.Logging;
|
|||
import akka.event.LoggingAdapter;
|
||||
|
||||
public class MetricsListener extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
Cluster cluster = Cluster.get(getContext().system());
|
||||
Cluster cluster = Cluster.get(getContext().getSystem());
|
||||
|
||||
ClusterMetricsExtension extension = ClusterMetricsExtension.get(getContext().system());
|
||||
ClusterMetricsExtension extension = ClusterMetricsExtension.get(getContext().getSystem());
|
||||
|
||||
|
||||
// Subscribe unto ClusterMetricsEvent events.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.cluster.Cluster;
|
||||
|
|
@ -11,8 +11,8 @@ import akka.event.Logging;
|
|||
import akka.event.LoggingAdapter;
|
||||
|
||||
public class SimpleClusterListener extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
Cluster cluster = Cluster.get(getContext().system());
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
Cluster cluster = Cluster.get(getContext().getSystem());
|
||||
|
||||
//subscribe to cluster changes
|
||||
@Override
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.cluster.Cluster;
|
||||
|
|
@ -11,8 +11,8 @@ import akka.event.Logging;
|
|||
import akka.event.LoggingAdapter;
|
||||
|
||||
public class SimpleClusterListener2 extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
Cluster cluster = Cluster.get(getContext().system());
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
Cluster cluster = Cluster.get(getContext().getSystem());
|
||||
|
||||
//subscribe to cluster changes
|
||||
@Override
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import docs.cluster.StatsMessages.JobFailed;
|
||||
import docs.cluster.StatsMessages.StatsResult;
|
||||
import jdocs.cluster.StatsMessages.JobFailed;
|
||||
import jdocs.cluster.StatsMessages.StatsResult;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ReceiveTimeout;
|
||||
|
|
@ -39,14 +39,14 @@ public class StatsAggregator extends AbstractActor {
|
|||
sum += c;
|
||||
}
|
||||
double meanWordLength = ((double) sum) / results.size();
|
||||
replyTo.tell(new StatsResult(meanWordLength), self());
|
||||
getContext().stop(self());
|
||||
replyTo.tell(new StatsResult(meanWordLength), getSelf());
|
||||
getContext().stop(getSelf());
|
||||
}
|
||||
})
|
||||
.match(ReceiveTimeout.class, x -> {
|
||||
replyTo.tell(new JobFailed("Service unavailable, try again later"),
|
||||
self());
|
||||
getContext().stop(self());
|
||||
getSelf());
|
||||
getContext().stop(getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -6,9 +6,9 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import docs.cluster.StatsMessages.JobFailed;
|
||||
import docs.cluster.StatsMessages.StatsJob;
|
||||
import docs.cluster.StatsMessages.StatsResult;
|
||||
import jdocs.cluster.StatsMessages.JobFailed;
|
||||
import jdocs.cluster.StatsMessages.StatsJob;
|
||||
import jdocs.cluster.StatsMessages.StatsResult;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
|
@ -32,15 +32,15 @@ public class StatsSampleClient extends AbstractActor {
|
|||
final Cancellable tickTask;
|
||||
final Set<Address> nodes = new HashSet<Address>();
|
||||
|
||||
Cluster cluster = Cluster.get(getContext().system());
|
||||
Cluster cluster = Cluster.get(getContext().getSystem());
|
||||
|
||||
public StatsSampleClient(String servicePath) {
|
||||
this.servicePath = servicePath;
|
||||
FiniteDuration interval = Duration.create(2, TimeUnit.SECONDS);
|
||||
tickTask = getContext()
|
||||
.system()
|
||||
.getSystem()
|
||||
.scheduler()
|
||||
.schedule(interval, interval, self(), "tick",
|
||||
.schedule(interval, interval, getSelf(), "tick",
|
||||
getContext().dispatcher(), null);
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +67,7 @@ public class StatsSampleClient extends AbstractActor {
|
|||
nodesList.size()));
|
||||
ActorSelection service = getContext().actorSelection(address + servicePath);
|
||||
service.tell(new StatsJob("this is the text that will be analyzed"),
|
||||
self());
|
||||
getSelf());
|
||||
})
|
||||
.match(StatsResult.class, System.out::println)
|
||||
.match(JobFailed.class, System.out::println)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import com.typesafe.config.Config;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import akka.cluster.routing.ClusterRouterGroup;
|
||||
import akka.cluster.routing.ClusterRouterGroupSettings;
|
||||
|
|
@ -6,7 +6,7 @@ import akka.cluster.routing.ClusterRouterPool;
|
|||
import akka.cluster.routing.ClusterRouterPoolSettings;
|
||||
import akka.routing.ConsistentHashingGroup;
|
||||
import akka.routing.ConsistentHashingPool;
|
||||
import docs.cluster.StatsMessages.StatsJob;
|
||||
import jdocs.cluster.StatsMessages.StatsJob;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.Props;
|
||||
import akka.actor.AbstractActor;
|
||||
|
|
@ -30,7 +30,7 @@ public class StatsService extends AbstractActor {
|
|||
return receiveBuilder()
|
||||
.match(StatsJob.class, job -> !job.getText().isEmpty(), job -> {
|
||||
String[] words = job.getText().split(" ");
|
||||
ActorRef replyTo = sender();
|
||||
ActorRef replyTo = getSender();
|
||||
|
||||
// create actor that collects replies from workers
|
||||
ActorRef aggregator = getContext().actorOf(
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -19,7 +19,7 @@ public class StatsWorker extends AbstractActor {
|
|||
length = word.length();
|
||||
cache.put(word, length);
|
||||
}
|
||||
sender().tell(length, self());
|
||||
getSender().tell(length, getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import static docs.cluster.TransformationMessages.BACKEND_REGISTRATION;
|
||||
import docs.cluster.TransformationMessages.TransformationJob;
|
||||
import docs.cluster.TransformationMessages.TransformationResult;
|
||||
import static jdocs.cluster.TransformationMessages.BACKEND_REGISTRATION;
|
||||
import jdocs.cluster.TransformationMessages.TransformationJob;
|
||||
import jdocs.cluster.TransformationMessages.TransformationResult;
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.cluster.Cluster;
|
||||
import akka.cluster.ClusterEvent.CurrentClusterState;
|
||||
|
|
@ -13,7 +13,7 @@ import akka.cluster.MemberStatus;
|
|||
//#backend
|
||||
public class TransformationBackend extends AbstractActor {
|
||||
|
||||
Cluster cluster = Cluster.get(getContext().system());
|
||||
Cluster cluster = Cluster.get(getContext().getSystem());
|
||||
|
||||
//subscribe to cluster changes, MemberUp
|
||||
@Override
|
||||
|
|
@ -31,8 +31,8 @@ public class TransformationBackend extends AbstractActor {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(TransformationJob.class, job -> {
|
||||
sender().tell(new TransformationResult(job.getText().toUpperCase()),
|
||||
self());
|
||||
getSender().tell(new TransformationResult(job.getText().toUpperCase()),
|
||||
getSelf());
|
||||
})
|
||||
.match(CurrentClusterState.class, state -> {
|
||||
for (Member member : state.getMembers()) {
|
||||
|
|
@ -50,7 +50,7 @@ public class TransformationBackend extends AbstractActor {
|
|||
void register(Member member) {
|
||||
if (member.hasRole("frontend"))
|
||||
getContext().actorSelection(member.address() + "/user/frontend").tell(
|
||||
BACKEND_REGISTRATION, self());
|
||||
BACKEND_REGISTRATION, getSelf());
|
||||
}
|
||||
}
|
||||
//#backend
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import static docs.cluster.TransformationMessages.BACKEND_REGISTRATION;
|
||||
import static jdocs.cluster.TransformationMessages.BACKEND_REGISTRATION;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import docs.cluster.TransformationMessages.JobFailed;
|
||||
import docs.cluster.TransformationMessages.TransformationJob;
|
||||
import jdocs.cluster.TransformationMessages.JobFailed;
|
||||
import jdocs.cluster.TransformationMessages.TransformationJob;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.Terminated;
|
||||
import akka.actor.AbstractActor;
|
||||
|
|
@ -21,9 +21,9 @@ public class TransformationFrontend extends AbstractActor {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(TransformationJob.class, job -> backends.isEmpty(), job -> {
|
||||
sender().tell(
|
||||
getSender().tell(
|
||||
new JobFailed("Service unavailable, try again later", job),
|
||||
sender());
|
||||
getSender());
|
||||
})
|
||||
.match(TransformationJob.class, job -> {
|
||||
jobCounter++;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.cluster;
|
||||
package jdocs.cluster;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.ddata;
|
||||
package jdocs.ddata;
|
||||
|
||||
//#data-bot
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
|
|
@ -24,21 +24,20 @@ import akka.cluster.ddata.Replicator.Update;
|
|||
import akka.cluster.ddata.Replicator.UpdateResponse;
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
|
||||
public class DataBot extends AbstractActor {
|
||||
|
||||
private static final String TICK = "tick";
|
||||
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
private final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
private final Cluster node = Cluster.get(getContext().system());
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
private final Cluster node = Cluster.get(getContext().getSystem());
|
||||
|
||||
private final Cancellable tickTask = getContext().system().scheduler().schedule(
|
||||
Duration.create(5, SECONDS), Duration.create(5, SECONDS), self(), TICK,
|
||||
getContext().dispatcher(), self());
|
||||
private final Cancellable tickTask = getContext().getSystem().scheduler().schedule(
|
||||
Duration.create(5, SECONDS), Duration.create(5, SECONDS), getSelf(), TICK,
|
||||
getContext().dispatcher(), getSelf());
|
||||
|
||||
private final Key<ORSet<String>> dataKey = ORSetKey.create("key");
|
||||
|
||||
|
|
@ -63,7 +62,7 @@ public class DataBot extends AbstractActor {
|
|||
ORSet.create(),
|
||||
Replicator.writeLocal(),
|
||||
curr -> curr.add(node, s));
|
||||
replicator.tell(update, self());
|
||||
replicator.tell(update, getSelf());
|
||||
} else {
|
||||
// remove
|
||||
log.info("Removing: {}", s);
|
||||
|
|
@ -72,7 +71,7 @@ public class DataBot extends AbstractActor {
|
|||
ORSet.create(),
|
||||
Replicator.writeLocal(),
|
||||
curr -> curr.remove(node, s));
|
||||
replicator.tell(update, self());
|
||||
replicator.tell(update, getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +88,7 @@ public class DataBot extends AbstractActor {
|
|||
|
||||
@Override
|
||||
public void preStart() {
|
||||
Subscribe<ORSet<String>> subscribe = new Subscribe<>(dataKey, self());
|
||||
Subscribe<ORSet<String>> subscribe = new Subscribe<>(dataKey, getSelf());
|
||||
replicator.tell(subscribe, ActorRef.noSender());
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.ddata;
|
||||
package jdocs.ddata;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Arrays;
|
||||
|
|
@ -11,17 +11,16 @@ import java.util.Optional;
|
|||
|
||||
import akka.actor.*;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import docs.AbstractJavaTest;
|
||||
import docs.ddata.DistributedDataDocSpec;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import scala.PartialFunction;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import akka.cluster.Cluster;
|
||||
import akka.cluster.ddata.*;
|
||||
|
|
@ -29,11 +28,7 @@ import akka.japi.pf.ReceiveBuilder;
|
|||
|
||||
import static akka.cluster.ddata.Replicator.*;
|
||||
|
||||
import akka.testkit.AkkaSpec;
|
||||
import akka.testkit.ImplicitSender;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.TestProbe;
|
||||
import akka.serialization.SerializationExtension;
|
||||
|
||||
@SuppressWarnings({"unchecked", "unused"})
|
||||
public class DistributedDataDocTest extends AbstractJavaTest {
|
||||
|
|
@ -56,9 +51,9 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
static
|
||||
//#update
|
||||
class DemonstrateUpdate extends AbstractActor {
|
||||
final Cluster node = Cluster.get(getContext().system());
|
||||
final Cluster node = Cluster.get(getContext().getSystem());
|
||||
final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
|
||||
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
|
||||
final Key<GSet<String>> set1Key = GSetKey.create("set1");
|
||||
|
|
@ -71,20 +66,20 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
|
||||
b.matchEquals("demonstrate update", msg -> {
|
||||
replicator.tell(new Replicator.Update<PNCounter>(counter1Key, PNCounter.create(),
|
||||
Replicator.writeLocal(), curr -> curr.increment(node, 1)), self());
|
||||
Replicator.writeLocal(), curr -> curr.increment(node, 1)), getSelf());
|
||||
|
||||
final WriteConsistency writeTo3 = new WriteTo(3, Duration.create(1, SECONDS));
|
||||
replicator.tell(new Replicator.Update<GSet<String>>(set1Key, GSet.create(),
|
||||
writeTo3, curr -> curr.add("hello")), self());
|
||||
writeTo3, curr -> curr.add("hello")), getSelf());
|
||||
|
||||
final WriteConsistency writeMajority =
|
||||
new WriteMajority(Duration.create(5, SECONDS));
|
||||
replicator.tell(new Replicator.Update<ORSet<String>>(set2Key, ORSet.create(),
|
||||
writeMajority, curr -> curr.add(node, "hello")), self());
|
||||
writeMajority, curr -> curr.add(node, "hello")), getSelf());
|
||||
|
||||
final WriteConsistency writeAll = new WriteAll(Duration.create(5, SECONDS));
|
||||
replicator.tell(new Replicator.Update<Flag>(activeFlagKey, Flag.create(),
|
||||
writeAll, curr -> curr.switchOn()), self());
|
||||
writeAll, curr -> curr.switchOn()), getSelf());
|
||||
});
|
||||
//#update
|
||||
|
||||
|
|
@ -112,9 +107,9 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
static
|
||||
//#update-request-context
|
||||
class DemonstrateUpdateWithRequestContext extends AbstractActor {
|
||||
final Cluster node = Cluster.get(getContext().system());
|
||||
final Cluster node = Cluster.get(getContext().getSystem());
|
||||
final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
|
||||
final WriteConsistency writeTwo = new WriteTo(2, Duration.create(3, SECONDS));
|
||||
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
|
||||
|
|
@ -127,17 +122,17 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
Optional<Object> reqContext = Optional.of(sender());
|
||||
Replicator.Update<PNCounter> upd = new Replicator.Update<PNCounter>(counter1Key,
|
||||
PNCounter.create(), writeTwo, reqContext, curr -> curr.increment(node, 1));
|
||||
replicator.tell(upd, self());
|
||||
replicator.tell(upd, getSelf());
|
||||
})
|
||||
|
||||
.match(UpdateSuccess.class, a -> a.key().equals(counter1Key), a -> {
|
||||
ActorRef replyTo = (ActorRef) a.getRequest().get();
|
||||
replyTo.tell("ack", self());
|
||||
replyTo.tell("ack", getSelf());
|
||||
})
|
||||
|
||||
.match(UpdateTimeout.class, a -> a.key().equals(counter1Key), a -> {
|
||||
ActorRef replyTo = (ActorRef) a.getRequest().get();
|
||||
replyTo.tell("nack", self());
|
||||
replyTo.tell("nack", getSelf());
|
||||
})
|
||||
|
||||
.build();
|
||||
|
|
@ -149,7 +144,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
//#get
|
||||
class DemonstrateGet extends AbstractActor {
|
||||
final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
|
||||
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
|
||||
final Key<GSet<String>> set1Key = GSetKey.create("set1");
|
||||
|
|
@ -163,19 +158,19 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
b.matchEquals("demonstrate get", msg -> {
|
||||
|
||||
replicator.tell(new Replicator.Get<PNCounter>(counter1Key,
|
||||
Replicator.readLocal()), self());
|
||||
Replicator.readLocal()), getSelf());
|
||||
|
||||
final ReadConsistency readFrom3 = new ReadFrom(3, Duration.create(1, SECONDS));
|
||||
replicator.tell(new Replicator.Get<GSet<String>>(set1Key,
|
||||
readFrom3), self());
|
||||
readFrom3), getSelf());
|
||||
|
||||
final ReadConsistency readMajority = new ReadMajority(Duration.create(5, SECONDS));
|
||||
replicator.tell(new Replicator.Get<ORSet<String>>(set2Key,
|
||||
readMajority), self());
|
||||
readMajority), getSelf());
|
||||
|
||||
final ReadConsistency readAll = new ReadAll(Duration.create(5, SECONDS));
|
||||
replicator.tell(new Replicator.Get<Flag>(activeFlagKey,
|
||||
readAll), self());
|
||||
readAll), getSelf());
|
||||
|
||||
});
|
||||
//#get
|
||||
|
|
@ -213,7 +208,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
//#get-request-context
|
||||
class DemonstrateGetWithRequestContext extends AbstractActor {
|
||||
final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
|
||||
final ReadConsistency readTwo = new ReadFrom(2, Duration.create(3, SECONDS));
|
||||
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
|
||||
|
|
@ -225,24 +220,24 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
// incoming request to retrieve current value of the counter
|
||||
Optional<Object> reqContext = Optional.of(sender());
|
||||
replicator.tell(new Replicator.Get<PNCounter>(counter1Key,
|
||||
readTwo), self());
|
||||
readTwo), getSelf());
|
||||
})
|
||||
|
||||
.match(GetSuccess.class, a -> a.key().equals(counter1Key), a -> {
|
||||
ActorRef replyTo = (ActorRef) a.getRequest().get();
|
||||
GetSuccess<PNCounter> g = a;
|
||||
long value = g.dataValue().getValue().longValue();
|
||||
replyTo.tell(value, self());
|
||||
replyTo.tell(value, getSelf());
|
||||
})
|
||||
|
||||
.match(GetFailure.class, a -> a.key().equals(counter1Key), a -> {
|
||||
ActorRef replyTo = (ActorRef) a.getRequest().get();
|
||||
replyTo.tell(-1L, self());
|
||||
replyTo.tell(-1L, getSelf());
|
||||
})
|
||||
|
||||
.match(NotFound.class, a -> a.key().equals(counter1Key), a -> {
|
||||
ActorRef replyTo = (ActorRef) a.getRequest().get();
|
||||
replyTo.tell(0L, self());
|
||||
replyTo.tell(0L, getSelf());
|
||||
})
|
||||
|
||||
.build();
|
||||
|
|
@ -254,7 +249,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
//#subscribe
|
||||
class DemonstrateSubscribe extends AbstractActor {
|
||||
final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
|
||||
|
||||
BigInteger currentValue = BigInteger.valueOf(0);
|
||||
|
|
@ -268,7 +263,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
})
|
||||
.match(String.class, a -> a.equals("get-count"), a -> {
|
||||
// incoming request to retrieve current value of the counter
|
||||
sender().tell(currentValue, sender());
|
||||
getSender().tell(currentValue, getSender());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -276,7 +271,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
@Override
|
||||
public void preStart() {
|
||||
// subscribe to changes of the Counter1Key value
|
||||
replicator.tell(new Subscribe<PNCounter>(counter1Key, self()), ActorRef.noSender());
|
||||
replicator.tell(new Subscribe<PNCounter>(counter1Key, getSelf()), ActorRef.noSender());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -286,7 +281,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
//#delete
|
||||
class DemonstrateDelete extends AbstractActor {
|
||||
final ActorRef replicator =
|
||||
DistributedData.get(getContext().system()).replicator();
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
|
||||
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
|
||||
final Key<ORSet<String>> set2Key = ORSetKey.create("set2");
|
||||
|
|
@ -297,12 +292,12 @@ public class DistributedDataDocTest extends AbstractJavaTest {
|
|||
.matchEquals("demonstrate delete", msg -> {
|
||||
|
||||
replicator.tell(new Delete<PNCounter>(counter1Key,
|
||||
Replicator.writeLocal()), self());
|
||||
Replicator.writeLocal()), getSelf());
|
||||
|
||||
final WriteConsistency writeMajority =
|
||||
new WriteMajority(Duration.create(5, SECONDS));
|
||||
replicator.tell(new Delete<PNCounter>(counter1Key,
|
||||
writeMajority), self());
|
||||
writeMajority), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -1,13 +1,12 @@
|
|||
package docs.ddata;
|
||||
package jdocs.ddata;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import java.io.Serializable;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import scala.PartialFunction;
|
||||
|
||||
import scala.concurrent.duration.Duration;
|
||||
import scala.runtime.BoxedUnit;
|
||||
|
||||
import akka.actor.AbstractActor;
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -30,7 +29,6 @@ import akka.cluster.ddata.Replicator.UpdateSuccess;
|
|||
import akka.cluster.ddata.Replicator.UpdateTimeout;
|
||||
import akka.cluster.ddata.Replicator.WriteConsistency;
|
||||
import akka.cluster.ddata.Replicator.WriteMajority;
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ShoppingCart extends AbstractActor {
|
||||
|
|
@ -125,8 +123,8 @@ public class ShoppingCart extends AbstractActor {
|
|||
return Props.create(ShoppingCart.class, userId);
|
||||
}
|
||||
|
||||
private final ActorRef replicator = DistributedData.get(context().system()).replicator();
|
||||
private final Cluster node = Cluster.get(context().system());
|
||||
private final ActorRef replicator = DistributedData.get(getContext().getSystem()).replicator();
|
||||
private final Cluster node = Cluster.get(getContext().getSystem());
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String userId;
|
||||
|
|
@ -159,9 +157,9 @@ public class ShoppingCart extends AbstractActor {
|
|||
}
|
||||
|
||||
private void receiveGetCart() {
|
||||
Optional<Object> ctx = Optional.of(sender());
|
||||
Optional<Object> ctx = Optional.of(getSender());
|
||||
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, readMajority, ctx),
|
||||
self());
|
||||
getSelf());
|
||||
}
|
||||
|
||||
private boolean isResponseToGetCart(GetResponse<?> response) {
|
||||
|
|
@ -172,19 +170,19 @@ public class ShoppingCart extends AbstractActor {
|
|||
private void receiveGetSuccess(GetSuccess<LWWMap<String, LineItem>> g) {
|
||||
Set<LineItem> items = new HashSet<>(g.dataValue().getEntries().values());
|
||||
ActorRef replyTo = (ActorRef) g.getRequest().get();
|
||||
replyTo.tell(new Cart(items), self());
|
||||
replyTo.tell(new Cart(items), getSelf());
|
||||
}
|
||||
|
||||
private void receiveNotFound(NotFound<LWWMap<String, LineItem>> n) {
|
||||
ActorRef replyTo = (ActorRef) n.getRequest().get();
|
||||
replyTo.tell(new Cart(new HashSet<>()), self());
|
||||
replyTo.tell(new Cart(new HashSet<>()), getSelf());
|
||||
}
|
||||
|
||||
private void receiveGetFailure(GetFailure<LWWMap<String, LineItem>> f) {
|
||||
// ReadMajority failure, try again with local read
|
||||
Optional<Object> ctx = Optional.of(sender());
|
||||
Optional<Object> ctx = Optional.of(getSender());
|
||||
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, Replicator.readLocal(),
|
||||
ctx), self());
|
||||
ctx), getSelf());
|
||||
}
|
||||
//#get-cart
|
||||
|
||||
|
|
@ -198,7 +196,7 @@ public class ShoppingCart extends AbstractActor {
|
|||
private void receiveAddItem(AddItem add) {
|
||||
Update<LWWMap<String, LineItem>> update = new Update<>(dataKey, LWWMap.create(), writeMajority,
|
||||
cart -> updateCart(cart, add.item));
|
||||
replicator.tell(update, self());
|
||||
replicator.tell(update, getSelf());
|
||||
}
|
||||
|
||||
//#add-item
|
||||
|
|
@ -230,8 +228,8 @@ public class ShoppingCart extends AbstractActor {
|
|||
// Try to fetch latest from a majority of nodes first, since ORMap
|
||||
// remove must have seen the item to be able to remove it.
|
||||
Optional<Object> ctx = Optional.of(rm);
|
||||
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, readMajority, ctx),
|
||||
self());
|
||||
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, readMajority, ctx),
|
||||
getSelf());
|
||||
}
|
||||
|
||||
private void receiveRemoveItemGetSuccess(GetSuccess<LWWMap<String, LineItem>> g) {
|
||||
|
|
@ -249,7 +247,7 @@ public class ShoppingCart extends AbstractActor {
|
|||
private void removeItem(String productId) {
|
||||
Update<LWWMap<String, LineItem>> update = new Update<>(dataKey, LWWMap.create(), writeMajority,
|
||||
cart -> cart.remove(node, productId));
|
||||
replicator.tell(update, self());
|
||||
replicator.tell(update, getSelf());
|
||||
}
|
||||
|
||||
private boolean isResponseToRemoveItem(GetResponse<?> response) {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.ddata.japi;
|
||||
package jdocs.ddata;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.ddata.japi.protobuf;
|
||||
package jdocs.ddata.protobuf;
|
||||
|
||||
//#serializer
|
||||
import docs.ddata.japi.TwoPhaseSet;
|
||||
import jdocs.ddata.TwoPhaseSet;
|
||||
import docs.ddata.protobuf.msg.TwoPhaseSetMessages;
|
||||
import docs.ddata.protobuf.msg.TwoPhaseSetMessages.TwoPhaseSet.Builder;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -1,14 +1,12 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.ddata.japi.protobuf;
|
||||
package jdocs.ddata.protobuf;
|
||||
|
||||
//#serializer
|
||||
import docs.ddata.japi.TwoPhaseSet;
|
||||
import jdocs.ddata.TwoPhaseSet;
|
||||
import docs.ddata.protobuf.msg.TwoPhaseSetMessages;
|
||||
import docs.ddata.protobuf.msg.TwoPhaseSetMessages.TwoPhaseSet2.Builder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
import akka.actor.ExtendedActorSystem;
|
||||
import akka.cluster.ddata.GSet;
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.ddata.japi.protobuf;
|
||||
package jdocs.ddata.protobuf;
|
||||
|
||||
import docs.ddata.japi.TwoPhaseSet;
|
||||
import jdocs.ddata.TwoPhaseSet;
|
||||
|
||||
import akka.actor.ExtendedActorSystem;
|
||||
|
||||
|
|
@ -1,15 +1,16 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.dispatcher;
|
||||
package jdocs.dispatcher;
|
||||
|
||||
import akka.dispatch.ControlMessage;
|
||||
import akka.dispatch.RequiresMessageQueue;
|
||||
import akka.testkit.AkkaSpec;
|
||||
import com.typesafe.config.ConfigFactory;
|
||||
import docs.AbstractJavaTest;
|
||||
import docs.actorlambda.MyBoundedActor;
|
||||
import docs.actorlambda.MyActor;
|
||||
import docs.dispatcher.DispatcherDocSpec;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import jdocs.actor.MyBoundedActor;
|
||||
import jdocs.actor.MyActor;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.ExecutionContext;
|
||||
|
|
@ -17,7 +18,6 @@ import scala.concurrent.ExecutionContext;
|
|||
//#imports
|
||||
import akka.actor.*;
|
||||
//#imports
|
||||
import akka.actor.AbstractActor.Receive;
|
||||
//#imports-prio
|
||||
import akka.event.Logging;
|
||||
import akka.event.LoggingAdapter;
|
||||
|
|
@ -127,12 +127,12 @@ public class DispatcherDocTest extends AbstractJavaTest {
|
|||
//#prio-dispatcher
|
||||
|
||||
class Demo extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
{
|
||||
for (Object msg : new Object[] { "lowpriority", "lowpriority",
|
||||
"highpriority", "pigdog", "pigdog2", "pigdog3", "highpriority",
|
||||
PoisonPill.getInstance() }) {
|
||||
self().tell(msg, self());
|
||||
getSelf().tell(msg, getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,11 +170,11 @@ public class DispatcherDocTest extends AbstractJavaTest {
|
|||
//#control-aware-dispatcher
|
||||
|
||||
class Demo extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
{
|
||||
for (Object msg : new Object[] { "foo", "bar", new MyControlMessage(),
|
||||
PoisonPill.getInstance() }) {
|
||||
self().tell(msg, self());
|
||||
getSelf().tell(msg, getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ public class DispatcherDocTest extends AbstractJavaTest {
|
|||
static
|
||||
//#require-mailbox-on-actor
|
||||
public class MySpecialActor extends AbstractActor implements
|
||||
RequiresMessageQueue<MyUnboundedJMessageQueueSemantics> {
|
||||
RequiresMessageQueue<MyUnboundedMessageQueueSemantics> {
|
||||
//#require-mailbox-on-actor
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.dispatcher;
|
||||
package jdocs.dispatcher;
|
||||
|
||||
//#mailbox-implementation-example
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -15,12 +15,12 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
import java.util.Queue;
|
||||
import scala.Option;
|
||||
|
||||
public class MyUnboundedJMailbox implements MailboxType,
|
||||
ProducesMessageQueue<MyUnboundedJMailbox.MyMessageQueue> {
|
||||
public class MyUnboundedMailbox implements MailboxType,
|
||||
ProducesMessageQueue<MyUnboundedMailbox.MyMessageQueue> {
|
||||
|
||||
// This is the MessageQueue implementation
|
||||
public static class MyMessageQueue implements MessageQueue,
|
||||
MyUnboundedJMessageQueueSemantics {
|
||||
MyUnboundedMessageQueueSemantics {
|
||||
private final Queue<Envelope> queue =
|
||||
new ConcurrentLinkedQueue<Envelope>();
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ public class MyUnboundedJMailbox implements MailboxType,
|
|||
}
|
||||
|
||||
// This constructor signature must exist, it will be called by Akka
|
||||
public MyUnboundedJMailbox(ActorSystem.Settings settings, Config config) {
|
||||
public MyUnboundedMailbox(ActorSystem.Settings settings, Config config) {
|
||||
// put your initialization code here
|
||||
}
|
||||
|
||||
|
|
@ -2,10 +2,10 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.dispatcher;
|
||||
package jdocs.dispatcher;
|
||||
|
||||
//#mailbox-implementation-example
|
||||
// Marker interface used for mailbox requirements mapping
|
||||
public interface MyUnboundedJMessageQueueSemantics {
|
||||
public interface MyUnboundedMessageQueueSemantics {
|
||||
}
|
||||
//#mailbox-implementation-example
|
||||
|
|
@ -1,36 +1,30 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.event;
|
||||
package jdocs.event;
|
||||
|
||||
import akka.event.japi.EventBus;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.ActorRef;
|
||||
import akka.event.japi.*;
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import akka.event.japi.EventBus;
|
||||
import akka.util.Subclassification;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import scala.concurrent.duration.FiniteDuration;
|
||||
|
||||
//#lookup-bus
|
||||
import akka.event.japi.LookupEventBus;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
//#lookup-bus
|
||||
|
||||
//#subchannel-bus
|
||||
import akka.event.japi.SubchannelEventBus;
|
||||
import akka.util.Subclassification;
|
||||
|
||||
//#subchannel-bus
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.event;
|
||||
package jdocs.event;
|
||||
|
||||
//#imports
|
||||
import akka.actor.*;
|
||||
|
|
@ -19,13 +19,12 @@ import akka.event.Logging.Debug;
|
|||
|
||||
//#imports-listener
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.Test;
|
||||
import akka.testkit.JavaTestKit;
|
||||
import java.util.Optional;
|
||||
|
||||
//#imports-mdc
|
||||
import akka.event.Logging;
|
||||
import akka.event.DiagnosticLoggingAdapter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -85,10 +84,10 @@ public class LoggingDocTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Jazz.class, msg ->
|
||||
System.out.printf("%s is listening to: %s%n", self().path().name(), msg)
|
||||
System.out.printf("%s is listening to: %s%n", getSelf().path().name(), msg)
|
||||
)
|
||||
.match(Electronic.class, msg ->
|
||||
System.out.printf("%s is listening to: %s%n", self().path().name(), msg)
|
||||
System.out.printf("%s is listening to: %s%n", getSelf().path().name(), msg)
|
||||
)
|
||||
.build();
|
||||
}
|
||||
|
|
@ -152,7 +151,7 @@ public class LoggingDocTest extends AbstractJavaTest {
|
|||
|
||||
//#my-actor
|
||||
class MyActor extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
@Override
|
||||
public void preStart() {
|
||||
|
|
@ -211,7 +210,7 @@ public class LoggingDocTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(InitializeLogger.class, msg -> {
|
||||
sender().tell(Logging.loggerInitialized(), self());
|
||||
getSender().tell(Logging.loggerInitialized(), getSelf());
|
||||
})
|
||||
.match(Error.class, msg -> {
|
||||
// ...
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.extension;
|
||||
package jdocs.extension;
|
||||
|
||||
//#imports
|
||||
import akka.actor.*;
|
||||
|
|
@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
|||
|
||||
//#imports
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtensionDocTest extends AbstractJavaTest {
|
||||
|
|
@ -64,7 +64,7 @@ public class ExtensionDocTest extends AbstractJavaTest {
|
|||
.matchAny(msg -> {
|
||||
// typically you would use static import of the
|
||||
// CountExtension.CountExtensionProvider field
|
||||
CountExtension.CountExtensionProvider.get(getContext().system()).increment();
|
||||
CountExtension.CountExtensionProvider.get(getContext().getSystem()).increment();
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.extension;
|
||||
package jdocs.extension;
|
||||
|
||||
//#imports
|
||||
import akka.actor.Extension;
|
||||
|
|
@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
//#imports
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import akka.actor.AbstractActor;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ public class SettingsExtensionDocTest extends AbstractJavaTest {
|
|||
public class MyActor extends AbstractActor {
|
||||
// typically you would use static import of the Settings.SettingsProvider field
|
||||
final SettingsImpl settings =
|
||||
Settings.SettingsProvider.get(getContext().system());
|
||||
Settings.SettingsProvider.get(getContext().getSystem());
|
||||
Connection connection =
|
||||
connect(settings.DB_URI, settings.CIRCUIT_BREAKER_TIMEOUT);
|
||||
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
package docs.future;
|
||||
package jdocs.future;
|
||||
|
||||
//#imports1
|
||||
import akka.dispatch.*;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import scala.concurrent.ExecutionContext;
|
||||
import scala.concurrent.Future;
|
||||
import scala.concurrent.Await;
|
||||
|
|
@ -39,8 +39,6 @@ import static akka.dispatch.Futures.reduce;
|
|||
//#imports6
|
||||
|
||||
//#imports7
|
||||
import scala.concurrent.ExecutionContext;
|
||||
import scala.concurrent.ExecutionContext$;
|
||||
//#imports7
|
||||
|
||||
//#imports8
|
||||
|
|
@ -661,13 +659,13 @@ public class FutureDocTest extends AbstractJavaTest {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(String.class, msg -> {
|
||||
sender().tell(msg.toUpperCase(), self());
|
||||
getSender().tell(msg.toUpperCase(), getSelf());
|
||||
})
|
||||
.match(Integer.class, i -> {
|
||||
if (i < 0) {
|
||||
sender().tell(new Failure(new ArithmeticException("Negative values not supported")), self());
|
||||
getSender().tell(new Failure(new ArithmeticException("Negative values not supported")), getSelf());
|
||||
} else {
|
||||
sender().tell(i, self());
|
||||
getSender().tell(i, getSelf());
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
|
@ -2,10 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
package jdocs.io;
|
||||
|
||||
import akka.actor.ActorSystem;
|
||||
import akka.actor.AbstractActor;
|
||||
|
|
@ -16,7 +13,6 @@ import java.util.List;
|
|||
import akka.actor.ActorRef;
|
||||
import akka.io.Inet;
|
||||
import akka.io.Tcp;
|
||||
import akka.io.TcpExt;
|
||||
import akka.io.TcpMessage;
|
||||
import akka.io.TcpSO;
|
||||
import akka.util.ByteString;
|
||||
|
|
@ -26,7 +22,7 @@ public class IODocTest {
|
|||
|
||||
static public class Demo extends AbstractActor {
|
||||
ActorRef connectionActor = null;
|
||||
ActorRef listener = self();
|
||||
ActorRef listener = getSelf();
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
|
|
@ -38,20 +34,20 @@ public class IODocTest {
|
|||
//#connect
|
||||
final InetSocketAddress remoteAddr = new InetSocketAddress("127.0.0.1",
|
||||
12345);
|
||||
tcp.tell(TcpMessage.connect(remoteAddr), self());
|
||||
tcp.tell(TcpMessage.connect(remoteAddr), getSelf());
|
||||
//#connect
|
||||
//#connect-with-options
|
||||
final InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
|
||||
1234);
|
||||
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
|
||||
options.add(TcpSO.keepAlive(true));
|
||||
tcp.tell(TcpMessage.connect(remoteAddr, localAddr, options, null, false), self());
|
||||
tcp.tell(TcpMessage.connect(remoteAddr, localAddr, options, null, false), getSelf());
|
||||
//#connect-with-options
|
||||
})
|
||||
//#connected
|
||||
.match(Tcp.Connected.class, conn -> {
|
||||
connectionActor = sender();
|
||||
connectionActor.tell(TcpMessage.register(listener), self());
|
||||
connectionActor = getSender();
|
||||
connectionActor.tell(TcpMessage.register(listener), getSelf());
|
||||
})
|
||||
//#connected
|
||||
//#received
|
||||
|
|
@ -70,14 +66,14 @@ public class IODocTest {
|
|||
})
|
||||
//#received
|
||||
.matchEquals("bind", msg -> {
|
||||
final ActorRef handler = self();
|
||||
final ActorRef handler = getSelf();
|
||||
//#bind
|
||||
final ActorRef tcp = Tcp.get(system).manager();
|
||||
final InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
|
||||
1234);
|
||||
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
|
||||
options.add(TcpSO.reuseAddress(true));
|
||||
tcp.tell(TcpMessage.bind(handler, localAddr, 10, options, false), self());
|
||||
tcp.tell(TcpMessage.bind(handler, localAddr, 10, options, false), getSelf());
|
||||
//#bind
|
||||
})
|
||||
.build();
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package docs.io;
|
||||
package jdocs.io;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.Props;
|
||||
|
|
@ -26,15 +26,15 @@ public class JavaReadBackPressure {
|
|||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Tcp.Bound.class, x -> {
|
||||
listener = sender();
|
||||
listener = getSender();
|
||||
// Accept connections one by one
|
||||
listener.tell(TcpMessage.resumeAccepting(1), self());
|
||||
listener.tell(TcpMessage.resumeAccepting(1), getSelf());
|
||||
})
|
||||
.match(Tcp.Connected.class, x -> {
|
||||
ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, sender()));
|
||||
sender().tell(TcpMessage.register(handler), self());
|
||||
ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, getSender()));
|
||||
getSender().tell(TcpMessage.register(handler), getSelf());
|
||||
// Resume accepting connections
|
||||
listener.tell(TcpMessage.resumeAccepting(1), self());
|
||||
listener.tell(TcpMessage.resumeAccepting(1), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -43,11 +43,11 @@ public class JavaReadBackPressure {
|
|||
@Override
|
||||
public void preStart() throws Exception {
|
||||
//#pull-mode-bind
|
||||
tcp = Tcp.get(getContext().system()).manager();
|
||||
tcp = Tcp.get(getContext().getSystem()).manager();
|
||||
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
|
||||
tcp.tell(
|
||||
TcpMessage.bind(self(), new InetSocketAddress("localhost", 0), 100, options, true),
|
||||
self()
|
||||
getSelf()
|
||||
);
|
||||
//#pull-mode-bind
|
||||
}
|
||||
|
|
@ -57,7 +57,7 @@ public class JavaReadBackPressure {
|
|||
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
|
||||
tcp.tell(
|
||||
TcpMessage.connect(new InetSocketAddress("localhost", 3000), null, options, null, true),
|
||||
self()
|
||||
getSelf()
|
||||
);
|
||||
//#pull-mode-connect
|
||||
}
|
||||
|
|
@ -76,7 +76,7 @@ public class JavaReadBackPressure {
|
|||
//#pull-reading-echo
|
||||
@Override
|
||||
public void preStart() throws Exception {
|
||||
connection.tell(TcpMessage.resumeReading(), self());
|
||||
connection.tell(TcpMessage.resumeReading(), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -84,10 +84,10 @@ public class JavaReadBackPressure {
|
|||
return receiveBuilder()
|
||||
.match(Tcp.Received.class, message -> {
|
||||
ByteString data = message.data();
|
||||
connection.tell(TcpMessage.write(data, new Ack()), self());
|
||||
connection.tell(TcpMessage.write(data, new Ack()), getSelf());
|
||||
})
|
||||
.match(Ack.class, message -> {
|
||||
connection.tell(TcpMessage.resumeReading(), self());
|
||||
connection.tell(TcpMessage.resumeReading(), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io;
|
||||
package jdocs.io;
|
||||
|
||||
//#imports
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -58,7 +58,7 @@ public class JavaUdpMulticast {
|
|||
//#multicast-group
|
||||
|
||||
public static class Listener extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
ActorRef sink;
|
||||
|
||||
|
|
@ -70,10 +70,10 @@ public class JavaUdpMulticast {
|
|||
options.add(new Inet6ProtocolFamily());
|
||||
options.add(new MulticastGroup(group, iface));
|
||||
|
||||
final ActorRef mgr = Udp.get(getContext().system()).getManager();
|
||||
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
|
||||
// listen for datagrams on this address
|
||||
InetSocketAddress endpoint = new InetSocketAddress(port);
|
||||
mgr.tell(UdpMessage.bind(self(), endpoint, options), self());
|
||||
mgr.tell(UdpMessage.bind(self(), endpoint, options), getSelf());
|
||||
//#bind
|
||||
}
|
||||
|
||||
|
|
@ -82,19 +82,19 @@ public class JavaUdpMulticast {
|
|||
return receiveBuilder()
|
||||
.match(Udp.Bound.class, bound -> {
|
||||
log.info("Bound to {}", bound.localAddress());
|
||||
sink.tell(bound, self());
|
||||
sink.tell(bound, getSelf());
|
||||
})
|
||||
.match(Udp.Received.class, received -> {
|
||||
final String txt = received.data().decodeString("utf-8");
|
||||
log.info("Received '{}' from {}", txt, received.sender());
|
||||
sink.tell(txt, self());
|
||||
sink.tell(txt, getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Sender extends AbstractActor {
|
||||
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
|
||||
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
String iface;
|
||||
String group;
|
||||
|
|
@ -110,8 +110,8 @@ public class JavaUdpMulticast {
|
|||
List<Inet.SocketOption> options = new ArrayList<>();
|
||||
options.add(new Inet6ProtocolFamily());
|
||||
|
||||
final ActorRef mgr = Udp.get(getContext().system()).getManager();
|
||||
mgr.tell(UdpMessage.simpleSender(options), self());
|
||||
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
|
||||
mgr.tell(UdpMessage.simpleSender(options), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -120,7 +120,7 @@ public class JavaUdpMulticast {
|
|||
.match(Udp.SimpleSenderReady.class, x -> {
|
||||
InetSocketAddress remote = new InetSocketAddress(group + "%" + iface, port);
|
||||
log.info("Sending message to " + remote);
|
||||
sender().tell(UdpMessage.send(ByteString.fromString(message), remote), self());
|
||||
getSender().tell(UdpMessage.send(ByteString.fromString(message), remote), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io;
|
||||
package jdocs.io;
|
||||
|
||||
import akka.actor.ActorRef;
|
||||
import akka.actor.ActorSystem;
|
||||
|
|
@ -11,7 +11,7 @@ import akka.io.Udp;
|
|||
import akka.testkit.JavaTestKit;
|
||||
import akka.testkit.SocketUtil;
|
||||
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io;
|
||||
package jdocs.io;
|
||||
|
||||
import akka.japi.pf.ReceiveBuilder;
|
||||
import org.junit.Test;
|
||||
|
|
@ -25,8 +25,8 @@ public class UdpConnectedDocTest {
|
|||
|
||||
static public class Demo extends AbstractActor {
|
||||
ActorRef connectionActor = null;
|
||||
ActorRef handler = self();
|
||||
ActorSystem system = getContext().system();
|
||||
ActorRef handler = getSelf();
|
||||
ActorSystem system = getContext().getSystem();
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
|
|
@ -38,7 +38,7 @@ public class UdpConnectedDocTest {
|
|||
//#connect
|
||||
final InetSocketAddress remoteAddr =
|
||||
new InetSocketAddress("127.0.0.1", 12345);
|
||||
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr), self());
|
||||
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr), getSelf());
|
||||
//#connect
|
||||
//#connect-with-options
|
||||
final InetSocketAddress localAddr =
|
||||
|
|
@ -46,12 +46,12 @@ public class UdpConnectedDocTest {
|
|||
final List<Inet.SocketOption> options =
|
||||
new ArrayList<Inet.SocketOption>();
|
||||
options.add(UdpSO.broadcast(true));
|
||||
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr, localAddr, options), self());
|
||||
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr, localAddr, options), getSelf());
|
||||
//#connect-with-options
|
||||
});
|
||||
//#connected
|
||||
builder.match(UdpConnected.Connected.class, conn -> {
|
||||
connectionActor = sender(); // Save the worker ref for later use
|
||||
connectionActor = getSender(); // Save the worker ref for later use
|
||||
});
|
||||
//#connected
|
||||
//#received
|
||||
|
|
@ -71,7 +71,7 @@ public class UdpConnectedDocTest {
|
|||
builder.matchEquals("send", x -> {
|
||||
ByteString data = ByteString.empty();
|
||||
//#send
|
||||
connectionActor.tell(UdpConnectedMessage.send(data), self());
|
||||
connectionActor.tell(UdpConnectedMessage.send(data), getSelf());
|
||||
//#send
|
||||
});
|
||||
return builder.build();
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io;
|
||||
package jdocs.io;
|
||||
|
||||
//#imports
|
||||
import akka.actor.ActorRef;
|
||||
|
|
@ -12,7 +12,6 @@ import akka.io.Udp;
|
|||
import akka.io.UdpConnected;
|
||||
import akka.io.UdpConnectedMessage;
|
||||
import akka.io.UdpMessage;
|
||||
import akka.japi.Procedure;
|
||||
import akka.util.ByteString;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
|
@ -28,8 +27,8 @@ public class UdpDocTest {
|
|||
this.remote = remote;
|
||||
|
||||
// request creation of a SimpleSender
|
||||
final ActorRef mgr = Udp.get(getContext().system()).getManager();
|
||||
mgr.tell(UdpMessage.simpleSender(), self());
|
||||
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
|
||||
mgr.tell(UdpMessage.simpleSender(), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -38,7 +37,7 @@ public class UdpDocTest {
|
|||
.match(Udp.SimpleSenderReady.class, message -> {
|
||||
getContext().become(ready(sender()));
|
||||
//#sender
|
||||
sender().tell(UdpMessage.send(ByteString.fromString("hello"), remote), self());
|
||||
getSender().tell(UdpMessage.send(ByteString.fromString("hello"), remote), getSelf());
|
||||
//#sender
|
||||
})
|
||||
.build();
|
||||
|
|
@ -47,10 +46,10 @@ public class UdpDocTest {
|
|||
private Receive ready(final ActorRef send) {
|
||||
return receiveBuilder()
|
||||
.match(String.class, message -> {
|
||||
send.tell(UdpMessage.send(ByteString.fromString(message), remote), self());
|
||||
send.tell(UdpMessage.send(ByteString.fromString(message), remote), getSelf());
|
||||
//#sender
|
||||
if (message.equals("world")) {
|
||||
send.tell(PoisonPill.getInstance(), self());
|
||||
send.tell(PoisonPill.getInstance(), getSelf());
|
||||
}
|
||||
//#sender
|
||||
})
|
||||
|
|
@ -67,10 +66,10 @@ public class UdpDocTest {
|
|||
this.nextActor = nextActor;
|
||||
|
||||
// request creation of a bound listen socket
|
||||
final ActorRef mgr = Udp.get(getContext().system()).getManager();
|
||||
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
|
||||
mgr.tell(
|
||||
UdpMessage.bind(self(), new InetSocketAddress("localhost", 0)),
|
||||
self());
|
||||
getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -78,9 +77,9 @@ public class UdpDocTest {
|
|||
return receiveBuilder()
|
||||
.match(Udp.Bound.class, bound -> {
|
||||
//#listener
|
||||
nextActor.tell(bound.localAddress(), sender());
|
||||
nextActor.tell(bound.localAddress(), getSender());
|
||||
//#listener
|
||||
getContext().become(ready(sender()));
|
||||
getContext().become(ready(getSender()));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -89,19 +88,19 @@ public class UdpDocTest {
|
|||
return receiveBuilder()
|
||||
.match(Udp.Received.class, r -> {
|
||||
// echo server example: send back the data
|
||||
socket.tell(UdpMessage.send(r.data(), r.sender()), self());
|
||||
socket.tell(UdpMessage.send(r.data(), r.sender()), getSelf());
|
||||
// or do some processing and forward it on
|
||||
final Object processed = // parse data etc., e.g. using PipelineStage
|
||||
// #listener
|
||||
r.data().utf8String();
|
||||
//#listener
|
||||
nextActor.tell(processed, self());
|
||||
nextActor.tell(processed, getSelf());
|
||||
})
|
||||
.matchEquals(UdpMessage.unbind(), message -> {
|
||||
socket.tell(message, self());
|
||||
socket.tell(message, getSelf());
|
||||
})
|
||||
.match(Udp.Unbound.class, message -> {
|
||||
getContext().stop(self());
|
||||
getContext().stop(getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -116,8 +115,8 @@ public class UdpDocTest {
|
|||
this.remote = remote;
|
||||
|
||||
// create a restricted a.k.a. “connected” socket
|
||||
final ActorRef mgr = UdpConnected.get(getContext().system()).getManager();
|
||||
mgr.tell(UdpConnectedMessage.connect(self(), remote), self());
|
||||
final ActorRef mgr = UdpConnected.get(getContext().getSystem()).getManager();
|
||||
mgr.tell(UdpConnectedMessage.connect(self(), remote), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -126,9 +125,9 @@ public class UdpDocTest {
|
|||
.match(UdpConnected.Connected.class, message -> {
|
||||
getContext().become(ready(sender()));
|
||||
//#connected
|
||||
sender()
|
||||
getSender()
|
||||
.tell(UdpConnectedMessage.send(ByteString.fromString("hello")),
|
||||
self());
|
||||
getSelf());
|
||||
//#connected
|
||||
})
|
||||
.build();
|
||||
|
|
@ -142,17 +141,17 @@ public class UdpDocTest {
|
|||
if (r.data().utf8String().equals("hello")) {
|
||||
connection.tell(
|
||||
UdpConnectedMessage.send(ByteString.fromString("world")),
|
||||
self());
|
||||
getSelf());
|
||||
}
|
||||
// #connected
|
||||
})
|
||||
.match(String.class, str -> {
|
||||
connection
|
||||
.tell(UdpConnectedMessage.send(ByteString.fromString(str)),
|
||||
self());
|
||||
getSelf());
|
||||
})
|
||||
.matchEquals(UdpConnectedMessage.disconnect(), message -> {
|
||||
connection.tell(message, self());
|
||||
connection.tell(message, getSelf());
|
||||
})
|
||||
.match(UdpConnected.Disconnected.class, x -> {
|
||||
getContext().stop(self());
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io.japi;
|
||||
package jdocs.io.japi;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.LinkedList;
|
||||
|
|
@ -25,7 +25,7 @@ import akka.util.ByteString;
|
|||
public class EchoHandler extends AbstractActor {
|
||||
|
||||
final LoggingAdapter log = Logging
|
||||
.getLogger(getContext().system(), self());
|
||||
.getLogger(getContext().getSystem(), getSelf());
|
||||
|
||||
final ActorRef connection;
|
||||
final InetSocketAddress remote;
|
||||
|
|
@ -72,7 +72,7 @@ public class EchoHandler extends AbstractActor {
|
|||
return receiveBuilder()
|
||||
.match(Received.class, msg -> {
|
||||
final ByteString data = msg.data();
|
||||
connection.tell(TcpMessage.write(data, new Ack(currentOffset())), self());
|
||||
connection.tell(TcpMessage.write(data, new Ack(currentOffset())), getSelf());
|
||||
buffer(data);
|
||||
|
||||
})
|
||||
|
|
@ -81,7 +81,7 @@ public class EchoHandler extends AbstractActor {
|
|||
})
|
||||
.match(CommandFailed.class, msg -> {
|
||||
final Write w = (Write) msg.cmd();
|
||||
connection.tell(TcpMessage.resumeWriting(), self());
|
||||
connection.tell(TcpMessage.resumeWriting(), getSelf());
|
||||
getContext().become(buffering((Ack) w.ack()));
|
||||
})
|
||||
.match(ConnectionClosed.class, msg -> {
|
||||
|
|
@ -159,7 +159,7 @@ public class EchoHandler extends AbstractActor {
|
|||
return receiveBuilder()
|
||||
.match(CommandFailed.class, msg -> {
|
||||
// the command can only have been a Write
|
||||
connection.tell(TcpMessage.resumeWriting(), self());
|
||||
connection.tell(TcpMessage.resumeWriting(), getSelf());
|
||||
getContext().become(closeResend(), false);
|
||||
})
|
||||
.match(Integer.class, msg -> {
|
||||
|
|
@ -201,7 +201,7 @@ public class EchoHandler extends AbstractActor {
|
|||
|
||||
} else if (stored > HIGH_WATERMARK) {
|
||||
log.debug("suspending reading at {}", currentOffset());
|
||||
connection.tell(TcpMessage.suspendReading(), self());
|
||||
connection.tell(TcpMessage.suspendReading(), getSelf());
|
||||
suspended = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ public class EchoHandler extends AbstractActor {
|
|||
|
||||
if (suspended && stored < LOW_WATERMARK) {
|
||||
log.debug("resuming reading");
|
||||
connection.tell(TcpMessage.resumeReading(), self());
|
||||
connection.tell(TcpMessage.resumeReading(), getSelf());
|
||||
suspended = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -230,12 +230,12 @@ public class EchoHandler extends AbstractActor {
|
|||
protected void writeAll() {
|
||||
int i = 0;
|
||||
for (ByteString data : storage) {
|
||||
connection.tell(TcpMessage.write(data, new Ack(storageOffset + i++)), self());
|
||||
connection.tell(TcpMessage.write(data, new Ack(storageOffset + i++)), getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeFirst() {
|
||||
connection.tell(TcpMessage.write(storage.peek(), new Ack(storageOffset)), self());
|
||||
connection.tell(TcpMessage.write(storage.peek(), new Ack(storageOffset)), getSelf());
|
||||
}
|
||||
|
||||
//#storage-omitted
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io.japi;
|
||||
package jdocs.io.japi;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
|
|
@ -15,14 +15,13 @@ import akka.event.LoggingAdapter;
|
|||
import akka.io.Tcp;
|
||||
import akka.io.Tcp.Bind;
|
||||
import akka.io.Tcp.Bound;
|
||||
import akka.io.Tcp.CommandFailed;
|
||||
import akka.io.Tcp.Connected;
|
||||
import akka.io.TcpMessage;
|
||||
|
||||
public class EchoManager extends AbstractActor {
|
||||
|
||||
final LoggingAdapter log = Logging
|
||||
.getLogger(getContext().system(), self());
|
||||
.getLogger(getContext().getSystem(), getSelf());
|
||||
|
||||
final Class<?> handlerClass;
|
||||
|
||||
|
|
@ -38,11 +37,11 @@ public class EchoManager extends AbstractActor {
|
|||
@Override
|
||||
public void preStart() throws Exception {
|
||||
//#manager
|
||||
final ActorRef tcpManager = Tcp.get(getContext().system()).manager();
|
||||
final ActorRef tcpManager = Tcp.get(getContext().getSystem()).manager();
|
||||
//#manager
|
||||
tcpManager.tell(
|
||||
TcpMessage.bind(self(), new InetSocketAddress("localhost", 0), 100),
|
||||
self());
|
||||
getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -67,13 +66,13 @@ public class EchoManager extends AbstractActor {
|
|||
})
|
||||
.match(Connected.class, conn -> {
|
||||
log.info("received connection from [{}]", conn.remoteAddress());
|
||||
final ActorRef connection = sender();
|
||||
final ActorRef connection = getSender();
|
||||
final ActorRef handler = getContext().actorOf(
|
||||
Props.create(handlerClass, connection, conn.remoteAddress()));
|
||||
//#echo-manager
|
||||
connection.tell(TcpMessage.register(handler,
|
||||
true, // <-- keepOpenOnPeerClosed flag
|
||||
true), self());
|
||||
true), getSelf());
|
||||
//#echo-manager
|
||||
})
|
||||
.build();
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io.japi;
|
||||
package jdocs.io.japi;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
@ -2,11 +2,11 @@
|
|||
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
|
||||
*/
|
||||
|
||||
package docs.io.japi;
|
||||
package jdocs.io.japi;
|
||||
|
||||
|
||||
import akka.testkit.AkkaJUnitActorSystemResource;
|
||||
import docs.AbstractJavaTest;
|
||||
import jdocs.AbstractJavaTest;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -23,7 +23,6 @@ import akka.io.Tcp.Connected;
|
|||
import akka.io.Tcp.ConnectionClosed;
|
||||
import akka.io.Tcp.Received;
|
||||
import akka.io.TcpMessage;
|
||||
import akka.japi.Procedure;
|
||||
import akka.util.ByteString;
|
||||
//#imports
|
||||
|
||||
|
|
@ -48,16 +47,16 @@ public class IODocTest extends AbstractJavaTest {
|
|||
|
||||
@Override
|
||||
public void preStart() throws Exception {
|
||||
final ActorRef tcp = Tcp.get(getContext().system()).manager();
|
||||
final ActorRef tcp = Tcp.get(getContext().getSystem()).manager();
|
||||
tcp.tell(TcpMessage.bind(self(),
|
||||
new InetSocketAddress("localhost", 0), 100), self());
|
||||
new InetSocketAddress("localhost", 0), 100), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(Bound.class, msg -> {
|
||||
manager.tell(msg, self());
|
||||
manager.tell(msg, getSelf());
|
||||
|
||||
})
|
||||
.match(CommandFailed.class, msg -> {
|
||||
|
|
@ -65,10 +64,10 @@ public class IODocTest extends AbstractJavaTest {
|
|||
|
||||
})
|
||||
.match(Connected.class, conn -> {
|
||||
manager.tell(conn, self());
|
||||
manager.tell(conn, getSelf());
|
||||
final ActorRef handler = getContext().actorOf(
|
||||
Props.create(SimplisticHandler.class));
|
||||
sender().tell(TcpMessage.register(handler), self());
|
||||
getSender().tell(TcpMessage.register(handler), getSelf());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
|
@ -85,7 +84,7 @@ public class IODocTest extends AbstractJavaTest {
|
|||
.match(Received.class, msg -> {
|
||||
final ByteString data = msg.data();
|
||||
System.out.println(data);
|
||||
sender().tell(TcpMessage.write(data), self());
|
||||
getSender().tell(TcpMessage.write(data), getSelf());
|
||||
})
|
||||
.match(ConnectionClosed.class, msg -> {
|
||||
getContext().stop(self());
|
||||
|
|
@ -110,21 +109,21 @@ public class IODocTest extends AbstractJavaTest {
|
|||
this.remote = remote;
|
||||
this.listener = listener;
|
||||
|
||||
final ActorRef tcp = Tcp.get(getContext().system()).manager();
|
||||
tcp.tell(TcpMessage.connect(remote), self());
|
||||
final ActorRef tcp = Tcp.get(getContext().getSystem()).manager();
|
||||
tcp.tell(TcpMessage.connect(remote), getSelf());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(CommandFailed.class, msg -> {
|
||||
listener.tell("failed", self());
|
||||
listener.tell("failed", getSelf());
|
||||
getContext().stop(self());
|
||||
|
||||
})
|
||||
.match(Connected.class, msg -> {
|
||||
listener.tell(msg, self());
|
||||
sender().tell(TcpMessage.register(self()), self());
|
||||
listener.tell(msg, getSelf());
|
||||
getSender().tell(TcpMessage.register(self()), getSelf());
|
||||
getContext().become(connected(sender()));
|
||||
})
|
||||
.build();
|
||||
|
|
@ -133,16 +132,16 @@ public class IODocTest extends AbstractJavaTest {
|
|||
private Receive connected(final ActorRef connection) {
|
||||
return receiveBuilder()
|
||||
.match(ByteString.class, msg -> {
|
||||
connection.tell(TcpMessage.write((ByteString) msg), self());
|
||||
connection.tell(TcpMessage.write((ByteString) msg), getSelf());
|
||||
})
|
||||
.match(CommandFailed.class, msg -> {
|
||||
// OS kernel socket buffer was full
|
||||
})
|
||||
.match(Received.class, msg -> {
|
||||
listener.tell(msg.data(), self());
|
||||
listener.tell(msg.data(), getSelf());
|
||||
})
|
||||
.matchEquals("close", msg -> {
|
||||
connection.tell(TcpMessage.close(), self());
|
||||
connection.tell(TcpMessage.close(), getSelf());
|
||||
})
|
||||
.match(ConnectionClosed.class, msg -> {
|
||||
getContext().stop(self());
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue