diff --git a/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java b/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java index 80b9c0a937..12cca2fc45 100644 --- a/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java +++ b/akka-actor/src/main/java/akka/japi/pf/ReceiveBuilder.java @@ -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() * ); * } diff --git a/akka-actor/src/main/scala/akka/actor/AbstractActor.scala b/akka-actor/src/main/scala/akka/actor/AbstractActor.scala index c002d5c7e2..3e73ec7fa2 100644 --- a/akka-actor/src/main/scala/akka/actor/AbstractActor.scala +++ b/akka-actor/src/main/scala/akka/actor/AbstractActor.scala @@ -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. diff --git a/akka-actor/src/main/scala/akka/actor/ActorCell.scala b/akka-actor/src/main/scala/akka/actor/ActorCell.scala index 4fa5428cf2..480f84b993 100644 --- a/akka-actor/src/main/scala/akka/actor/ActorCell.scala +++ b/akka-actor/src/main/scala/akka/actor/ActorCell.scala @@ -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 diff --git a/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala b/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala index 01ee0ffbd6..265efb23be 100644 --- a/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala +++ b/akka-camel/src/test/scala/akka/camel/CamelExchangeAdapterTest.scala @@ -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) -} +} diff --git a/akka-cluster-sharding/src/test/java/akka/cluster/sharding/ClusterShardingTest.java b/akka-cluster-sharding/src/test/java/akka/cluster/sharding/ClusterShardingTest.java index 69630eec5e..55bde97274 100644 --- a/akka-cluster-sharding/src/test/java/akka/cluster/sharding/ClusterShardingTest.java +++ b/akka-cluster-sharding/src/test/java/akka/cluster/sharding/ClusterShardingTest.java @@ -174,7 +174,7 @@ public class ClusterShardingTest { } private void passivate() { - getContext().parent().tell( + getContext().getParent().tell( new ShardRegion.Passivate(PoisonPill.getInstance()), getSelf()); } diff --git a/akka-docs/rst/java/actors.rst b/akka-docs/rst/java/actors.rst index 9c55fea9c0..90c92d36e1 100644 --- a/akka-docs/rst/java/actors.rst +++ b/akka-docs/rst/java/actors.rst @@ -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 ` 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 `_. +to `Javaslang Pattern Matching DSL `_. 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 `` 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. diff --git a/akka-docs/rst/java/agents.rst b/akka-docs/rst/java/agents.rst index 80d7a44c95..99385e09b0 100644 --- a/akka-docs/rst/java/agents.rst +++ b/akka-docs/rst/java/agents.rst @@ -36,7 +36,7 @@ Creating Agents Agents are created by invoking ``new Agent(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 diff --git a/akka-docs/rst/java/camel.rst b/akka-docs/rst/java/camel.rst index e41c173c4a..367ac52086 100644 --- a/akka-docs/rst/java/camel.rst +++ b/akka-docs/rst/java/camel.rst @@ -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 diff --git a/akka-docs/rst/java/cluster-client.rst b/akka-docs/rst/java/cluster-client.rst index 8f95e46d0c..176f30ab94 100644 --- a/akka-docs/rst/java/cluster-client.rst +++ b/akka-docs/rst/java/cluster-client.rst @@ -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. diff --git a/akka-docs/rst/java/cluster-metrics.rst b/akka-docs/rst/java/cluster-metrics.rst index 7fa1476ad4..fb5b8c9072 100644 --- a/akka-docs/rst/java/cluster-metrics.rst +++ b/akka-docs/rst/java/cluster-metrics.rst @@ -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 `_ tutorial named `Akka Cluster Samples with 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 ------------------------ diff --git a/akka-docs/rst/java/cluster-usage.rst b/akka-docs/rst/java/cluster-usage.rst index 7f942c2412..7d3f61b8df 100644 --- a/akka-docs/rst/java/cluster-usage.rst +++ b/akka-docs/rst/java/cluster-usage.rst @@ -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 `_, +`Split Brain Resolver `_, which is part of the `Lightbend Reactive Platform `_. -If you don’t use RP, you should anyway carefully read the `documentation `_ +If you don’t use RP, you should anyway carefully read the `documentation `_ 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 `_. +as described in `Monitoring and Management Using JMX Technology `_. Make sure you understand the security implications of enabling remote monitoring and management. .. _cluster_configuration_java: diff --git a/akka-docs/rst/java/code/docs/actorlambda/Messages.java b/akka-docs/rst/java/code/docs/actorlambda/Messages.java deleted file mode 100644 index cd15e38c5f..0000000000 --- a/akka-docs/rst/java/code/docs/actorlambda/Messages.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Copyright (C) 2009-2017 Lightbend Inc. - */ - -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 values; - - public ImmutableMessage(int sequenceNumber, List values) { - this.sequenceNumber = sequenceNumber; - this.values = Collections.unmodifiableList(new ArrayList(values)); - } - - public int getSequenceNumber() { - return sequenceNumber; - } - - public List 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; - } - } -} diff --git a/akka-docs/rst/java/code/docs/AbstractJavaTest.scala b/akka-docs/rst/java/code/jdocs/AbstractJavaTest.scala similarity index 94% rename from akka-docs/rst/java/code/docs/AbstractJavaTest.scala rename to akka-docs/rst/java/code/jdocs/AbstractJavaTest.scala index bb21c38803..907166eb81 100644 --- a/akka-docs/rst/java/code/docs/AbstractJavaTest.scala +++ b/akka-docs/rst/java/code/jdocs/AbstractJavaTest.scala @@ -1,7 +1,7 @@ /* * Copyright (C) 2016-2017 Lightbend Inc. */ -package docs +package jdocs import org.scalatest.junit.JUnitSuite diff --git a/akka-docs/rst/java/code/docs/actorlambda/ActorDocTest.java b/akka-docs/rst/java/code/jdocs/actor/ActorDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/actorlambda/ActorDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/ActorDocTest.java index 5f2b14993d..504bcdeff4 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/ActorDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/ActorDocTest.java @@ -2,14 +2,15 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 diff --git a/akka-docs/rst/java/code/docs/actor/ByteBufferSerializerDocTest.java b/akka-docs/rst/java/code/jdocs/actor/ByteBufferSerializerDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/actor/ByteBufferSerializerDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/ByteBufferSerializerDocTest.java index cb605f8781..95bacb8dee 100644 --- a/akka-docs/rst/java/code/docs/actor/ByteBufferSerializerDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/ByteBufferSerializerDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2016-2017 Lightbend Inc. */ -package docs.actor; +package jdocs.actor; //#bytebufserializer-with-manifest import akka.serialization.ByteBufferSerializer; diff --git a/akka-docs/rst/java/code/docs/actorlambda/DependencyInjectionDocTest.java b/akka-docs/rst/java/code/jdocs/actor/DependencyInjectionDocTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/actorlambda/DependencyInjectionDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/DependencyInjectionDocTest.java index fed5e15dfe..3f227eda6e 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/DependencyInjectionDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/DependencyInjectionDocTest.java @@ -1,9 +1,9 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); } diff --git a/akka-docs/rst/java/code/docs/actorlambda/FaultHandlingTest.java b/akka-docs/rst/java/code/jdocs/actor/FaultHandlingTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/actorlambda/FaultHandlingTest.java rename to akka-docs/rst/java/code/jdocs/actor/FaultHandlingTest.java index e7750df9ac..6bd0874837 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/FaultHandlingTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/FaultHandlingTest.java @@ -1,14 +1,14 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); } } diff --git a/akka-docs/rst/java/code/docs/actorlambda/GraduallyBuiltActor.java b/akka-docs/rst/java/code/jdocs/actor/GraduallyBuiltActor.java similarity index 87% rename from akka-docs/rst/java/code/docs/actorlambda/GraduallyBuiltActor.java rename to akka-docs/rst/java/code/jdocs/actor/GraduallyBuiltActor.java index 720dd8cc04..105a723629 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/GraduallyBuiltActor.java +++ b/akka-docs/rst/java/code/jdocs/actor/GraduallyBuiltActor.java @@ -2,20 +2,19 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 }); diff --git a/akka-docs/rst/java/code/docs/actor/ImmutableMessage.java b/akka-docs/rst/java/code/jdocs/actor/ImmutableMessage.java similarity index 96% rename from akka-docs/rst/java/code/docs/actor/ImmutableMessage.java rename to akka-docs/rst/java/code/jdocs/actor/ImmutableMessage.java index ea635c5f01..7b0e8b5710 100644 --- a/akka-docs/rst/java/code/docs/actor/ImmutableMessage.java +++ b/akka-docs/rst/java/code/jdocs/actor/ImmutableMessage.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.actor; +package jdocs.actor; import java.util.ArrayList; import java.util.Collections; diff --git a/akka-docs/rst/java/code/docs/actor/InboxDocTest.java b/akka-docs/rst/java/code/jdocs/actor/InboxDocTest.java similarity index 97% rename from akka-docs/rst/java/code/docs/actor/InboxDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/InboxDocTest.java index aa57d70940..d6ab1a0b6e 100644 --- a/akka-docs/rst/java/code/docs/actor/InboxDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/InboxDocTest.java @@ -2,12 +2,12 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/actorlambda/InitializationDocTest.java b/akka-docs/rst/java/code/jdocs/actor/InitializationDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/actorlambda/InitializationDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/InitializationDocTest.java index 9036c821f2..708910dd8e 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/InitializationDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/InitializationDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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 msg) -> { GenericMessage 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 msg) -> { - sender().tell(msg.value.toUpperCase(), self()); + getSender().tell(msg.value.toUpperCase(), getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/actor/Messages.java b/akka-docs/rst/java/code/jdocs/actor/Messages.java similarity index 99% rename from akka-docs/rst/java/code/docs/actor/Messages.java rename to akka-docs/rst/java/code/jdocs/actor/Messages.java index 717cf69212..93b2ed9881 100644 --- a/akka-docs/rst/java/code/docs/actor/Messages.java +++ b/akka-docs/rst/java/code/jdocs/actor/Messages.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.actor; +package jdocs.actor; import java.util.ArrayList; import java.util.Collections; diff --git a/akka-docs/rst/java/code/docs/actorlambda/MyActor.java b/akka-docs/rst/java/code/jdocs/actor/MyActor.java similarity index 88% rename from akka-docs/rst/java/code/docs/actorlambda/MyActor.java rename to akka-docs/rst/java/code/jdocs/actor/MyActor.java index be93290458..40f69f34ba 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/MyActor.java +++ b/akka-docs/rst/java/code/jdocs/actor/MyActor.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 }) diff --git a/akka-docs/rst/java/code/docs/actorlambda/MyBoundedActor.java b/akka-docs/rst/java/code/jdocs/actor/MyBoundedActor.java similarity index 80% rename from akka-docs/rst/java/code/docs/actorlambda/MyBoundedActor.java rename to akka-docs/rst/java/code/jdocs/actor/MyBoundedActor.java index 649395e9f5..dcec9a79ec 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/MyBoundedActor.java +++ b/akka-docs/rst/java/code/jdocs/actor/MyBoundedActor.java @@ -2,13 +2,13 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 { } //#my-bounded-untyped-actor diff --git a/akka-docs/rst/java/code/docs/actorlambda/MyStoppingActor.java b/akka-docs/rst/java/code/jdocs/actor/MyStoppingActor.java similarity index 89% rename from akka-docs/rst/java/code/docs/actorlambda/MyStoppingActor.java rename to akka-docs/rst/java/code/jdocs/actor/MyStoppingActor.java index ec00820d79..75627bc3c3 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/MyStoppingActor.java +++ b/akka-docs/rst/java/code/jdocs/actor/MyStoppingActor.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); } diff --git a/akka-docs/rst/java/code/docs/actorlambda/SampleActor.java b/akka-docs/rst/java/code/jdocs/actor/SampleActor.java similarity index 70% rename from akka-docs/rst/java/code/docs/actorlambda/SampleActor.java rename to akka-docs/rst/java/code/jdocs/actor/SampleActor.java index c9f232ee28..82607ebeee 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/SampleActor.java +++ b/akka-docs/rst/java/code/jdocs/actor/SampleActor.java @@ -2,17 +2,16 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); diff --git a/akka-docs/rst/java/code/docs/actorlambda/SampleActorTest.java b/akka-docs/rst/java/code/jdocs/actor/SampleActorTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/actorlambda/SampleActorTest.java rename to akka-docs/rst/java/code/jdocs/actor/SampleActorTest.java index 2f3d8440ea..1206b31783 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/SampleActorTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/SampleActorTest.java @@ -2,13 +2,13 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/actor/SchedulerDocTest.java b/akka-docs/rst/java/code/jdocs/actor/SchedulerDocTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/actor/SchedulerDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/SchedulerDocTest.java index 12bddbd84b..3ce7422f34 100644 --- a/akka-docs/rst/java/code/docs/actor/SchedulerDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/SchedulerDocTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/actor/TypedActorDocTest.java b/akka-docs/rst/java/code/jdocs/actor/TypedActorDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/actor/TypedActorDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/TypedActorDocTest.java index 7a7954a507..fa2eaae1ba 100644 --- a/akka-docs/rst/java/code/docs/actor/TypedActorDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/TypedActorDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/actorlambda/fsm/Buncher.java b/akka-docs/rst/java/code/jdocs/actor/fsm/Buncher.java similarity index 91% rename from akka-docs/rst/java/code/docs/actorlambda/fsm/Buncher.java rename to akka-docs/rst/java/code/jdocs/actor/fsm/Buncher.java index c06f81a1e3..35072fe5c5 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/fsm/Buncher.java +++ b/akka-docs/rst/java/code/jdocs/actor/fsm/Buncher.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 { diff --git a/akka-docs/rst/java/code/docs/actorlambda/fsm/BuncherTest.java b/akka-docs/rst/java/code/jdocs/actor/fsm/BuncherTest.java similarity index 86% rename from akka-docs/rst/java/code/docs/actorlambda/fsm/BuncherTest.java rename to akka-docs/rst/java/code/jdocs/actor/fsm/BuncherTest.java index 8c1ee1c39d..300578ea21 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/fsm/BuncherTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/fsm/BuncherTest.java @@ -2,23 +2,22 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 { diff --git a/akka-docs/rst/java/code/docs/actorlambda/fsm/Events.java b/akka-docs/rst/java/code/jdocs/actor/fsm/Events.java similarity index 98% rename from akka-docs/rst/java/code/docs/actorlambda/fsm/Events.java rename to akka-docs/rst/java/code/jdocs/actor/fsm/Events.java index 3c62b78ae9..3f45829561 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/fsm/Events.java +++ b/akka-docs/rst/java/code/jdocs/actor/fsm/Events.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.actorlambda.fsm; +package jdocs.actor.fsm; import akka.actor.ActorRef; import java.util.List; diff --git a/akka-docs/rst/java/code/docs/actorlambda/fsm/FSMDocTest.java b/akka-docs/rst/java/code/jdocs/actor/fsm/FSMDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/actorlambda/fsm/FSMDocTest.java rename to akka-docs/rst/java/code/jdocs/actor/fsm/FSMDocTest.java index 3815347e7d..6a19884c09 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/fsm/FSMDocTest.java +++ b/akka-docs/rst/java/code/jdocs/actor/fsm/FSMDocTest.java @@ -2,12 +2,11 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 { diff --git a/akka-docs/rst/java/code/docs/actorlambda/japi/FaultHandlingDocSample.java b/akka-docs/rst/java/code/jdocs/actor/japi/FaultHandlingDocSample.java similarity index 89% rename from akka-docs/rst/java/code/docs/actorlambda/japi/FaultHandlingDocSample.java rename to akka-docs/rst/java/code/jdocs/actor/japi/FaultHandlingDocSample.java index e806d86cad..4c00a2e337 100644 --- a/akka-docs/rst/java/code/docs/actorlambda/japi/FaultHandlingDocSample.java +++ b/akka-docs/rst/java/code/jdocs/actor/japi/FaultHandlingDocSample.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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 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()); } } diff --git a/akka-docs/rst/java/code/docs/agent/AgentDocTest.java b/akka-docs/rst/java/code/jdocs/agent/AgentDocTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/agent/AgentDocTest.java rename to akka-docs/rst/java/code/jdocs/agent/AgentDocTest.java index cf19f43854..e9b3fe1d6d 100644 --- a/akka-docs/rst/java/code/docs/agent/AgentDocTest.java +++ b/akka-docs/rst/java/code/jdocs/agent/AgentDocTest.java @@ -1,11 +1,10 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); diff --git a/akka-docs/rst/java/code/docs/camel/ActivationTestBase.java b/akka-docs/rst/java/code/jdocs/camel/ActivationTestBase.java similarity index 95% rename from akka-docs/rst/java/code/docs/camel/ActivationTestBase.java rename to akka-docs/rst/java/code/jdocs/camel/ActivationTestBase.java index 9e7b883d93..5e095e78b8 100644 --- a/akka-docs/rst/java/code/docs/camel/ActivationTestBase.java +++ b/akka-docs/rst/java/code/jdocs/camel/ActivationTestBase.java @@ -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; diff --git a/akka-docs/rst/java/code/docs/camel/CamelExtensionTest.java b/akka-docs/rst/java/code/jdocs/camel/CamelExtensionTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/camel/CamelExtensionTest.java rename to akka-docs/rst/java/code/jdocs/camel/CamelExtensionTest.java index 8cb3388cae..97d615cbe8 100644 --- a/akka-docs/rst/java/code/docs/camel/CamelExtensionTest.java +++ b/akka-docs/rst/java/code/jdocs/camel/CamelExtensionTest.java @@ -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; diff --git a/akka-docs/rst/java/code/docs/camel/Consumer1.java b/akka-docs/rst/java/code/jdocs/camel/Consumer1.java similarity index 97% rename from akka-docs/rst/java/code/docs/camel/Consumer1.java rename to akka-docs/rst/java/code/jdocs/camel/Consumer1.java index df21ee3fcc..95a9e2a845 100644 --- a/akka-docs/rst/java/code/docs/camel/Consumer1.java +++ b/akka-docs/rst/java/code/jdocs/camel/Consumer1.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#Consumer1 import akka.camel.CamelMessage; import akka.camel.javaapi.UntypedConsumerActor; diff --git a/akka-docs/rst/java/code/docs/camel/Consumer2.java b/akka-docs/rst/java/code/jdocs/camel/Consumer2.java similarity index 83% rename from akka-docs/rst/java/code/docs/camel/Consumer2.java rename to akka-docs/rst/java/code/jdocs/camel/Consumer2.java index 9ae8528937..198b231872 100644 --- a/akka-docs/rst/java/code/docs/camel/Consumer2.java +++ b/akka-docs/rst/java/code/jdocs/camel/Consumer2.java @@ -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); } diff --git a/akka-docs/rst/java/code/docs/camel/Consumer3.java b/akka-docs/rst/java/code/jdocs/camel/Consumer3.java similarity index 79% rename from akka-docs/rst/java/code/docs/camel/Consumer3.java rename to akka-docs/rst/java/code/jdocs/camel/Consumer3.java index 46516fae5d..6f08eef38c 100644 --- a/akka-docs/rst/java/code/docs/camel/Consumer3.java +++ b/akka-docs/rst/java/code/jdocs/camel/Consumer3.java @@ -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); } diff --git a/akka-docs/rst/java/code/docs/camel/Consumer4.java b/akka-docs/rst/java/code/jdocs/camel/Consumer4.java similarity index 90% rename from akka-docs/rst/java/code/docs/camel/Consumer4.java rename to akka-docs/rst/java/code/jdocs/camel/Consumer4.java index 8b1a0ac212..e1fe980bfc 100644 --- a/akka-docs/rst/java/code/docs/camel/Consumer4.java +++ b/akka-docs/rst/java/code/jdocs/camel/Consumer4.java @@ -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); } diff --git a/akka-docs/rst/java/code/docs/camel/CustomRouteBuilder.java b/akka-docs/rst/java/code/jdocs/camel/CustomRouteBuilder.java similarity index 95% rename from akka-docs/rst/java/code/docs/camel/CustomRouteBuilder.java rename to akka-docs/rst/java/code/jdocs/camel/CustomRouteBuilder.java index fd62d0dbbe..f2eea8d4f3 100644 --- a/akka-docs/rst/java/code/docs/camel/CustomRouteBuilder.java +++ b/akka-docs/rst/java/code/jdocs/camel/CustomRouteBuilder.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#CustomRoute import akka.actor.ActorRef; import akka.camel.internal.component.CamelPath; diff --git a/akka-docs/rst/java/code/docs/camel/CustomRouteTestBase.java b/akka-docs/rst/java/code/jdocs/camel/CustomRouteTestBase.java similarity index 96% rename from akka-docs/rst/java/code/docs/camel/CustomRouteTestBase.java rename to akka-docs/rst/java/code/jdocs/camel/CustomRouteTestBase.java index a02ac74d4a..b6d70ee7bc 100644 --- a/akka-docs/rst/java/code/docs/camel/CustomRouteTestBase.java +++ b/akka-docs/rst/java/code/jdocs/camel/CustomRouteTestBase.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; import akka.actor.ActorRef; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/camel/ErrorThrowingConsumer.java b/akka-docs/rst/java/code/jdocs/camel/ErrorThrowingConsumer.java similarity index 94% rename from akka-docs/rst/java/code/docs/camel/ErrorThrowingConsumer.java rename to akka-docs/rst/java/code/jdocs/camel/ErrorThrowingConsumer.java index 198488d2a6..da2e1e629b 100644 --- a/akka-docs/rst/java/code/docs/camel/ErrorThrowingConsumer.java +++ b/akka-docs/rst/java/code/jdocs/camel/ErrorThrowingConsumer.java @@ -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 message) { - sender().tell(new Status.Failure(reason), self()); + getSender().tell(new Status.Failure(reason), getSelf()); } } //#ErrorThrowingConsumer \ No newline at end of file diff --git a/akka-docs/rst/java/code/docs/camel/FirstProducer.java b/akka-docs/rst/java/code/jdocs/camel/FirstProducer.java similarity index 91% rename from akka-docs/rst/java/code/docs/camel/FirstProducer.java rename to akka-docs/rst/java/code/jdocs/camel/FirstProducer.java index c1b0c03698..d2f8724541 100644 --- a/akka-docs/rst/java/code/docs/camel/FirstProducer.java +++ b/akka-docs/rst/java/code/jdocs/camel/FirstProducer.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#Producer1 import akka.camel.javaapi.UntypedProducerActor; diff --git a/akka-docs/rst/java/code/docs/camel/Forwarder.java b/akka-docs/rst/java/code/jdocs/camel/Forwarder.java similarity index 95% rename from akka-docs/rst/java/code/docs/camel/Forwarder.java rename to akka-docs/rst/java/code/jdocs/camel/Forwarder.java index 7ddcc3628a..577234baae 100644 --- a/akka-docs/rst/java/code/docs/camel/Forwarder.java +++ b/akka-docs/rst/java/code/jdocs/camel/Forwarder.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#RouteResponse import akka.actor.ActorRef; import akka.camel.javaapi.UntypedProducerActor; diff --git a/akka-docs/rst/java/code/docs/camel/MyActor.java b/akka-docs/rst/java/code/jdocs/camel/MyActor.java similarity index 81% rename from akka-docs/rst/java/code/docs/camel/MyActor.java rename to akka-docs/rst/java/code/jdocs/camel/MyActor.java index 5fbbdb5b28..a95a15f757 100644 --- a/akka-docs/rst/java/code/docs/camel/MyActor.java +++ b/akka-docs/rst/java/code/jdocs/camel/MyActor.java @@ -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); } diff --git a/akka-docs/rst/java/code/docs/camel/MyEndpoint.java b/akka-docs/rst/java/code/jdocs/camel/MyEndpoint.java similarity index 96% rename from akka-docs/rst/java/code/docs/camel/MyEndpoint.java rename to akka-docs/rst/java/code/jdocs/camel/MyEndpoint.java index 0c31f200ed..8c41e5e286 100644 --- a/akka-docs/rst/java/code/docs/camel/MyEndpoint.java +++ b/akka-docs/rst/java/code/jdocs/camel/MyEndpoint.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#Consumer-mina import akka.camel.CamelMessage; diff --git a/akka-docs/rst/java/code/docs/camel/OnRouteResponseTestBase.java b/akka-docs/rst/java/code/jdocs/camel/OnRouteResponseTestBase.java similarity index 97% rename from akka-docs/rst/java/code/docs/camel/OnRouteResponseTestBase.java rename to akka-docs/rst/java/code/jdocs/camel/OnRouteResponseTestBase.java index 0e1e61e779..a7287119cc 100644 --- a/akka-docs/rst/java/code/docs/camel/OnRouteResponseTestBase.java +++ b/akka-docs/rst/java/code/jdocs/camel/OnRouteResponseTestBase.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; import akka.actor.*; import akka.testkit.JavaTestKit; diff --git a/akka-docs/rst/java/code/docs/camel/OnewaySender.java b/akka-docs/rst/java/code/jdocs/camel/OnewaySender.java similarity index 94% rename from akka-docs/rst/java/code/docs/camel/OnewaySender.java rename to akka-docs/rst/java/code/jdocs/camel/OnewaySender.java index 232e095730..58abb84639 100644 --- a/akka-docs/rst/java/code/docs/camel/OnewaySender.java +++ b/akka-docs/rst/java/code/jdocs/camel/OnewaySender.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#Oneway import akka.camel.javaapi.UntypedProducerActor; diff --git a/akka-docs/rst/java/code/docs/camel/Orders.java b/akka-docs/rst/java/code/jdocs/camel/Orders.java similarity index 90% rename from akka-docs/rst/java/code/docs/camel/Orders.java rename to akka-docs/rst/java/code/jdocs/camel/Orders.java index 8c61993bd6..5ebdbe0c92 100644 --- a/akka-docs/rst/java/code/docs/camel/Orders.java +++ b/akka-docs/rst/java/code/jdocs/camel/Orders.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#Producer import akka.camel.javaapi.UntypedProducerActor; diff --git a/akka-docs/rst/java/code/docs/camel/Producer1.java b/akka-docs/rst/java/code/jdocs/camel/Producer1.java similarity index 90% rename from akka-docs/rst/java/code/docs/camel/Producer1.java rename to akka-docs/rst/java/code/jdocs/camel/Producer1.java index 96bd697755..4d872e0685 100644 --- a/akka-docs/rst/java/code/docs/camel/Producer1.java +++ b/akka-docs/rst/java/code/jdocs/camel/Producer1.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#Producer1 import akka.camel.javaapi.UntypedProducerActor; diff --git a/akka-docs/rst/java/code/docs/camel/ProducerTestBase.java b/akka-docs/rst/java/code/jdocs/camel/ProducerTestBase.java similarity index 98% rename from akka-docs/rst/java/code/docs/camel/ProducerTestBase.java rename to akka-docs/rst/java/code/jdocs/camel/ProducerTestBase.java index f13712ba63..83b2e36c95 100644 --- a/akka-docs/rst/java/code/docs/camel/ProducerTestBase.java +++ b/akka-docs/rst/java/code/jdocs/camel/ProducerTestBase.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; import java.util.HashMap; import java.util.Map; diff --git a/akka-docs/rst/java/code/docs/camel/RequestBodyActor.java b/akka-docs/rst/java/code/jdocs/camel/RequestBodyActor.java similarity index 71% rename from akka-docs/rst/java/code/docs/camel/RequestBodyActor.java rename to akka-docs/rst/java/code/jdocs/camel/RequestBodyActor.java index 289c59dc80..b53e534f01 100644 --- a/akka-docs/rst/java/code/docs/camel/RequestBodyActor.java +++ b/akka-docs/rst/java/code/jdocs/camel/RequestBodyActor.java @@ -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(); } diff --git a/akka-docs/rst/java/code/docs/camel/Responder.java b/akka-docs/rst/java/code/jdocs/camel/Responder.java similarity index 85% rename from akka-docs/rst/java/code/docs/camel/Responder.java rename to akka-docs/rst/java/code/jdocs/camel/Responder.java index fddbc247fa..8af132d4e4 100644 --- a/akka-docs/rst/java/code/docs/camel/Responder.java +++ b/akka-docs/rst/java/code/jdocs/camel/Responder.java @@ -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); } diff --git a/akka-docs/rst/java/code/docs/camel/ResponseReceiver.java b/akka-docs/rst/java/code/jdocs/camel/ResponseReceiver.java similarity index 93% rename from akka-docs/rst/java/code/docs/camel/ResponseReceiver.java rename to akka-docs/rst/java/code/jdocs/camel/ResponseReceiver.java index e3d7a033ef..ca5f2cf8d1 100644 --- a/akka-docs/rst/java/code/docs/camel/ResponseReceiver.java +++ b/akka-docs/rst/java/code/jdocs/camel/ResponseReceiver.java @@ -1,4 +1,4 @@ -package docs.camel; +package jdocs.camel; //#RouteResponse import akka.actor.UntypedAbstractActor; import akka.camel.CamelMessage; diff --git a/akka-docs/rst/java/code/docs/camel/Transformer.java b/akka-docs/rst/java/code/jdocs/camel/Transformer.java similarity index 94% rename from akka-docs/rst/java/code/docs/camel/Transformer.java rename to akka-docs/rst/java/code/jdocs/camel/Transformer.java index 17338f6837..38e7ce7b6c 100644 --- a/akka-docs/rst/java/code/docs/camel/Transformer.java +++ b/akka-docs/rst/java/code/jdocs/camel/Transformer.java @@ -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; diff --git a/akka-docs/rst/java/code/docs/cluster/ClusterDocTest.java b/akka-docs/rst/java/code/jdocs/cluster/ClusterDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/cluster/ClusterDocTest.java rename to akka-docs/rst/java/code/jdocs/cluster/ClusterDocTest.java index 3d27251e80..582b1ee518 100644 --- a/akka-docs/rst/java/code/docs/cluster/ClusterDocTest.java +++ b/akka-docs/rst/java/code/jdocs/cluster/ClusterDocTest.java @@ -1,10 +1,10 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/cluster/FactorialBackend.java b/akka-docs/rst/java/code/jdocs/cluster/FactorialBackend.java similarity index 97% rename from akka-docs/rst/java/code/docs/cluster/FactorialBackend.java rename to akka-docs/rst/java/code/jdocs/cluster/FactorialBackend.java index 3fe82524bb..7a3343b2a5 100644 --- a/akka-docs/rst/java/code/docs/cluster/FactorialBackend.java +++ b/akka-docs/rst/java/code/jdocs/cluster/FactorialBackend.java @@ -1,4 +1,4 @@ -package docs.cluster; +package jdocs.cluster; import java.math.BigInteger; import java.util.concurrent.CompletableFuture; diff --git a/akka-docs/rst/java/code/docs/cluster/FactorialFrontend.java b/akka-docs/rst/java/code/jdocs/cluster/FactorialFrontend.java similarity index 95% rename from akka-docs/rst/java/code/docs/cluster/FactorialFrontend.java rename to akka-docs/rst/java/code/jdocs/cluster/FactorialFrontend.java index 34fb095880..15dd6aae5d 100644 --- a/akka-docs/rst/java/code/docs/cluster/FactorialFrontend.java +++ b/akka-docs/rst/java/code/jdocs/cluster/FactorialFrontend.java @@ -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()); } } diff --git a/akka-docs/rst/java/code/docs/cluster/FactorialFrontendMain.java b/akka-docs/rst/java/code/jdocs/cluster/FactorialFrontendMain.java similarity index 96% rename from akka-docs/rst/java/code/docs/cluster/FactorialFrontendMain.java rename to akka-docs/rst/java/code/jdocs/cluster/FactorialFrontendMain.java index 891b200536..5228c0a173 100644 --- a/akka-docs/rst/java/code/docs/cluster/FactorialFrontendMain.java +++ b/akka-docs/rst/java/code/jdocs/cluster/FactorialFrontendMain.java @@ -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; diff --git a/akka-docs/rst/java/code/docs/cluster/FactorialResult.java b/akka-docs/rst/java/code/jdocs/cluster/FactorialResult.java similarity index 93% rename from akka-docs/rst/java/code/docs/cluster/FactorialResult.java rename to akka-docs/rst/java/code/jdocs/cluster/FactorialResult.java index 38dbcfc065..21aec6ff5c 100644 --- a/akka-docs/rst/java/code/docs/cluster/FactorialResult.java +++ b/akka-docs/rst/java/code/jdocs/cluster/FactorialResult.java @@ -1,4 +1,4 @@ -package docs.cluster; +package jdocs.cluster; import java.math.BigInteger; import java.io.Serializable; diff --git a/akka-docs/rst/java/code/docs/cluster/MetricsListener.java b/akka-docs/rst/java/code/jdocs/cluster/MetricsListener.java similarity index 90% rename from akka-docs/rst/java/code/docs/cluster/MetricsListener.java rename to akka-docs/rst/java/code/jdocs/cluster/MetricsListener.java index e9fd928ea2..44d2616200 100644 --- a/akka-docs/rst/java/code/docs/cluster/MetricsListener.java +++ b/akka-docs/rst/java/code/jdocs/cluster/MetricsListener.java @@ -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. diff --git a/akka-docs/rst/java/code/docs/cluster/SimpleClusterListener.java b/akka-docs/rst/java/code/jdocs/cluster/SimpleClusterListener.java similarity index 89% rename from akka-docs/rst/java/code/docs/cluster/SimpleClusterListener.java rename to akka-docs/rst/java/code/jdocs/cluster/SimpleClusterListener.java index 8774ac83be..dc4440488f 100644 --- a/akka-docs/rst/java/code/docs/cluster/SimpleClusterListener.java +++ b/akka-docs/rst/java/code/jdocs/cluster/SimpleClusterListener.java @@ -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 diff --git a/akka-docs/rst/java/code/docs/cluster/SimpleClusterListener2.java b/akka-docs/rst/java/code/jdocs/cluster/SimpleClusterListener2.java similarity index 89% rename from akka-docs/rst/java/code/docs/cluster/SimpleClusterListener2.java rename to akka-docs/rst/java/code/jdocs/cluster/SimpleClusterListener2.java index e9a9c5fa63..9fbe8d8f72 100644 --- a/akka-docs/rst/java/code/docs/cluster/SimpleClusterListener2.java +++ b/akka-docs/rst/java/code/jdocs/cluster/SimpleClusterListener2.java @@ -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 diff --git a/akka-docs/rst/java/code/docs/cluster/StatsAggregator.java b/akka-docs/rst/java/code/jdocs/cluster/StatsAggregator.java similarity index 80% rename from akka-docs/rst/java/code/docs/cluster/StatsAggregator.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsAggregator.java index 83c5929bc6..255c38523c 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsAggregator.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsAggregator.java @@ -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(); } diff --git a/akka-docs/rst/java/code/docs/cluster/StatsMessages.java b/akka-docs/rst/java/code/jdocs/cluster/StatsMessages.java similarity index 97% rename from akka-docs/rst/java/code/docs/cluster/StatsMessages.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsMessages.java index b8ca17a50f..8d95b02100 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsMessages.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsMessages.java @@ -1,4 +1,4 @@ -package docs.cluster; +package jdocs.cluster; import java.io.Serializable; diff --git a/akka-docs/rst/java/code/docs/cluster/StatsSampleClient.java b/akka-docs/rst/java/code/jdocs/cluster/StatsSampleClient.java similarity index 90% rename from akka-docs/rst/java/code/docs/cluster/StatsSampleClient.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsSampleClient.java index c0da371e16..84a5169688 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsSampleClient.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsSampleClient.java @@ -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
nodes = new HashSet
(); - 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) diff --git a/akka-docs/rst/java/code/docs/cluster/StatsSampleOneMasterClientMain.java b/akka-docs/rst/java/code/jdocs/cluster/StatsSampleOneMasterClientMain.java similarity index 95% rename from akka-docs/rst/java/code/docs/cluster/StatsSampleOneMasterClientMain.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsSampleOneMasterClientMain.java index d4e30ff8d0..17c134c8a2 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsSampleOneMasterClientMain.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsSampleOneMasterClientMain.java @@ -1,4 +1,4 @@ -package docs.cluster; +package jdocs.cluster; import com.typesafe.config.ConfigFactory; diff --git a/akka-docs/rst/java/code/docs/cluster/StatsSampleOneMasterMain.java b/akka-docs/rst/java/code/jdocs/cluster/StatsSampleOneMasterMain.java similarity index 98% rename from akka-docs/rst/java/code/docs/cluster/StatsSampleOneMasterMain.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsSampleOneMasterMain.java index 388bdf9745..de51dbdbfe 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsSampleOneMasterMain.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsSampleOneMasterMain.java @@ -1,4 +1,4 @@ -package docs.cluster; +package jdocs.cluster; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; diff --git a/akka-docs/rst/java/code/docs/cluster/StatsService.java b/akka-docs/rst/java/code/jdocs/cluster/StatsService.java similarity index 96% rename from akka-docs/rst/java/code/docs/cluster/StatsService.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsService.java index f81827b471..61509307c1 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsService.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsService.java @@ -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( diff --git a/akka-docs/rst/java/code/docs/cluster/StatsWorker.java b/akka-docs/rst/java/code/jdocs/cluster/StatsWorker.java similarity index 88% rename from akka-docs/rst/java/code/docs/cluster/StatsWorker.java rename to akka-docs/rst/java/code/jdocs/cluster/StatsWorker.java index b62f2a3402..1638da2272 100644 --- a/akka-docs/rst/java/code/docs/cluster/StatsWorker.java +++ b/akka-docs/rst/java/code/jdocs/cluster/StatsWorker.java @@ -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(); } diff --git a/akka-docs/rst/java/code/docs/cluster/TransformationBackend.java b/akka-docs/rst/java/code/jdocs/cluster/TransformationBackend.java similarity index 72% rename from akka-docs/rst/java/code/docs/cluster/TransformationBackend.java rename to akka-docs/rst/java/code/jdocs/cluster/TransformationBackend.java index 3e1a44c89c..cb47d18051 100644 --- a/akka-docs/rst/java/code/docs/cluster/TransformationBackend.java +++ b/akka-docs/rst/java/code/jdocs/cluster/TransformationBackend.java @@ -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 diff --git a/akka-docs/rst/java/code/docs/cluster/TransformationFrontend.java b/akka-docs/rst/java/code/jdocs/cluster/TransformationFrontend.java similarity index 78% rename from akka-docs/rst/java/code/docs/cluster/TransformationFrontend.java rename to akka-docs/rst/java/code/jdocs/cluster/TransformationFrontend.java index 7d7b1c2430..a16ac12679 100644 --- a/akka-docs/rst/java/code/docs/cluster/TransformationFrontend.java +++ b/akka-docs/rst/java/code/jdocs/cluster/TransformationFrontend.java @@ -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++; diff --git a/akka-docs/rst/java/code/docs/cluster/TransformationMessages.java b/akka-docs/rst/java/code/jdocs/cluster/TransformationMessages.java similarity index 98% rename from akka-docs/rst/java/code/docs/cluster/TransformationMessages.java rename to akka-docs/rst/java/code/jdocs/cluster/TransformationMessages.java index 677aebd48e..c3ed0ac6a3 100644 --- a/akka-docs/rst/java/code/docs/cluster/TransformationMessages.java +++ b/akka-docs/rst/java/code/jdocs/cluster/TransformationMessages.java @@ -1,4 +1,4 @@ -package docs.cluster; +package jdocs.cluster; import java.io.Serializable; diff --git a/akka-docs/rst/java/code/docs/ddata/DataBot.java b/akka-docs/rst/java/code/jdocs/ddata/DataBot.java similarity index 85% rename from akka-docs/rst/java/code/docs/ddata/DataBot.java rename to akka-docs/rst/java/code/jdocs/ddata/DataBot.java index 49cfade45b..bc62fed17b 100644 --- a/akka-docs/rst/java/code/docs/ddata/DataBot.java +++ b/akka-docs/rst/java/code/jdocs/ddata/DataBot.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -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> 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> subscribe = new Subscribe<>(dataKey, self()); + Subscribe> subscribe = new Subscribe<>(dataKey, getSelf()); replicator.tell(subscribe, ActorRef.noSender()); } diff --git a/akka-docs/rst/java/code/docs/ddata/DistributedDataDocTest.java b/akka-docs/rst/java/code/jdocs/ddata/DistributedDataDocTest.java similarity index 87% rename from akka-docs/rst/java/code/docs/ddata/DistributedDataDocTest.java rename to akka-docs/rst/java/code/jdocs/ddata/DistributedDataDocTest.java index 1cb88d4623..b5695377a0 100644 --- a/akka-docs/rst/java/code/docs/ddata/DistributedDataDocTest.java +++ b/akka-docs/rst/java/code/jdocs/ddata/DistributedDataDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -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 counter1Key = PNCounterKey.create("counter1"); final Key> set1Key = GSetKey.create("set1"); @@ -71,20 +66,20 @@ public class DistributedDataDocTest extends AbstractJavaTest { b.matchEquals("demonstrate update", msg -> { replicator.tell(new Replicator.Update(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>(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>(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(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 counter1Key = PNCounterKey.create("counter1"); @@ -127,17 +122,17 @@ public class DistributedDataDocTest extends AbstractJavaTest { Optional reqContext = Optional.of(sender()); Replicator.Update upd = new Replicator.Update(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 counter1Key = PNCounterKey.create("counter1"); final Key> set1Key = GSetKey.create("set1"); @@ -163,19 +158,19 @@ public class DistributedDataDocTest extends AbstractJavaTest { b.matchEquals("demonstrate get", msg -> { replicator.tell(new Replicator.Get(counter1Key, - Replicator.readLocal()), self()); + Replicator.readLocal()), getSelf()); final ReadConsistency readFrom3 = new ReadFrom(3, Duration.create(1, SECONDS)); replicator.tell(new Replicator.Get>(set1Key, - readFrom3), self()); + readFrom3), getSelf()); final ReadConsistency readMajority = new ReadMajority(Duration.create(5, SECONDS)); replicator.tell(new Replicator.Get>(set2Key, - readMajority), self()); + readMajority), getSelf()); final ReadConsistency readAll = new ReadAll(Duration.create(5, SECONDS)); replicator.tell(new Replicator.Get(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 counter1Key = PNCounterKey.create("counter1"); @@ -225,24 +220,24 @@ public class DistributedDataDocTest extends AbstractJavaTest { // incoming request to retrieve current value of the counter Optional reqContext = Optional.of(sender()); replicator.tell(new Replicator.Get(counter1Key, - readTwo), self()); + readTwo), getSelf()); }) .match(GetSuccess.class, a -> a.key().equals(counter1Key), a -> { ActorRef replyTo = (ActorRef) a.getRequest().get(); GetSuccess 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 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(counter1Key, self()), ActorRef.noSender()); + replicator.tell(new Subscribe(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 counter1Key = PNCounterKey.create("counter1"); final Key> set2Key = ORSetKey.create("set2"); @@ -297,12 +292,12 @@ public class DistributedDataDocTest extends AbstractJavaTest { .matchEquals("demonstrate delete", msg -> { replicator.tell(new Delete(counter1Key, - Replicator.writeLocal()), self()); + Replicator.writeLocal()), getSelf()); final WriteConsistency writeMajority = new WriteMajority(Duration.create(5, SECONDS)); replicator.tell(new Delete(counter1Key, - writeMajority), self()); + writeMajority), getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/ddata/ShoppingCart.java b/akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java similarity index 92% rename from akka-docs/rst/java/code/docs/ddata/ShoppingCart.java rename to akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java index 8e48ba387d..6fdff58dc4 100644 --- a/akka-docs/rst/java/code/docs/ddata/ShoppingCart.java +++ b/akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java @@ -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 ctx = Optional.of(sender()); + Optional ctx = Optional.of(getSender()); replicator.tell(new Replicator.Get>(dataKey, readMajority, ctx), - self()); + getSelf()); } private boolean isResponseToGetCart(GetResponse response) { @@ -172,19 +170,19 @@ public class ShoppingCart extends AbstractActor { private void receiveGetSuccess(GetSuccess> g) { Set 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> 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> f) { // ReadMajority failure, try again with local read - Optional ctx = Optional.of(sender()); + Optional ctx = Optional.of(getSender()); replicator.tell(new Replicator.Get>(dataKey, Replicator.readLocal(), - ctx), self()); + ctx), getSelf()); } //#get-cart @@ -198,7 +196,7 @@ public class ShoppingCart extends AbstractActor { private void receiveAddItem(AddItem add) { Update> 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 ctx = Optional.of(rm); - replicator.tell(new Replicator.Get>(dataKey, readMajority, ctx), - self()); + replicator.tell(new Replicator.Get>(dataKey, readMajority, ctx), + getSelf()); } private void receiveRemoveItemGetSuccess(GetSuccess> g) { @@ -249,7 +247,7 @@ public class ShoppingCart extends AbstractActor { private void removeItem(String productId) { Update> 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) { diff --git a/akka-docs/rst/java/code/docs/ddata/japi/TwoPhaseSet.java b/akka-docs/rst/java/code/jdocs/ddata/TwoPhaseSet.java similarity index 97% rename from akka-docs/rst/java/code/docs/ddata/japi/TwoPhaseSet.java rename to akka-docs/rst/java/code/jdocs/ddata/TwoPhaseSet.java index 4a678185e4..70d179c5b4 100644 --- a/akka-docs/rst/java/code/docs/ddata/japi/TwoPhaseSet.java +++ b/akka-docs/rst/java/code/jdocs/ddata/TwoPhaseSet.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.ddata.japi; +package jdocs.ddata; import java.util.HashSet; diff --git a/akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer.java b/akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializer.java similarity index 97% rename from akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer.java rename to akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializer.java index 524e058144..925daa0fa6 100644 --- a/akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer.java +++ b/akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializer.java @@ -1,10 +1,10 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer2.java b/akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializer2.java similarity index 95% rename from akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer2.java rename to akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializer2.java index 8e1d5fe9ce..8527cb2371 100644 --- a/akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer2.java +++ b/akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializer2.java @@ -1,14 +1,12 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializerWithCompression.java b/akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializerWithCompression.java similarity index 91% rename from akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializerWithCompression.java rename to akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializerWithCompression.java index 5855dd95a6..9c05d68605 100644 --- a/akka-docs/rst/java/code/docs/ddata/japi/protobuf/TwoPhaseSetSerializerWithCompression.java +++ b/akka-docs/rst/java/code/jdocs/ddata/protobuf/TwoPhaseSetSerializerWithCompression.java @@ -1,9 +1,9 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.ddata.japi.protobuf; +package jdocs.ddata.protobuf; -import docs.ddata.japi.TwoPhaseSet; +import jdocs.ddata.TwoPhaseSet; import akka.actor.ExtendedActorSystem; diff --git a/akka-docs/rst/java/code/docs/dispatcher/DispatcherDocTest.java b/akka-docs/rst/java/code/jdocs/dispatcher/DispatcherDocTest.java similarity index 93% rename from akka-docs/rst/java/code/docs/dispatcher/DispatcherDocTest.java rename to akka-docs/rst/java/code/jdocs/dispatcher/DispatcherDocTest.java index 03354c3209..724cc95726 100644 --- a/akka-docs/rst/java/code/docs/dispatcher/DispatcherDocTest.java +++ b/akka-docs/rst/java/code/jdocs/dispatcher/DispatcherDocTest.java @@ -1,15 +1,16 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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 { + RequiresMessageQueue { //#require-mailbox-on-actor @Override public Receive createReceive() { diff --git a/akka-docs/rst/java/code/docs/dispatcher/MyUnboundedJMailbox.java b/akka-docs/rst/java/code/jdocs/dispatcher/MyUnboundedMailbox.java similarity index 84% rename from akka-docs/rst/java/code/docs/dispatcher/MyUnboundedJMailbox.java rename to akka-docs/rst/java/code/jdocs/dispatcher/MyUnboundedMailbox.java index 6eb77b9d0a..37b936242f 100644 --- a/akka-docs/rst/java/code/docs/dispatcher/MyUnboundedJMailbox.java +++ b/akka-docs/rst/java/code/jdocs/dispatcher/MyUnboundedMailbox.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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 { +public class MyUnboundedMailbox implements MailboxType, + ProducesMessageQueue { // This is the MessageQueue implementation public static class MyMessageQueue implements MessageQueue, - MyUnboundedJMessageQueueSemantics { + MyUnboundedMessageQueueSemantics { private final Queue queue = new ConcurrentLinkedQueue(); @@ -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 } diff --git a/akka-docs/rst/java/code/docs/dispatcher/MyUnboundedJMessageQueueSemantics.java b/akka-docs/rst/java/code/jdocs/dispatcher/MyUnboundedMessageQueueSemantics.java similarity index 72% rename from akka-docs/rst/java/code/docs/dispatcher/MyUnboundedJMessageQueueSemantics.java rename to akka-docs/rst/java/code/jdocs/dispatcher/MyUnboundedMessageQueueSemantics.java index 85e1628fe4..1001c790fa 100644 --- a/akka-docs/rst/java/code/docs/dispatcher/MyUnboundedJMessageQueueSemantics.java +++ b/akka-docs/rst/java/code/jdocs/dispatcher/MyUnboundedMessageQueueSemantics.java @@ -2,10 +2,10 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 diff --git a/akka-docs/rst/java/code/docs/event/EventBusDocTest.java b/akka-docs/rst/java/code/jdocs/event/EventBusDocTest.java similarity index 97% rename from akka-docs/rst/java/code/docs/event/EventBusDocTest.java rename to akka-docs/rst/java/code/jdocs/event/EventBusDocTest.java index 3695010609..6809577d4d 100644 --- a/akka-docs/rst/java/code/docs/event/EventBusDocTest.java +++ b/akka-docs/rst/java/code/jdocs/event/EventBusDocTest.java @@ -1,36 +1,30 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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 diff --git a/akka-docs/rst/java/code/docs/event/LoggingDocTest.java b/akka-docs/rst/java/code/jdocs/event/LoggingDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/event/LoggingDocTest.java rename to akka-docs/rst/java/code/jdocs/event/LoggingDocTest.java index 5379fa756e..4c8f94c3df 100644 --- a/akka-docs/rst/java/code/docs/event/LoggingDocTest.java +++ b/akka-docs/rst/java/code/jdocs/event/LoggingDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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 -> { // ... diff --git a/akka-docs/rst/java/code/docs/extension/ExtensionDocTest.java b/akka-docs/rst/java/code/jdocs/extension/ExtensionDocTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/extension/ExtensionDocTest.java rename to akka-docs/rst/java/code/jdocs/extension/ExtensionDocTest.java index 7f046526f4..8f46e293fa 100644 --- a/akka-docs/rst/java/code/docs/extension/ExtensionDocTest.java +++ b/akka-docs/rst/java/code/jdocs/extension/ExtensionDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); } diff --git a/akka-docs/rst/java/code/docs/extension/SettingsExtensionDocTest.java b/akka-docs/rst/java/code/jdocs/extension/SettingsExtensionDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/extension/SettingsExtensionDocTest.java rename to akka-docs/rst/java/code/jdocs/extension/SettingsExtensionDocTest.java index 605335b819..2c8bfcfec7 100644 --- a/akka-docs/rst/java/code/docs/extension/SettingsExtensionDocTest.java +++ b/akka-docs/rst/java/code/jdocs/extension/SettingsExtensionDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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); diff --git a/akka-docs/rst/java/code/docs/future/FutureDocTest.java b/akka-docs/rst/java/code/jdocs/future/FutureDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/future/FutureDocTest.java rename to akka-docs/rst/java/code/jdocs/future/FutureDocTest.java index 9e42ccdbff..2c80fd5b68 100644 --- a/akka-docs/rst/java/code/docs/future/FutureDocTest.java +++ b/akka-docs/rst/java/code/jdocs/future/FutureDocTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); diff --git a/akka-docs/rst/java/code/docs/io/IODocTest.java b/akka-docs/rst/java/code/jdocs/io/IODocTest.java similarity index 86% rename from akka-docs/rst/java/code/docs/io/IODocTest.java rename to akka-docs/rst/java/code/jdocs/io/IODocTest.java index ac3cb3a453..678ee83e4e 100644 --- a/akka-docs/rst/java/code/docs/io/IODocTest.java +++ b/akka-docs/rst/java/code/jdocs/io/IODocTest.java @@ -2,10 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 options = new ArrayList(); 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 options = new ArrayList(); 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(); diff --git a/akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java b/akka-docs/rst/java/code/jdocs/io/JavaReadBackPressure.java similarity index 82% rename from akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java rename to akka-docs/rst/java/code/jdocs/io/JavaReadBackPressure.java index fd607a8525..16c0ed4395 100644 --- a/akka-docs/rst/java/code/docs/io/JavaReadBackPressure.java +++ b/akka-docs/rst/java/code/jdocs/io/JavaReadBackPressure.java @@ -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 options = new ArrayList(); 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 options = new ArrayList(); 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(); } diff --git a/akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java b/akka-docs/rst/java/code/jdocs/io/JavaUdpMulticast.java similarity index 85% rename from akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java rename to akka-docs/rst/java/code/jdocs/io/JavaUdpMulticast.java index 626c051f94..31794fdc1b 100644 --- a/akka-docs/rst/java/code/docs/io/JavaUdpMulticast.java +++ b/akka-docs/rst/java/code/jdocs/io/JavaUdpMulticast.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 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(); } diff --git a/akka-docs/rst/java/code/docs/io/JavaUdpMulticastTest.java b/akka-docs/rst/java/code/jdocs/io/JavaUdpMulticastTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/io/JavaUdpMulticastTest.java rename to akka-docs/rst/java/code/jdocs/io/JavaUdpMulticastTest.java index 705cbd82eb..3ca4d3a54a 100644 --- a/akka-docs/rst/java/code/docs/io/JavaUdpMulticastTest.java +++ b/akka-docs/rst/java/code/jdocs/io/JavaUdpMulticastTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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; diff --git a/akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java b/akka-docs/rst/java/code/jdocs/io/UdpConnectedDocTest.java similarity index 88% rename from akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java rename to akka-docs/rst/java/code/jdocs/io/UdpConnectedDocTest.java index dec0e8bea4..7959e11d4c 100644 --- a/akka-docs/rst/java/code/docs/io/UdpConnectedDocTest.java +++ b/akka-docs/rst/java/code/jdocs/io/UdpConnectedDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 options = new ArrayList(); 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(); diff --git a/akka-docs/rst/java/code/docs/io/UdpDocTest.java b/akka-docs/rst/java/code/jdocs/io/UdpDocTest.java similarity index 78% rename from akka-docs/rst/java/code/docs/io/UdpDocTest.java rename to akka-docs/rst/java/code/jdocs/io/UdpDocTest.java index a67b4b06cf..25859ffb71 100644 --- a/akka-docs/rst/java/code/docs/io/UdpDocTest.java +++ b/akka-docs/rst/java/code/jdocs/io/UdpDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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()); diff --git a/akka-docs/rst/java/code/docs/io/japi/EchoHandler.java b/akka-docs/rst/java/code/jdocs/io/japi/EchoHandler.java similarity index 93% rename from akka-docs/rst/java/code/docs/io/japi/EchoHandler.java rename to akka-docs/rst/java/code/jdocs/io/japi/EchoHandler.java index 22aab6762a..45c3e28b0f 100644 --- a/akka-docs/rst/java/code/docs/io/japi/EchoHandler.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/EchoHandler.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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 diff --git a/akka-docs/rst/java/code/docs/io/japi/EchoManager.java b/akka-docs/rst/java/code/jdocs/io/japi/EchoManager.java similarity index 88% rename from akka-docs/rst/java/code/docs/io/japi/EchoManager.java rename to akka-docs/rst/java/code/jdocs/io/japi/EchoManager.java index c2e032f6d5..829c6434be 100644 --- a/akka-docs/rst/java/code/docs/io/japi/EchoManager.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/EchoManager.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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(); diff --git a/akka-docs/rst/java/code/docs/io/japi/EchoServer.java b/akka-docs/rst/java/code/jdocs/io/japi/EchoServer.java similarity index 98% rename from akka-docs/rst/java/code/docs/io/japi/EchoServer.java rename to akka-docs/rst/java/code/jdocs/io/japi/EchoServer.java index 9be36b30d4..d86c7ca496 100644 --- a/akka-docs/rst/java/code/docs/io/japi/EchoServer.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/EchoServer.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.io.japi; +package jdocs.io.japi; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/akka-docs/rst/java/code/docs/io/japi/IODocTest.java b/akka-docs/rst/java/code/jdocs/io/japi/IODocTest.java similarity index 84% rename from akka-docs/rst/java/code/docs/io/japi/IODocTest.java rename to akka-docs/rst/java/code/jdocs/io/japi/IODocTest.java index 7a3376f8e5..bebfff8d79 100644 --- a/akka-docs/rst/java/code/docs/io/japi/IODocTest.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/IODocTest.java @@ -2,11 +2,11 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -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()); diff --git a/akka-docs/rst/java/code/docs/io/japi/Message.java b/akka-docs/rst/java/code/jdocs/io/japi/Message.java similarity index 97% rename from akka-docs/rst/java/code/docs/io/japi/Message.java rename to akka-docs/rst/java/code/jdocs/io/japi/Message.java index 0badb9b53b..f44d8a492d 100644 --- a/akka-docs/rst/java/code/docs/io/japi/Message.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/Message.java @@ -2,7 +2,7 @@ * Copyright (C) 2013-2017 Lightbend Inc. */ -package docs.io.japi; +package jdocs.io.japi; //#message public class Message { diff --git a/akka-docs/rst/java/code/docs/io/japi/SimpleEchoHandler.java b/akka-docs/rst/java/code/jdocs/io/japi/SimpleEchoHandler.java similarity index 90% rename from akka-docs/rst/java/code/docs/io/japi/SimpleEchoHandler.java rename to akka-docs/rst/java/code/jdocs/io/japi/SimpleEchoHandler.java index e759ef41d5..2913cb5e56 100644 --- a/akka-docs/rst/java/code/docs/io/japi/SimpleEchoHandler.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/SimpleEchoHandler.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.io.japi; +package jdocs.io.japi; import java.net.InetSocketAddress; import java.util.LinkedList; @@ -16,14 +16,13 @@ import akka.io.Tcp.ConnectionClosed; import akka.io.Tcp.Event; import akka.io.Tcp.Received; import akka.io.TcpMessage; -import akka.japi.Procedure; import akka.util.ByteString; //#simple-echo-handler public class SimpleEchoHandler extends AbstractActor { final LoggingAdapter log = Logging - .getLogger(getContext().system(), self()); + .getLogger(getContext().getSystem(), getSelf()); final ActorRef connection; final InetSocketAddress remote; @@ -46,7 +45,7 @@ public class SimpleEchoHandler extends AbstractActor { .match(Received.class, msg -> { final ByteString data = msg.data(); buffer(data); - connection.tell(TcpMessage.write(data, ACK), self()); + connection.tell(TcpMessage.write(data, ACK), getSelf()); // now switch behavior to “waiting for acknowledgement” getContext().become(buffering(), false); @@ -103,7 +102,7 @@ public class SimpleEchoHandler extends AbstractActor { } else if (stored > highWatermark) { log.debug("suspending reading"); - connection.tell(TcpMessage.suspendReading(), self()); + connection.tell(TcpMessage.suspendReading(), getSelf()); suspended = true; } } @@ -115,7 +114,7 @@ public class SimpleEchoHandler extends AbstractActor { if (suspended && stored < lowWatermark) { log.debug("resuming reading"); - connection.tell(TcpMessage.resumeReading(), self()); + connection.tell(TcpMessage.resumeReading(), getSelf()); suspended = false; } @@ -126,7 +125,7 @@ public class SimpleEchoHandler extends AbstractActor { getContext().unbecome(); } } else { - connection.tell(TcpMessage.write(storage.peek(), ACK), self()); + connection.tell(TcpMessage.write(storage.peek(), ACK), getSelf()); } } //#simple-helpers diff --git a/akka-docs/rst/java/code/docs/io/japi/Watcher.java b/akka-docs/rst/java/code/jdocs/io/japi/Watcher.java similarity index 96% rename from akka-docs/rst/java/code/docs/io/japi/Watcher.java rename to akka-docs/rst/java/code/jdocs/io/japi/Watcher.java index 4bbef03c6f..47376774aa 100644 --- a/akka-docs/rst/java/code/docs/io/japi/Watcher.java +++ b/akka-docs/rst/java/code/jdocs/io/japi/Watcher.java @@ -1,4 +1,4 @@ -package docs.io.japi; +package jdocs.io.japi; import java.util.concurrent.CountDownLatch; diff --git a/akka-docs/rst/java/code/docs/pattern/BackoffSupervisorDocTest.java b/akka-docs/rst/java/code/jdocs/pattern/BackoffSupervisorDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/pattern/BackoffSupervisorDocTest.java rename to akka-docs/rst/java/code/jdocs/pattern/BackoffSupervisorDocTest.java index 7d483c01cd..13a0b2f625 100644 --- a/akka-docs/rst/java/code/docs/pattern/BackoffSupervisorDocTest.java +++ b/akka-docs/rst/java/code/jdocs/pattern/BackoffSupervisorDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.pattern; +package jdocs.pattern; import akka.actor.*; import akka.pattern.Backoff; diff --git a/akka-docs/rst/java/code/docs/pattern/SchedulerPatternTest.java b/akka-docs/rst/java/code/jdocs/pattern/SchedulerPatternTest.java similarity index 90% rename from akka-docs/rst/java/code/docs/pattern/SchedulerPatternTest.java rename to akka-docs/rst/java/code/jdocs/pattern/SchedulerPatternTest.java index 2d304011ca..8aafa98687 100644 --- a/akka-docs/rst/java/code/docs/pattern/SchedulerPatternTest.java +++ b/akka-docs/rst/java/code/jdocs/pattern/SchedulerPatternTest.java @@ -2,13 +2,13 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.pattern; +package jdocs.pattern; import akka.actor.*; import akka.testkit.*; import akka.testkit.TestEvent.Mute; import akka.testkit.TestEvent.UnMute; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.*; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; @@ -27,10 +27,10 @@ public class SchedulerPatternTest extends AbstractJavaTest { //#schedule-constructor public class ScheduleInConstructor extends AbstractActor { - private final Cancellable tick = getContext().system().scheduler().schedule( + private final Cancellable tick = getContext().getSystem().scheduler().schedule( Duration.create(500, TimeUnit.MILLISECONDS), Duration.create(1, TimeUnit.SECONDS), - self(), "tick", getContext().dispatcher(), null); + getSelf(), "tick", getContext().dispatcher(), null); //#schedule-constructor // this variable and constructor is declared here to not show up in the docs final ActorRef target; @@ -50,7 +50,7 @@ public class SchedulerPatternTest extends AbstractJavaTest { .matchEquals("tick", message -> { // do something useful here //#schedule-constructor - target.tell(message, self()); + target.tell(message, getSelf()); //#schedule-constructor }) .matchEquals("restart", message -> { @@ -74,9 +74,9 @@ public class SchedulerPatternTest extends AbstractJavaTest { @Override public void preStart() { - getContext().system().scheduler().scheduleOnce( + getContext().getSystem().scheduler().scheduleOnce( Duration.create(500, TimeUnit.MILLISECONDS), - self(), "tick", getContext().dispatcher(), null); + getSelf(), "tick", getContext().dispatcher(), null); } // override postRestart so we don't call preStart and schedule a new message @@ -89,12 +89,12 @@ public class SchedulerPatternTest extends AbstractJavaTest { return receiveBuilder() .matchEquals("tick", message -> { // send another periodic tick after the specified delay - getContext().system().scheduler().scheduleOnce( + getContext().getSystem().scheduler().scheduleOnce( Duration.create(1, TimeUnit.SECONDS), - self(), "tick", getContext().dispatcher(), null); + getSelf(), "tick", getContext().dispatcher(), null); // do something useful here //#schedule-receive - target.tell(message, self()); + target.tell(message, getSelf()); //#schedule-receive }) .matchEquals("restart", message -> { diff --git a/akka-docs/rst/java/code/docs/pattern/SupervisedAsk.java b/akka-docs/rst/java/code/jdocs/pattern/SupervisedAsk.java similarity index 83% rename from akka-docs/rst/java/code/docs/pattern/SupervisedAsk.java rename to akka-docs/rst/java/code/jdocs/pattern/SupervisedAsk.java index 43db7c9533..604535d73f 100644 --- a/akka-docs/rst/java/code/docs/pattern/SupervisedAsk.java +++ b/akka-docs/rst/java/code/jdocs/pattern/SupervisedAsk.java @@ -1,4 +1,4 @@ -package docs.pattern; +package jdocs.pattern; import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeoutException; @@ -59,7 +59,7 @@ public class SupervisedAsk { @Override public SupervisorStrategy supervisorStrategy() { return new OneForOneStrategy(0, Duration.Zero(), cause -> { - caller.tell(new Status.Failure(cause), self()); + caller.tell(new Status.Failure(cause), getSelf()); return SupervisorStrategy.stop(); }); } @@ -69,25 +69,25 @@ public class SupervisedAsk { return receiveBuilder() .match(AskParam.class, message -> { askParam = message; - caller = sender(); + caller = getSender(); targetActor = getContext().actorOf(askParam.props); getContext().watch(targetActor); targetActor.forward(askParam.message, getContext()); - Scheduler scheduler = getContext().system().scheduler(); + Scheduler scheduler = getContext().getSystem().scheduler(); timeoutMessage = scheduler.scheduleOnce(askParam.timeout.duration(), - self(), new AskTimeout(), getContext().dispatcher(), null); + getSelf(), new AskTimeout(), getContext().dispatcher(), null); }) .match(Terminated.class, message -> { Throwable ex = new ActorKilledException("Target actor terminated."); - caller.tell(new Status.Failure(ex), self()); + caller.tell(new Status.Failure(ex), getSelf()); timeoutMessage.cancel(); - getContext().stop(self()); + getContext().stop(getSelf()); }) .match(AskTimeout.class, message -> { Throwable ex = new TimeoutException("Target actor timed out after " + askParam.timeout.toString()); - caller.tell(new Status.Failure(ex), self()); - getContext().stop(self()); + caller.tell(new Status.Failure(ex), getSelf()); + getContext().stop(getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/pattern/SupervisedAskSpec.java b/akka-docs/rst/java/code/jdocs/pattern/SupervisedAskSpec.java similarity index 94% rename from akka-docs/rst/java/code/docs/pattern/SupervisedAskSpec.java rename to akka-docs/rst/java/code/jdocs/pattern/SupervisedAskSpec.java index 90483962d0..3790ae2000 100644 --- a/akka-docs/rst/java/code/docs/pattern/SupervisedAskSpec.java +++ b/akka-docs/rst/java/code/jdocs/pattern/SupervisedAskSpec.java @@ -1,4 +1,4 @@ -package docs.pattern; +package jdocs.pattern; import akka.actor.ActorRef; import akka.actor.ActorRefFactory; diff --git a/akka-docs/rst/java/code/docs/persistence/LambdaPersistenceDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/LambdaPersistenceDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/persistence/LambdaPersistenceDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/LambdaPersistenceDocTest.java index 945713f2de..0b452622be 100644 --- a/akka-docs/rst/java/code/docs/persistence/LambdaPersistenceDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/LambdaPersistenceDocTest.java @@ -1,18 +1,14 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; import akka.actor.*; import akka.japi.Procedure; -import akka.japi.pf.ReceiveBuilder; import akka.pattern.BackoffSupervisor; import akka.persistence.*; -import akka.persistence.journal.EventAdapter; -import akka.persistence.journal.EventSeq; import scala.concurrent.duration.Duration; -import scala.PartialFunction; -import scala.runtime.BoxedUnit; + import java.io.Serializable; import java.util.Optional; import java.util.concurrent.TimeUnit; @@ -222,7 +218,7 @@ public class LambdaPersistenceDocTest { return receiveBuilder() .match(Msg.class, msg -> { // ... - sender().tell(new Confirm(msg.deliveryId), self()); + getSender().tell(new Confirm(msg.deliveryId), getSelf()); }) .build(); } @@ -331,13 +327,13 @@ public class LambdaPersistenceDocTest { } private void handleCommand(String c) { - sender().tell(c, self()); + getSender().tell(c, getSelf()); persistAsync(String.format("evt-%s-1", c), e -> { - sender().tell(e, self()); + getSender().tell(e, getSelf()); }); persistAsync(String.format("evt-%s-2", c), e -> { - sender().tell(e, self()); + getSender().tell(e, getSelf()); }); } @@ -382,14 +378,14 @@ public class LambdaPersistenceDocTest { private void handleCommand(String c) { persistAsync(String.format("evt-%s-1", c), e -> { - sender().tell(e, self()); + getSender().tell(e, getSelf()); }); persistAsync(String.format("evt-%s-2", c), e -> { - sender().tell(e, self()); + getSender().tell(e, getSelf()); }); deferAsync(String.format("evt-%s-3", c), e -> { - sender().tell(e, self()); + getSender().tell(e, getSelf()); }); } @@ -440,17 +436,17 @@ public class LambdaPersistenceDocTest { //#nested-persist-persist @Override public Receive createReceiveRecover() { - final Procedure replyToSender = event -> sender().tell(event, self()); + final Procedure replyToSender = event -> getSender().tell(event, getSelf()); return receiveBuilder() .match(String.class, msg -> { persist(String.format("%s-outer-1", msg), event -> { - sender().tell(event, self()); + getSender().tell(event, getSelf()); persist(String.format("%s-inner-1", event), replyToSender); }); persist(String.format("%s-outer-2", msg), event -> { - sender().tell(event, self()); + getSender().tell(event, getSelf()); persist(String.format("%s-inner-2", event), replyToSender); }); }) @@ -495,17 +491,17 @@ public class LambdaPersistenceDocTest { //#nested-persistAsync-persistAsync @Override public Receive createReceive() { - final Procedure replyToSender = event -> sender().tell(event, self()); + final Procedure replyToSender = event -> getSender().tell(event, getSelf()); return receiveBuilder() .match(String.class, msg -> { persistAsync(String.format("%s-outer-1", msg ), event -> { - sender().tell(event, self()); + getSender().tell(event, getSelf()); persistAsync(String.format("%s-inner-1", event), replyToSender); }); persistAsync(String.format("%s-outer-2", msg ), event -> { - sender().tell(event, self()); + getSender().tell(event, getSelf()); persistAsync(String.format("%s-inner-1", event), replyToSender); }); }) @@ -515,8 +511,8 @@ public class LambdaPersistenceDocTest { void usage(ActorRef persistentActor) { //#nested-persistAsync-persistAsync-caller - persistentActor.tell("a", self()); - persistentActor.tell("b", self()); + persistentActor.tell("a", getSelf()); + persistentActor.tell("b", getSelf()); // order of received messages: // a @@ -554,7 +550,7 @@ public class LambdaPersistenceDocTest { public Receive createReceive() { return receiveBuilder() .match(Shutdown.class, shutdown -> { - getContext().stop(self()); + getContext().stop(getSelf()); }) .match(String.class, msg -> { System.out.println(msg); diff --git a/akka-docs/rst/java/code/docs/persistence/LambdaPersistencePluginDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/LambdaPersistencePluginDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/persistence/LambdaPersistencePluginDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/LambdaPersistencePluginDocTest.java index d9ebb00c0f..797a85e200 100644 --- a/akka-docs/rst/java/code/docs/persistence/LambdaPersistencePluginDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/LambdaPersistencePluginDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; //#plugin-imports import akka.dispatch.Futures; @@ -44,7 +44,7 @@ public class LambdaPersistencePluginDocTest { public void preStart() throws Exception { String path = "akka.tcp://example@127.0.0.1:2552/user/store"; ActorSelection selection = getContext().actorSelection(path); - selection.tell(new Identify(1), self()); + selection.tell(new Identify(1), getSelf()); } @Override @@ -54,7 +54,7 @@ public class LambdaPersistencePluginDocTest { if (ai.correlationId().equals(1)) { Optional store = ai.getActorRef(); if (store.isPresent()) { - SharedLeveldbJournal.setStore(store.get(), getContext().system()); + SharedLeveldbJournal.setStore(store.get(), getContext().getSystem()); } else { throw new RuntimeException("Couldn't identify store"); } diff --git a/akka-docs/rst/java/code/docs/persistence/PersistenceEventAdapterDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/PersistenceEventAdapterDocTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/persistence/PersistenceEventAdapterDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/PersistenceEventAdapterDocTest.java index 0ab0dc026c..b329078aba 100644 --- a/akka-docs/rst/java/code/docs/persistence/PersistenceEventAdapterDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/PersistenceEventAdapterDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; import akka.persistence.journal.EventAdapter; import akka.persistence.journal.EventSeq; diff --git a/akka-docs/rst/java/code/docs/persistence/PersistenceMultiDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/PersistenceMultiDocTest.java similarity index 97% rename from akka-docs/rst/java/code/docs/persistence/PersistenceMultiDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/PersistenceMultiDocTest.java index 108a8f07d5..5746f4eeba 100644 --- a/akka-docs/rst/java/code/docs/persistence/PersistenceMultiDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/PersistenceMultiDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; import akka.persistence.UntypedPersistentActor; diff --git a/akka-docs/rst/java/code/docs/persistence/PersistenceQueryDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/PersistenceQueryDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/persistence/PersistenceQueryDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/PersistenceQueryDocTest.java index c30050fb5c..b9a05a7ba8 100644 --- a/akka-docs/rst/java/code/docs/persistence/PersistenceQueryDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/PersistenceQueryDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; import static akka.pattern.PatternsCS.ask; import java.util.HashSet; diff --git a/akka-docs/rst/java/code/docs/persistence/PersistenceSchemaEvolutionDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/persistence/PersistenceSchemaEvolutionDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java index 0f5dd7b33e..3570f8c0f7 100644 --- a/akka-docs/rst/java/code/docs/persistence/PersistenceSchemaEvolutionDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java @@ -2,13 +2,13 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; +import docs.persistence.ExampleJsonMarshaller; import docs.persistence.proto.FlightAppModels; import java.nio.charset.Charset; import spray.json.JsObject; -import akka.japi.Util; import akka.persistence.journal.EventAdapter; import akka.persistence.journal.EventSeq; import akka.protobuf.InvalidProtocolBufferException; diff --git a/akka-docs/rst/java/code/docs/persistence/PersistentActorExample.java b/akka-docs/rst/java/code/jdocs/persistence/PersistentActorExample.java similarity index 96% rename from akka-docs/rst/java/code/docs/persistence/PersistentActorExample.java rename to akka-docs/rst/java/code/jdocs/persistence/PersistentActorExample.java index b337b1530c..7b4ef6f1d6 100644 --- a/akka-docs/rst/java/code/docs/persistence/PersistentActorExample.java +++ b/akka-docs/rst/java/code/jdocs/persistence/PersistentActorExample.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence; +package jdocs.persistence; //#persistent-actor-example @@ -15,8 +15,6 @@ import akka.persistence.SnapshotOffer; import java.io.Serializable; import java.util.ArrayList; -import static java.util.Arrays.asList; - class Cmd implements Serializable { private static final long serialVersionUID = 1L; private final String data; @@ -101,7 +99,7 @@ class ExamplePersistentActor extends AbstractPersistentActor { final Evt evt = new Evt(data + "-" + getNumEvents()); persist(evt, (Evt e) -> { state.update(e); - getContext().system().eventStream().publish(e); + getContext().getSystem().eventStream().publish(e); if (lastSequenceNr() % snapShotInterval == 0 && lastSequenceNr() != 0) // IMPORTANT: create a copy of snapshot because ExampleState is mutable saveSnapshot(state.copy()); diff --git a/akka-docs/rst/java/code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java b/akka-docs/rst/java/code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java rename to akka-docs/rst/java/code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java index 733bcf8916..f81fd4a014 100644 --- a/akka-docs/rst/java/code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java +++ b/akka-docs/rst/java/code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.persistence.query; +package jdocs.persistence.query; import java.util.HashSet; import java.util.Set; diff --git a/akka-docs/rst/java/code/docs/persistence/query/MyEventsByTagJavaPublisher.java b/akka-docs/rst/java/code/jdocs/persistence/query/MyEventsByTagJavaPublisher.java similarity index 90% rename from akka-docs/rst/java/code/docs/persistence/query/MyEventsByTagJavaPublisher.java rename to akka-docs/rst/java/code/jdocs/persistence/query/MyEventsByTagJavaPublisher.java index 6fcd8ed824..dea24352e3 100644 --- a/akka-docs/rst/java/code/docs/persistence/query/MyEventsByTagJavaPublisher.java +++ b/akka-docs/rst/java/code/jdocs/persistence/query/MyEventsByTagJavaPublisher.java @@ -2,18 +2,16 @@ * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.persistence.query; +package jdocs.persistence.query; import akka.actor.Cancellable; import akka.actor.Scheduler; import akka.japi.Pair; -import akka.japi.pf.ReceiveBuilder; import akka.persistence.PersistentRepr; import akka.persistence.query.Offset; import akka.serialization.Serialization; import akka.serialization.SerializationExtension; import akka.stream.actor.AbstractActorPublisher; -import scala.Int; import akka.actor.Props; import akka.persistence.query.EventEnvelope; @@ -33,7 +31,7 @@ import static java.util.stream.Collectors.toList; //#events-by-tag-publisher class MyEventsByTagJavaPublisher extends AbstractActorPublisher { private final Serialization serialization = - SerializationExtension.get(getContext().system()); + SerializationExtension.get(getContext().getSystem()); private final Connection connection; @@ -54,10 +52,10 @@ class MyEventsByTagJavaPublisher extends AbstractActorPublisher { this.tag = tag; this.currentOffset = offset; - final Scheduler scheduler = getContext().system().scheduler(); + final Scheduler scheduler = getContext().getSystem().scheduler(); this.continueTask = scheduler - .schedule(refreshInterval, refreshInterval, self(), CONTINUE, - getContext().dispatcher(), self()); + .schedule(refreshInterval, refreshInterval, getSelf(), CONTINUE, + getContext().dispatcher(), getSelf()); } @Override @@ -68,7 +66,7 @@ class MyEventsByTagJavaPublisher extends AbstractActorPublisher { deliverBuf(); }) .match(Cancel.class, (in) -> { - getContext().stop(self()); + getContext().stop(getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/remoting/RemoteDeploymentDocTest.java b/akka-docs/rst/java/code/jdocs/remoting/RemoteDeploymentDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/remoting/RemoteDeploymentDocTest.java rename to akka-docs/rst/java/code/jdocs/remoting/RemoteDeploymentDocTest.java index fc136366ee..674964ef59 100644 --- a/akka-docs/rst/java/code/docs/remoting/RemoteDeploymentDocTest.java +++ b/akka-docs/rst/java/code/jdocs/remoting/RemoteDeploymentDocTest.java @@ -1,10 +1,10 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.remoting; +package jdocs.remoting; import akka.testkit.AkkaJUnitActorSystemResource; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.ClassRule; import org.junit.Test; @@ -28,7 +28,7 @@ public class RemoteDeploymentDocTest extends AbstractJavaTest { @Override public Receive createReceive() { return receiveBuilder() - .matchAny(message -> sender().tell(self(), self())) + .matchAny(message -> getSender().tell(getSelf(), getSelf())) .build(); } } diff --git a/akka-docs/rst/java/code/docs/jrouting/ConsistentHashingRouterDocTest.java b/akka-docs/rst/java/code/jdocs/routing/ConsistentHashingRouterDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/jrouting/ConsistentHashingRouterDocTest.java rename to akka-docs/rst/java/code/jdocs/routing/ConsistentHashingRouterDocTest.java index 39cf9ea551..3360f91110 100644 --- a/akka-docs/rst/java/code/docs/jrouting/ConsistentHashingRouterDocTest.java +++ b/akka-docs/rst/java/code/jdocs/routing/ConsistentHashingRouterDocTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.jrouting; +package jdocs.routing; import akka.testkit.AkkaJUnitActorSystemResource; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.ClassRule; import org.junit.Test; @@ -26,7 +26,6 @@ import java.io.Serializable; import akka.actor.Props; import akka.actor.ActorRef; import akka.routing.ConsistentHashingPool; -import akka.routing.ConsistentHashingRouter; import akka.routing.ConsistentHashingRouter.ConsistentHashMapper; import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope; //#imports2 @@ -52,8 +51,7 @@ public class ConsistentHashingRouterDocTest extends AbstractJavaTest { }) .match(Get.class, get -> { Object value = cache.get(get.key); - sender().tell(value == null ? NOT_FOUND : value, - getContext().self()); + getSender().tell(value == null ? NOT_FOUND : value, getSelf()); }) .match(Evict.class, evict -> { cache.remove(evict.key); diff --git a/akka-docs/rst/java/code/docs/jrouting/CustomRouterDocTest.java b/akka-docs/rst/java/code/jdocs/routing/CustomRouterDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/jrouting/CustomRouterDocTest.java rename to akka-docs/rst/java/code/jdocs/routing/CustomRouterDocTest.java index dc2d3d3fa9..7d8bd26c53 100644 --- a/akka-docs/rst/java/code/docs/jrouting/CustomRouterDocTest.java +++ b/akka-docs/rst/java/code/jdocs/routing/CustomRouterDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.jrouting; +package jdocs.routing; import akka.routing.FromConfig; import akka.routing.RoundRobinRoutingLogic; @@ -10,7 +10,7 @@ import akka.routing.RoutingLogic; import akka.routing.SeveralRoutees; import akka.testkit.AkkaJUnitActorSystemResource; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.ClassRule; import org.junit.Test; @@ -20,8 +20,7 @@ import com.typesafe.config.ConfigFactory; import scala.collection.immutable.IndexedSeq; import static akka.japi.Util.immutableIndexedSeq; -import docs.jrouting.RouterDocTest.Parent; -import docs.jrouting.RouterDocTest.Workers; + import docs.routing.CustomRouterDocSpec; import akka.testkit.JavaTestKit; import akka.actor.ActorRef; @@ -30,7 +29,6 @@ import akka.actor.Props; //#imports1 import akka.actor.AbstractActor; -import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -99,7 +97,7 @@ public class CustomRouterDocTest extends AbstractJavaTest { public Receive createReceive() { return receiveBuilder() .matchAny(message -> { - sender().tell(message, self()); + getSender().tell(message, getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/jrouting/RedundancyGroup.java b/akka-docs/rst/java/code/jdocs/routing/RedundancyGroup.java similarity index 71% rename from akka-docs/rst/java/code/docs/jrouting/RedundancyGroup.java rename to akka-docs/rst/java/code/jdocs/routing/RedundancyGroup.java index 8ac3d0992f..1eebebffe9 100644 --- a/akka-docs/rst/java/code/docs/jrouting/RedundancyGroup.java +++ b/akka-docs/rst/java/code/jdocs/routing/RedundancyGroup.java @@ -1,29 +1,19 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.jrouting; +package jdocs.routing; //#group import java.util.List; -import scala.Option; -import scala.collection.immutable.Iterable; -import akka.actor.ActorContext; -import akka.actor.ActorPath; import akka.actor.ActorSystem; -import akka.actor.Props; import akka.dispatch.Dispatchers; -import akka.routing.Group; -import akka.routing.Routee; import akka.routing.Router; -import akka.routing.RouterActor; -import akka.routing.RouterConfig; -import akka.routing.RoutingLogic; import com.typesafe.config.Config; import akka.routing.GroupBase; -import static docs.jrouting.CustomRouterDocTest.RedundancyRoutingLogic; +import static jdocs.routing.CustomRouterDocTest.RedundancyRoutingLogic; public class RedundancyGroup extends GroupBase { private final List paths; diff --git a/akka-docs/rst/java/code/docs/jrouting/RouterDocTest.java b/akka-docs/rst/java/code/jdocs/routing/RouterDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/jrouting/RouterDocTest.java rename to akka-docs/rst/java/code/jdocs/routing/RouterDocTest.java index 2b8bdf6b6a..d5bdd09f26 100644 --- a/akka-docs/rst/java/code/docs/jrouting/RouterDocTest.java +++ b/akka-docs/rst/java/code/jdocs/routing/RouterDocTest.java @@ -1,11 +1,11 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.jrouting; +package jdocs.routing; import akka.testkit.AkkaJUnitActorSystemResource; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.ClassRule; import org.junit.Test; @@ -107,7 +107,7 @@ public class RouterDocTest extends AbstractJavaTest { public Receive createReceive() { return receiveBuilder() .match(Work.class, message -> { - router.route(message, sender()); + router.route(message, getSender()); }) .match(Terminated.class, message -> { router = router.removeRoutee(message.actor()); @@ -132,7 +132,7 @@ public class RouterDocTest extends AbstractJavaTest { @Override public Receive createReceive() { return receiveBuilder() - .matchAny(message -> sender().tell(message, self())) + .matchAny(message -> getSender().tell(message, getSelf())) .build(); } } @@ -143,11 +143,11 @@ public class RouterDocTest extends AbstractJavaTest { return receiveBuilder() .matchAny(message -> { //#reply-with-self - sender().tell("reply", self()); + getSender().tell("reply", getSelf()); //#reply-with-self //#reply-with-parent - sender().tell("reply", getContext().parent()); + getSender().tell("reply", getContext().getParent()); //#reply-with-parent }) .build(); diff --git a/akka-docs/rst/java/code/docs/serialization/SerializationDocTest.java b/akka-docs/rst/java/code/jdocs/serialization/SerializationDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/serialization/SerializationDocTest.java rename to akka-docs/rst/java/code/jdocs/serialization/SerializationDocTest.java index 46e07d4197..bad2340c97 100644 --- a/akka-docs/rst/java/code/docs/serialization/SerializationDocTest.java +++ b/akka-docs/rst/java/code/jdocs/serialization/SerializationDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.serialization; +package jdocs.serialization; import java.io.UnsupportedEncodingException; diff --git a/akka-docs/rst/java/code/docs/stream/ActorPublisherDocTest.java b/akka-docs/rst/java/code/jdocs/stream/ActorPublisherDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/stream/ActorPublisherDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/ActorPublisherDocTest.java index 5a2023b1d4..7888d7f0fc 100644 --- a/akka-docs/rst/java/code/docs/stream/ActorPublisherDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/ActorPublisherDocTest.java @@ -1,12 +1,11 @@ /* * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; -import akka.japi.pf.ReceiveBuilder; import akka.stream.ActorMaterializer; import akka.stream.Materializer; import akka.stream.actor.AbstractActorPublisher; @@ -14,7 +13,7 @@ import akka.stream.actor.ActorPublisherMessage; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.JavaTestKit; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -79,10 +78,10 @@ public class ActorPublisherDocTest extends AbstractJavaTest { public Receive createReceive() { return receiveBuilder() .match(JobManagerProtocol.Job.class, job -> buf.size() == MAX_BUFFER_SIZE, job -> { - sender().tell(JobManagerProtocol.JobDenied, self()); + getSender().tell(JobManagerProtocol.JobDenied, getSelf()); }) .match(JobManagerProtocol.Job.class, job -> { - sender().tell(JobManagerProtocol.JobAccepted, self()); + getSender().tell(JobManagerProtocol.JobAccepted, getSelf()); if (buf.isEmpty() && totalDemand() > 0) onNext(job); diff --git a/akka-docs/rst/java/code/docs/stream/ActorSubscriberDocTest.java b/akka-docs/rst/java/code/jdocs/stream/ActorSubscriberDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/stream/ActorSubscriberDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/ActorSubscriberDocTest.java index 8f1af033ee..76993eeee0 100644 --- a/akka-docs/rst/java/code/docs/stream/ActorSubscriberDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/ActorSubscriberDocTest.java @@ -2,13 +2,12 @@ * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.actor.AbstractActor; import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Props; -import akka.japi.pf.ReceiveBuilder; import akka.routing.ActorRefRoutee; import akka.routing.RoundRobinRoutingLogic; import akka.routing.Routee; @@ -22,7 +21,7 @@ import akka.stream.actor.RequestStrategy; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.JavaTestKit; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -176,7 +175,7 @@ public class ActorSubscriberDocTest extends AbstractJavaTest { if (queue.size() > MAX_QUEUE_SIZE) throw new RuntimeException("queued too many: " + queue.size()); - router.route(WorkerPoolProtocol.work(msg.id), self()); + router.route(WorkerPoolProtocol.work(msg.id), getSelf()); }) .match(ActorSubscriberMessage.onCompleteInstance().getClass(), complete -> { if (queue.isEmpty()) { @@ -185,7 +184,7 @@ public class ActorSubscriberDocTest extends AbstractJavaTest { }) .match(WorkerPoolProtocol.Reply.class, reply -> { int id = reply.id; - queue.get(id).tell(WorkerPoolProtocol.done(id), self()); + queue.get(id).tell(WorkerPoolProtocol.done(id), getSelf()); queue.remove(id); if (canceled() && queue.isEmpty()) { getContext().stop(self()); @@ -201,7 +200,7 @@ public class ActorSubscriberDocTest extends AbstractJavaTest { return receiveBuilder() .match(WorkerPoolProtocol.Work.class, work -> { // ... - sender().tell(WorkerPoolProtocol.reply(work.id), self()); + getSender().tell(WorkerPoolProtocol.reply(work.id), getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/stream/BidiFlowDocTest.java b/akka-docs/rst/java/code/jdocs/stream/BidiFlowDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/BidiFlowDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/BidiFlowDocTest.java index 9338078530..a36433bb0d 100644 --- a/akka-docs/rst/java/code/docs/stream/BidiFlowDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/BidiFlowDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import java.nio.ByteOrder; import java.util.Arrays; @@ -11,7 +11,7 @@ import java.util.concurrent.TimeUnit; import akka.NotUsed; import akka.stream.javadsl.GraphDSL; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/CompositionDocTest.java b/akka-docs/rst/java/code/jdocs/stream/CompositionDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/CompositionDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/CompositionDocTest.java index 4f0bb3d5db..dd995c8fa7 100644 --- a/akka-docs/rst/java/code/docs/stream/CompositionDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/CompositionDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import java.util.Arrays; import java.util.Optional; @@ -10,22 +10,18 @@ import java.util.concurrent.CompletionStage; import akka.NotUsed; import akka.stream.ClosedShape; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import akka.actor.ActorSystem; -import akka.dispatch.Mapper; import akka.japi.Pair; import akka.stream.*; import akka.stream.javadsl.*; import akka.stream.javadsl.Tcp.OutgoingConnection; import akka.testkit.JavaTestKit; import akka.util.ByteString; -import scala.concurrent.*; - -import scala.Option; public class CompositionDocTest extends AbstractJavaTest { diff --git a/akka-docs/rst/java/code/docs/stream/FlowDocTest.java b/akka-docs/rst/java/code/jdocs/stream/FlowDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/FlowDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/FlowDocTest.java index e815cc84a7..48eb646ebc 100644 --- a/akka-docs/rst/java/code/docs/stream/FlowDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/FlowDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import static org.junit.Assert.assertEquals; @@ -9,11 +9,10 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionStage; import java.util.concurrent.TimeUnit; -import java.util.stream.Stream; import akka.NotUsed; import akka.japi.Pair; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/FlowErrorDocTest.java b/akka-docs/rst/java/code/jdocs/stream/FlowErrorDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/FlowErrorDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/FlowErrorDocTest.java index 1f762f6da9..ef733ebfed 100644 --- a/akka-docs/rst/java/code/docs/stream/FlowErrorDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/FlowErrorDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import static org.junit.Assert.assertEquals; import java.util.Arrays; @@ -11,7 +11,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import akka.NotUsed; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/FlowParallelismDocTest.java b/akka-docs/rst/java/code/jdocs/stream/FlowParallelismDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/FlowParallelismDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/FlowParallelismDocTest.java index 4823ac959f..00d4af8ded 100644 --- a/akka-docs/rst/java/code/docs/stream/FlowParallelismDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/FlowParallelismDocTest.java @@ -1,13 +1,13 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import static org.junit.Assert.assertEquals; import akka.NotUsed; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/GraphCyclesDocTest.java b/akka-docs/rst/java/code/jdocs/stream/GraphCyclesDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/GraphCyclesDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/GraphCyclesDocTest.java index 97777e3307..cbed775c43 100644 --- a/akka-docs/rst/java/code/docs/stream/GraphCyclesDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/GraphCyclesDocTest.java @@ -1,9 +1,9 @@ -package docs.stream; +package jdocs.stream; import java.util.Arrays; import akka.NotUsed; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/GraphDSLDocTest.java b/akka-docs/rst/java/code/jdocs/stream/GraphDSLDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/GraphDSLDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/GraphDSLDocTest.java index 2d02ebb156..16058c1382 100644 --- a/akka-docs/rst/java/code/docs/stream/GraphDSLDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/GraphDSLDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import static org.junit.Assert.*; @@ -13,7 +13,7 @@ import java.util.concurrent.TimeUnit; import akka.NotUsed; import akka.stream.ClosedShape; import akka.stream.SourceShape; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/GraphStageDocTest.java b/akka-docs/rst/java/code/jdocs/stream/GraphStageDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/GraphStageDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/GraphStageDocTest.java index 64773f7f64..ee1852463f 100644 --- a/akka-docs/rst/java/code/docs/stream/GraphStageDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/GraphStageDocTest.java @@ -1,12 +1,10 @@ -package docs.stream; +package jdocs.stream; import akka.Done; import akka.NotUsed; import akka.actor.ActorSystem; //#imports import akka.dispatch.Futures; -import akka.dispatch.Mapper; -import akka.dispatch.OnSuccess; import akka.japi.Option; import akka.japi.Predicate; import akka.japi.function.Procedure; @@ -18,7 +16,7 @@ import akka.stream.testkit.TestPublisher; import akka.stream.testkit.TestSubscriber; import akka.testkit.JavaTestKit; import akka.japi.Function; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/GraphStageLoggingDocTest.java b/akka-docs/rst/java/code/jdocs/stream/GraphStageLoggingDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/stream/GraphStageLoggingDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/GraphStageLoggingDocTest.java index 6771553eb8..2de4df547d 100644 --- a/akka-docs/rst/java/code/docs/stream/GraphStageLoggingDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/GraphStageLoggingDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2016-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.actor.ActorSystem; import akka.stream.Attributes; @@ -10,11 +10,10 @@ import akka.stream.Materializer; import akka.stream.Outlet; import akka.stream.SourceShape; import akka.stream.stage.*; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.Test; import java.util.concurrent.ThreadLocalRandom; -import java.util.stream.Collector; public class GraphStageLoggingDocTest extends AbstractJavaTest { static ActorSystem system; diff --git a/akka-docs/rst/java/code/docs/stream/HubDocTest.java b/akka-docs/rst/java/code/jdocs/stream/HubDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/HubDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/HubDocTest.java index 79d2745687..01426ae912 100644 --- a/akka-docs/rst/java/code/docs/stream/HubDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/HubDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.Done; import akka.NotUsed; @@ -14,7 +14,7 @@ import akka.stream.Materializer; import akka.stream.UniqueKillSwitch; import akka.stream.javadsl.*; import akka.testkit.JavaTestKit; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/IntegrationDocTest.java b/akka-docs/rst/java/code/jdocs/stream/IntegrationDocTest.java similarity index 97% rename from akka-docs/rst/java/code/docs/stream/IntegrationDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/IntegrationDocTest.java index e1456dee51..44b7f65048 100644 --- a/akka-docs/rst/java/code/docs/stream/IntegrationDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/IntegrationDocTest.java @@ -2,11 +2,10 @@ * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.NotUsed; import akka.actor.*; -import akka.japi.pf.ReceiveBuilder; import akka.stream.*; import akka.stream.javadsl.*; import akka.testkit.JavaTestKit; @@ -15,14 +14,13 @@ import akka.util.Timeout; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; -import docs.AbstractJavaTest; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Author; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Tweet; +import jdocs.AbstractJavaTest; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Author; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Tweet; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import scala.Option; -import scala.PartialFunction; + import java.util.Arrays; import java.util.HashSet; import java.util.Optional; @@ -33,8 +31,8 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import static akka.pattern.PatternsCS.ask; -import static docs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; -import static docs.stream.TwitterStreamQuickstartDocTest.Model.tweets; +import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; +import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.tweets; import static junit.framework.TestCase.assertTrue; public class IntegrationDocTest extends AbstractJavaTest { @@ -264,7 +262,7 @@ public class IntegrationDocTest extends AbstractJavaTest { return receiveBuilder() .match(Save.class, s -> { probe.tell(s.tweet.author.handle, ActorRef.noSender()); - sender().tell(SaveDone.INSTANCE, self()); + getSender().tell(SaveDone.INSTANCE, getSelf()); }) .build(); } @@ -303,7 +301,7 @@ public class IntegrationDocTest extends AbstractJavaTest { // ... process message String reply = word.toUpperCase(); // reply to the ask - sender().tell(reply, self()); + getSender().tell(reply, getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/code/docs/stream/KillSwitchDocTest.java b/akka-docs/rst/java/code/jdocs/stream/KillSwitchDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/KillSwitchDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/KillSwitchDocTest.java index c3613dacdb..cf4c51196c 100644 --- a/akka-docs/rst/java/code/docs/stream/KillSwitchDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/KillSwitchDocTest.java @@ -1,4 +1,4 @@ -package docs.stream; +package jdocs.stream; import akka.NotUsed; import akka.actor.ActorSystem; @@ -8,7 +8,7 @@ import akka.stream.javadsl.Keep; import akka.stream.javadsl.Sink; import akka.stream.javadsl.Source; import akka.testkit.JavaTestKit; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; diff --git a/akka-docs/rst/java/code/docs/stream/MigrationsJava.java b/akka-docs/rst/java/code/jdocs/stream/MigrationsJava.java similarity index 97% rename from akka-docs/rst/java/code/docs/stream/MigrationsJava.java rename to akka-docs/rst/java/code/jdocs/stream/MigrationsJava.java index 7d32c10436..44798335ca 100644 --- a/akka-docs/rst/java/code/docs/stream/MigrationsJava.java +++ b/akka-docs/rst/java/code/jdocs/stream/MigrationsJava.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import java.util.stream.Stream; diff --git a/akka-docs/rst/java/code/docs/stream/QuickStartDocTest.java b/akka-docs/rst/java/code/jdocs/stream/QuickStartDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/QuickStartDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/QuickStartDocTest.java index e58a55318c..50fce73f1b 100644 --- a/akka-docs/rst/java/code/docs/stream/QuickStartDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/QuickStartDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2016-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; //#stream-imports import akka.stream.*; @@ -20,7 +20,7 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import scala.concurrent.duration.Duration; //#other-imports diff --git a/akka-docs/rst/java/code/docs/stream/RateTransformationDocTest.java b/akka-docs/rst/java/code/jdocs/stream/RateTransformationDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/RateTransformationDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/RateTransformationDocTest.java index 05b1521d05..cea485584a 100644 --- a/akka-docs/rst/java/code/docs/stream/RateTransformationDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/RateTransformationDocTest.java @@ -2,7 +2,7 @@ * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import java.util.ArrayList; import java.util.Collections; @@ -14,7 +14,7 @@ import java.util.stream.DoubleStream; import java.util.stream.Stream; import akka.NotUsed; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/ReactiveStreamsDocTest.java b/akka-docs/rst/java/code/jdocs/stream/ReactiveStreamsDocTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/stream/ReactiveStreamsDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/ReactiveStreamsDocTest.java index d54064e4b2..5d3ac467f3 100644 --- a/akka-docs/rst/java/code/docs/stream/ReactiveStreamsDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/ReactiveStreamsDocTest.java @@ -2,23 +2,21 @@ * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.NotUsed; import akka.actor.ActorRef; import akka.actor.ActorSystem; -import akka.japi.Pair; import akka.japi.function.Creator; import akka.stream.*; import akka.stream.javadsl.*; import akka.testkit.JavaTestKit; import akka.testkit.TestProbe; -import docs.AbstractJavaTest; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Author; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Tweet; +import jdocs.AbstractJavaTest; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Author; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Tweet; import org.junit.AfterClass; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; //#imports @@ -31,8 +29,8 @@ import org.reactivestreams.Subscription; import java.lang.Exception; -import static docs.stream.ReactiveStreamsDocTest.Fixture.Data.authors; -import static docs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; +import static jdocs.stream.ReactiveStreamsDocTest.Fixture.Data.authors; +import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; public class ReactiveStreamsDocTest extends AbstractJavaTest { diff --git a/akka-docs/rst/java/code/docs/stream/SilenceSystemOut.java b/akka-docs/rst/java/code/jdocs/stream/SilenceSystemOut.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/SilenceSystemOut.java rename to akka-docs/rst/java/code/jdocs/stream/SilenceSystemOut.java index b4b17162ea..04b85df45b 100644 --- a/akka-docs/rst/java/code/docs/stream/SilenceSystemOut.java +++ b/akka-docs/rst/java/code/jdocs/stream/SilenceSystemOut.java @@ -1,4 +1,4 @@ -package docs.stream; +package jdocs.stream; import akka.actor.ActorRef; diff --git a/akka-docs/rst/java/code/docs/stream/StreamBuffersRateDocTest.java b/akka-docs/rst/java/code/jdocs/stream/StreamBuffersRateDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/StreamBuffersRateDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/StreamBuffersRateDocTest.java index 9a1986d4f8..5be5648860 100644 --- a/akka-docs/rst/java/code/docs/stream/StreamBuffersRateDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/StreamBuffersRateDocTest.java @@ -1,13 +1,13 @@ /** * Copyright (C) 2014-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import java.util.Arrays; import java.util.concurrent.TimeUnit; import akka.NotUsed; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/StreamPartialGraphDSLDocTest.java b/akka-docs/rst/java/code/jdocs/stream/StreamPartialGraphDSLDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/StreamPartialGraphDSLDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/StreamPartialGraphDSLDocTest.java index e832b8b4e4..d49600a6f7 100644 --- a/akka-docs/rst/java/code/docs/stream/StreamPartialGraphDSLDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/StreamPartialGraphDSLDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.Done; import akka.NotUsed; @@ -11,7 +11,7 @@ import akka.japi.Pair; import akka.stream.*; import akka.stream.javadsl.*; import akka.testkit.JavaTestKit; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/StreamTestKitDocTest.java b/akka-docs/rst/java/code/jdocs/stream/StreamTestKitDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/StreamTestKitDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/StreamTestKitDocTest.java index 7582e8677d..06e81d4939 100644 --- a/akka-docs/rst/java/code/docs/stream/StreamTestKitDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/StreamTestKitDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import java.util.Arrays; import java.util.Collections; @@ -12,7 +12,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import akka.NotUsed; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.*; import static org.junit.Assert.assertEquals; @@ -24,8 +24,6 @@ import akka.stream.javadsl.*; import akka.stream.testkit.*; import akka.stream.testkit.javadsl.*; import akka.testkit.TestProbe; -import scala.util.*; -import scala.concurrent.Await; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; diff --git a/akka-docs/rst/java/code/docs/stream/TwitterStreamQuickstartDocTest.java b/akka-docs/rst/java/code/jdocs/stream/TwitterStreamQuickstartDocTest.java similarity index 96% rename from akka-docs/rst/java/code/docs/stream/TwitterStreamQuickstartDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/TwitterStreamQuickstartDocTest.java index d3765ed22b..4bb651624f 100644 --- a/akka-docs/rst/java/code/docs/stream/TwitterStreamQuickstartDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/TwitterStreamQuickstartDocTest.java @@ -1,22 +1,21 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream; +package jdocs.stream; import akka.Done; import akka.NotUsed; import akka.actor.ActorSystem; -import akka.dispatch.Foreach; import akka.japi.JavaPartialFunction; import akka.testkit.JavaTestKit; //#imports import akka.stream.*; import akka.stream.javadsl.*; //#imports -import docs.AbstractJavaTest; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Author; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Hashtag; -import docs.stream.TwitterStreamQuickstartDocTest.Model.Tweet; +import jdocs.AbstractJavaTest; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Author; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Hashtag; +import jdocs.stream.TwitterStreamQuickstartDocTest.Model.Tweet; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -31,8 +30,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; -import static docs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; -import static docs.stream.TwitterStreamQuickstartDocTest.Model.tweets; +import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.AKKA; +import static jdocs.stream.TwitterStreamQuickstartDocTest.Model.tweets; @SuppressWarnings("unused") public class TwitterStreamQuickstartDocTest extends AbstractJavaTest { diff --git a/akka-docs/rst/java/code/docs/stream/io/StreamFileDocTest.java b/akka-docs/rst/java/code/jdocs/stream/io/StreamFileDocTest.java similarity index 95% rename from akka-docs/rst/java/code/docs/stream/io/StreamFileDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/io/StreamFileDocTest.java index 302dea4db1..378894c9c7 100644 --- a/akka-docs/rst/java/code/docs/stream/io/StreamFileDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/io/StreamFileDocTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.io; +package jdocs.stream.io; import java.nio.file.Files; import java.nio.file.Path; @@ -14,8 +14,8 @@ import akka.actor.ActorSystem; import akka.stream.ActorAttributes; import akka.stream.javadsl.Sink; import akka.stream.javadsl.FileIO; -import docs.AbstractJavaTest; -import docs.stream.SilenceSystemOut; +import jdocs.AbstractJavaTest; +import jdocs.stream.SilenceSystemOut; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/io/StreamTcpDocTest.java b/akka-docs/rst/java/code/jdocs/stream/io/StreamTcpDocTest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/io/StreamTcpDocTest.java rename to akka-docs/rst/java/code/jdocs/stream/io/StreamTcpDocTest.java index fa7635e0fc..8359d56595 100644 --- a/akka-docs/rst/java/code/docs/stream/io/StreamTcpDocTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/io/StreamTcpDocTest.java @@ -1,15 +1,15 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.io; +package jdocs.stream.io; import java.util.concurrent.CompletionStage; import java.util.concurrent.ConcurrentLinkedQueue; import akka.NotUsed; import akka.stream.javadsl.Framing; -import docs.AbstractJavaTest; -import docs.stream.SilenceSystemOut; +import jdocs.AbstractJavaTest; +import jdocs.stream.SilenceSystemOut; import java.net.InetSocketAddress; import org.junit.AfterClass; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeByteStrings.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeByteStrings.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java index e769d90f21..26897d4d75 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeByteStrings.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDecompress.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDecompress.java similarity index 96% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDecompress.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDecompress.java index 1c34768e66..34c0d1bab8 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDecompress.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDecompress.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2016-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; @@ -19,7 +19,6 @@ import org.junit.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.zip.GZIPOutputStream; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDigest.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDigest.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDigest.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDigest.java index c9b5446c2f..ee728a3fbd 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDigest.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDigest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; @@ -17,7 +17,6 @@ import org.junit.Test; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.security.Security; import java.util.Arrays; import java.util.concurrent.TimeUnit; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java index e2c3fee9f2..5c0ccb9e2e 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.Done; import akka.NotUsed; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeFlattenList.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java similarity index 97% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeFlattenList.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java index 597a4ed3fe..128f1922e1 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeFlattenList.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java similarity index 95% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java index c3d9088019..3399981ffb 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java @@ -1,11 +1,10 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.*; -import akka.japi.pf.ReceiveBuilder; import akka.pattern.PatternsCS; import akka.stream.*; import akka.stream.javadsl.*; @@ -16,10 +15,8 @@ import akka.util.Timeout; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import scala.PartialFunction; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; -import scala.runtime.BoxedUnit; import java.util.*; @@ -83,10 +80,10 @@ public class RecipeGlobalRateLimit extends RecipeTest { this.replenishTimer = system.scheduler().schedule( this.tokenRefreshPeriod, this.tokenRefreshPeriod, - self(), + getSelf(), REPLENISH_TOKENS, - getContext().system().dispatcher(), - self()); + getContext().getSystem().dispatcher(), + getSelf()); } @Override @@ -101,7 +98,7 @@ public class RecipeGlobalRateLimit extends RecipeTest { }) .match(WantToPass.class, wtp -> { permitTokens -= 1; - sender().tell(MAY_PASS, self()); + getSender().tell(MAY_PASS, getSelf()); if (permitTokens == 0) { getContext().become(closed()); } @@ -129,7 +126,7 @@ public class RecipeGlobalRateLimit extends RecipeTest { permitTokens --; } - toBeReleased.stream().forEach(ref -> ref.tell(MAY_PASS, self())); + toBeReleased.stream().forEach(ref -> ref.tell(MAY_PASS, getSelf())); if (permitTokens > 0) { getContext().become(open()); } @@ -139,7 +136,7 @@ public class RecipeGlobalRateLimit extends RecipeTest { public void postStop() { replenishTimer.cancel(); waitQueue.stream().forEach(ref -> { - ref.tell(new Status.Failure(new IllegalStateException("limiter stopped")), self()); + ref.tell(new Status.Failure(new IllegalStateException("limiter stopped")), getSelf()); }); } } diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeHold.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeHold.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeHold.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeHold.java index 5c5383bfdd..a4d0c2c28f 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeHold.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeHold.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.actor.ActorSystem; import akka.japi.Pair; @@ -15,7 +15,6 @@ import akka.stream.testkit.TestSubscriber; import akka.stream.testkit.javadsl.TestSink; import akka.stream.testkit.javadsl.TestSource; import akka.testkit.JavaTestKit; -import akka.util.ByteString; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeKeepAlive.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java similarity index 97% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeKeepAlive.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java index 2ce6477edc..f446095b82 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeKeepAlive.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeLoggingElements.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java similarity index 97% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeLoggingElements.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java index 7f6c3993a7..192fb03650 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeLoggingElements.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; @@ -15,7 +15,7 @@ import akka.stream.javadsl.Source; import akka.testkit.DebugFilter; import akka.testkit.JavaTestKit; import com.typesafe.config.ConfigFactory; -import docs.stream.SilenceSystemOut; +import jdocs.stream.SilenceSystemOut; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeManualTrigger.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeManualTrigger.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java index c972242869..2da7715417 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeManualTrigger.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.actor.ActorSystem; import akka.japi.Pair; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeMissedTicks.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeMissedTicks.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java index 6f9e0b4bf8..56dc33eb41 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeMissedTicks.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java index 4b420eaeab..cf29fc001f 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeParseLines.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeParseLines.java similarity index 97% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeParseLines.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeParseLines.java index 858da92a77..7551b4c9b3 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeParseLines.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeParseLines.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java index b2e9028d41..f01d1b222f 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeSeq.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeSeq.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeSeq.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeSeq.java index 648e7b5ddf..2c11d0e817 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeSeq.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeSeq.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeSimpleDrop.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeSimpleDrop.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java index a7ef0e5c09..3e8664a846 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeSimpleDrop.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeTest.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeTest.java similarity index 90% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeTest.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeTest.java index e74b5cdeb0..ccd8ed3eb2 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeTest.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeTest.java @@ -1,6 +1,6 @@ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; public abstract class RecipeTest extends AbstractJavaTest { final class Message { diff --git a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeWorkerPool.java b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java similarity index 98% rename from akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeWorkerPool.java rename to akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java index c1683afb05..82a12aae17 100644 --- a/akka-docs/rst/java/code/docs/stream/javadsl/cookbook/RecipeWorkerPool.java +++ b/akka-docs/rst/java/code/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2015-2017 Lightbend Inc. */ -package docs.stream.javadsl.cookbook; +package jdocs.stream.javadsl.cookbook; import akka.NotUsed; import akka.actor.ActorSystem; diff --git a/akka-docs/rst/java/code/docs/testkit/ParentChildTest.java b/akka-docs/rst/java/code/jdocs/testkit/ParentChildTest.java similarity index 93% rename from akka-docs/rst/java/code/docs/testkit/ParentChildTest.java rename to akka-docs/rst/java/code/jdocs/testkit/ParentChildTest.java index d48034863d..2888e4cf5f 100644 --- a/akka-docs/rst/java/code/docs/testkit/ParentChildTest.java +++ b/akka-docs/rst/java/code/jdocs/testkit/ParentChildTest.java @@ -1,7 +1,7 @@ /** * Copyright (C) 2014-2017 Lightbend Inc. */ -package docs.testkit; +package jdocs.testkit; import static org.junit.Assert.*; import akka.actor.*; @@ -14,7 +14,8 @@ import akka.testkit.TestProbe; import com.typesafe.config.ConfigFactory; -import docs.AbstractJavaTest; +import docs.testkit.MockedChild; +import jdocs.AbstractJavaTest; import org.junit.ClassRule; import org.junit.Test; @@ -35,7 +36,7 @@ public class ParentChildTest extends AbstractJavaTest { @Override public Receive createReceive() { return receiveBuilder() - .matchEquals("pingit", message -> child.tell("ping", self())) + .matchEquals("pingit", message -> child.tell("ping", getSelf())) .matchEquals("pong", message -> ponged = true) .build(); } @@ -46,7 +47,7 @@ public class ParentChildTest extends AbstractJavaTest { public Receive createReceive() { return receiveBuilder() .matchEquals("ping", message -> { - getContext().parent().tell("pong", self()); + getContext().getParent().tell("pong", getSelf()); }) .build(); } @@ -65,7 +66,7 @@ public class ParentChildTest extends AbstractJavaTest { @Override public Receive createReceive() { return receiveBuilder() - .matchEquals("ping", message -> parent.tell("pong", self())) + .matchEquals("ping", message -> parent.tell("pong", getSelf())) .build(); } } @@ -84,7 +85,7 @@ public class ParentChildTest extends AbstractJavaTest { @Override public Receive createReceive() { return receiveBuilder() - .matchEquals("pingit", message -> child.tell("ping", self())) + .matchEquals("pingit", message -> child.tell("ping", getSelf())) .matchEquals("pong", message -> ponged = true) .build(); } @@ -105,7 +106,7 @@ public class ParentChildTest extends AbstractJavaTest { @Override public Receive createReceive() { return receiveBuilder() - .matchEquals("pingit", message -> child.tell("ping", self())) + .matchEquals("pingit", message -> child.tell("ping", getSelf())) .matchEquals("pong", message -> ponged = true) .build(); } diff --git a/akka-docs/rst/java/code/docs/testkit/TestKitDocTest.java b/akka-docs/rst/java/code/jdocs/testkit/TestKitDocTest.java similarity index 99% rename from akka-docs/rst/java/code/docs/testkit/TestKitDocTest.java rename to akka-docs/rst/java/code/jdocs/testkit/TestKitDocTest.java index 38f6d33ea7..a5a499328e 100644 --- a/akka-docs/rst/java/code/docs/testkit/TestKitDocTest.java +++ b/akka-docs/rst/java/code/jdocs/testkit/TestKitDocTest.java @@ -1,13 +1,13 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.testkit; +package jdocs.testkit; import static org.junit.Assert.*; import akka.pattern.PatternsCS; import akka.testkit.*; -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.Assert; import org.junit.ClassRule; import org.junit.Test; @@ -42,7 +42,7 @@ public class TestKitDocTest extends AbstractJavaTest { public Receive createReceive() { return receiveBuilder() .matchEquals("say42", message -> { - sender().tell(42, self()); + getSender().tell(42, getSelf()); }) .match(Exception.class, (Exception ex) -> { throw ex; diff --git a/akka-docs/rst/java/code/docs/testkit/TestKitSampleTest.java b/akka-docs/rst/java/code/jdocs/testkit/TestKitSampleTest.java similarity index 94% rename from akka-docs/rst/java/code/docs/testkit/TestKitSampleTest.java rename to akka-docs/rst/java/code/jdocs/testkit/TestKitSampleTest.java index d2706e1b26..b123742a9a 100644 --- a/akka-docs/rst/java/code/docs/testkit/TestKitSampleTest.java +++ b/akka-docs/rst/java/code/jdocs/testkit/TestKitSampleTest.java @@ -1,10 +1,10 @@ /** * Copyright (C) 2009-2017 Lightbend Inc. */ -package docs.testkit; +package jdocs.testkit; //#fullsample -import docs.AbstractJavaTest; +import jdocs.AbstractJavaTest; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -26,12 +26,12 @@ public class TestKitSampleTest extends AbstractJavaTest { public Receive createReceive() { return receiveBuilder() .matchEquals("hello", message -> { - sender().tell("world", self()); + getSender().tell("world", getSelf()); if (target != null) target.forward(message, getContext()); }) .match(ActorRef.class, actorRef -> { target = actorRef; - sender().tell("done", self()); + getSender().tell("done", getSelf()); }) .build(); } diff --git a/akka-docs/rst/java/dispatchers.rst b/akka-docs/rst/java/dispatchers.rst index 6ba186af90..1982bd687c 100644 --- a/akka-docs/rst/java/dispatchers.rst +++ b/akka-docs/rst/java/dispatchers.rst @@ -24,7 +24,7 @@ Looking up a Dispatcher Dispatchers implement the :class:`ExecutionContext` interface and can thus be used to run :class:`Future` invocations etc. -.. includecode:: code/docs/dispatcher/DispatcherDocTest.java#lookup +.. includecode:: code/jdocs/dispatcher/DispatcherDocTest.java#lookup Setting the dispatcher for an Actor ----------------------------------- @@ -52,7 +52,7 @@ For more options, see the default-dispatcher section of the :ref:`configuration` Then you create the actor as usual and define the dispatcher in the deployment configuration. -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#defining-dispatcher-in-config +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#defining-dispatcher-in-config .. includecode:: ../scala/code/docs/dispatcher/DispatcherDocSpec.scala#dispatcher-deployment-config @@ -60,7 +60,7 @@ An alternative to the deployment configuration is to define the dispatcher in co If you define the ``dispatcher`` in the deployment configuration then this value will be used instead of programmatically provided parameter. -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#defining-dispatcher-in-code +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#defining-dispatcher-in-code .. note:: The dispatcher you specify in ``withDispatcher`` and the ``dispatcher`` property in the deployment @@ -68,8 +68,8 @@ of programmatically provided parameter. So in this example it's a top-level section, but you could for instance put it as a sub-section, where you'd use periods to denote sub-sections, like this: ``"foo.bar.my-dispatcher"`` -.. _ForkJoinPool documentation: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html -.. _ThreadPoolExecutor documentation: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ThreadPoolExecutor.html +.. _ForkJoinPool documentation: https://docs.oracle.com/javase/8/jdocs/api/java/util/concurrent/ForkJoinPool.html +.. _ThreadPoolExecutor documentation: https://docs.oracle.com/javase/8/jdocs/api/java/util/concurrent/ThreadPoolExecutor.html Types of dispatchers -------------------- @@ -128,7 +128,7 @@ Configuring a dispatcher with fixed thread pool size, e.g. for actors that perfo And then using it: -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#defining-fixed-pool-size-dispatcher +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#defining-fixed-pool-size-dispatcher Another example that uses the thread pool based on the number of cores (e.g. for CPU bound tasks) @@ -140,7 +140,7 @@ Configuring a ``PinnedDispatcher``: And then using it: -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#defining-pinned-dispatcher +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#defining-pinned-dispatcher Note that ``thread-pool-executor`` configuration as per the above ``my-thread-pool-dispatcher`` example is NOT applicable. This is because every actor will have its own thread pool when using ``PinnedDispatcher``, diff --git a/akka-docs/rst/java/distributed-data.rst b/akka-docs/rst/java/distributed-data.rst index 322abfeab3..c611873fe1 100644 --- a/akka-docs/rst/java/distributed-data.rst +++ b/akka-docs/rst/java/distributed-data.rst @@ -47,7 +47,7 @@ Below is an example of an actor that schedules tick messages to itself and for e adds or removes elements from a ``ORSet`` (observed-remove set). It also subscribes to changes of this. -.. includecode:: code/docs/ddata/DataBot.java#data-bot +.. includecode:: code/jdocs/ddata/DataBot.java#data-bot .. _replicator_update_java: @@ -63,7 +63,7 @@ will then be replicated according to the given consistency level. The ``modify`` function is called by the ``Replicator`` actor and must therefore be a pure function that only uses the data parameter and stable fields from enclosing scope. It must -for example not access ``sender()`` reference of an enclosing actor. +for example not access the sender reference of an enclosing actor. ``Update`` is intended to only be sent from an actor running in same local ``ActorSystem`` as the ``Replicator``, because the ``modify`` function is typically not serializable. @@ -86,7 +86,7 @@ When you specify to write to ``n`` out of ``x`` nodes, the update will first rep Note that ``WriteMajority`` has a ``minCap`` parameter that is useful to specify to achieve better safety for small clusters. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#update +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#update As reply of the ``Update`` a ``Replicator.UpdateSuccess`` is sent to the sender of the ``Update`` if the value was successfully replicated according to the supplied consistency @@ -95,9 +95,9 @@ sent back. Note that a ``Replicator.UpdateTimeout`` reply does not mean that the or was rolled back. It may still have been replicated to some nodes, and will eventually be replicated to all nodes with the gossip protocol. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#update-response1 +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#update-response1 -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#update-response2 +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#update-response2 You will always see your own writes. For example if you send two ``Update`` messages changing the value of the same ``key``, the ``modify`` function of the second message will @@ -108,7 +108,7 @@ does not care about, but is included in the reply messages. This is a convenient way to pass contextual information (e.g. original sender) without having to use ``ask`` or maintain local correlation data structures. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#update-request-context +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#update-request-context .. _replicator_get_java: @@ -129,16 +129,16 @@ To retrieve the current value of a data you send ``Replicator.Get`` message to t Note that ``ReadMajority`` has a ``minCap`` parameter that is useful to specify to achieve better safety for small clusters. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#get +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#get As reply of the ``Get`` a ``Replicator.GetSuccess`` is sent to the sender of the ``Get`` if the value was successfully retrieved according to the supplied consistency level within the supplied timeout. Otherwise a ``Replicator.GetFailure`` is sent. If the key does not exist the reply will be ``Replicator.NotFound``. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#get-response1 +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#get-response1 -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#get-response2 +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#get-response2 You will always read your own writes. For example if you send a ``Update`` message followed by a ``Get`` of the same ``key`` the ``Get`` will retrieve the change that was @@ -150,7 +150,7 @@ In the ``Get`` message you can pass an optional request context in the same way ``Update`` message, described above. For example the original sender can be passed and replied to after receiving and transforming ``GetSuccess``. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#get-request-context +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#get-request-context Consistency ----------- @@ -193,11 +193,11 @@ the total size of the cluster. Here is an example of using ``writeMajority`` and ``readMajority``: -.. includecode:: ../../../akka-docs/rst/java/code/docs/ddata/ShoppingCart.java#read-write-majority +.. includecode:: ../../../akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java#read-write-majority -.. includecode:: ../../../akka-docs/rst/java/code/docs/ddata/ShoppingCart.java#get-cart +.. includecode:: ../../../akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java#get-cart -.. includecode:: ../../../akka-docs/rst/java/code/docs/ddata/ShoppingCart.java#add-item +.. includecode:: ../../../akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java#add-item In some rare cases, when performing an ``Update`` it is needed to first try to fetch latest data from other nodes. That can be done by first sending a ``Get`` with ``ReadMajority`` and then continue with @@ -209,7 +209,7 @@ performed (hence the name observed-removed set). The following example illustrates how to do that: -.. includecode:: ../../../akka-docs/rst/java/code/docs/ddata/ShoppingCart.java#remove-item +.. includecode:: ../../../akka-docs/rst/java/code/jdocs/ddata/ShoppingCart.java#remove-item .. warning:: @@ -233,7 +233,7 @@ immediately. The subscriber is automatically removed if the subscriber is terminated. A subscriber can also be deregistered with the ``Replicator.Unsubscribe`` message. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#subscribe +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#subscribe Delete ------ @@ -251,7 +251,7 @@ data entries because that reduces the replication overhead when new nodes join t Subsequent ``Delete``, ``Update`` and ``Get`` requests will be replied with ``Replicator.DataDeleted``. Subscribers will receive ``Replicator.DataDeleted``. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#delete +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#delete .. warning:: @@ -317,7 +317,7 @@ It is tracking the increments (P) separate from the decrements (N). Both P and N as two internal ``GCounter``. Merge is handled by merging the internal P and N counters. The value of the counter is the value of the P counter minus the value of the N counter. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#pncounter +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#pncounter ``GCounter`` and ``PNCounter`` have support for :ref:`delta_crdt_java` and don't need causal delivery of deltas. @@ -327,7 +327,7 @@ When the counters are placed in a ``PNCounterMap`` as opposed to placing them as values they are guaranteed to be replicated together as one unit, which is sometimes necessary for related data. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#pncountermap +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#pncountermap Sets ---- @@ -336,7 +336,7 @@ If you only need to add elements to a set and not remove elements the ``GSet`` ( the data type to use. The elements can be any type of values that can be serialized. Merge is simply the union of the two sets. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#gset +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#gset ``GSet`` has support for :ref:`delta_crdt_java` and it doesn't require causal delivery of deltas. @@ -349,7 +349,7 @@ The version for the node that added the element is also tracked for each element called "birth dot". The version vector and the dots are used by the ``merge`` function to track causality of the operations and resolve concurrent updates. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#orset +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#orset ``ORSet`` has support for :ref:`delta_crdt_java` and it requires causal delivery of deltas. @@ -378,7 +378,7 @@ such as the following specialized maps. ``LWWMap`` (last writer wins map) is a specialized ``ORMap`` with ``LWWRegister`` (last writer wins register) values. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#ormultimap +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#ormultimap When a data entry is changed the full state of that entry is replicated to other nodes, i.e. when you update a map the whole map is replicated. Therefore, instead of using one ``ORMap`` @@ -398,7 +398,7 @@ Flags and Registers ``Flag`` is a data type for a boolean value that is initialized to ``false`` and can be switched to ``true``. Thereafter it cannot be changed. ``true`` wins over ``false`` in merge. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#flag +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#flag ``LWWRegister`` (last writer wins register) can hold any (serializable) value. @@ -409,13 +409,13 @@ value is not important for concurrent updates occurring within the clock skew. Merge takes the register updated by the node with lowest address (``UniqueAddress`` is ordered) if the timestamps are exactly the same. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#lwwregister +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#lwwregister Instead of using timestamps based on ``System.currentTimeMillis()`` time it is possible to use a timestamp value based on something else, for example an increasing version number from a database record that is used for optimistic concurrency control. -.. includecode:: code/docs/ddata/DistributedDataDocTest.java#lwwregister-custom-clock +.. includecode:: code/jdocs/ddata/DistributedDataDocTest.java#lwwregister-custom-clock For first-write-wins semantics you can use the ``LWWRegister#reverseClock`` instead of the ``LWWRegister#defaultClock``. @@ -441,7 +441,7 @@ Here is s simple implementation of a custom ``TwoPhaseSet`` that is using two in to keep track of addition and removals. A ``TwoPhaseSet`` is a set where an element may be added and removed, but never added again thereafter. -.. includecode:: code/docs/ddata/japi/TwoPhaseSet.java#twophaseset +.. includecode:: code/jdocs/ddata/japi/TwoPhaseSet.java#twophaseset Data types should be immutable, i.e. "modifying" methods should return a new instance. @@ -466,7 +466,7 @@ This is a protobuf representation of the above ``TwoPhaseSet``: The serializer for the ``TwoPhaseSet``: -.. includecode:: code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer.java#serializer +.. includecode:: code/jdocs/ddata/japi/protobuf/TwoPhaseSetSerializer.java#serializer Note that the elements of the sets are sorted so the SHA-1 digests are the same for the same elements. @@ -478,7 +478,7 @@ You register the serializer in configuration: Using compression can sometimes be a good idea to reduce the data size. Gzip compression is provided by the ``akka.cluster.ddata.protobuf.SerializationSupport`` trait: -.. includecode:: code/docs/ddata/japi/protobuf/TwoPhaseSetSerializerWithCompression.java#compression +.. includecode:: code/jdocs/ddata/japi/protobuf/TwoPhaseSetSerializerWithCompression.java#compression The two embedded ``GSet`` can be serialized as illustrated above, but in general when composing new data types from the existing built in types it is better to make use of the existing @@ -491,7 +491,7 @@ by the ``SerializationSupport`` trait to serialize and deserialize the ``GSet`` works with any type that has a registered Akka serializer. This is how such an serializer would look like for the ``TwoPhaseSet``: -.. includecode:: code/docs/ddata/japi/protobuf/TwoPhaseSetSerializer2.java#serializer +.. includecode:: code/jdocs/ddata/japi/protobuf/TwoPhaseSetSerializer2.java#serializer .. _ddata_durable_java: diff --git a/akka-docs/rst/java/distributed-pub-sub.rst b/akka-docs/rst/java/distributed-pub-sub.rst index 4a19d872fc..f3ad71d5ba 100644 --- a/akka-docs/rst/java/distributed-pub-sub.rst +++ b/akka-docs/rst/java/distributed-pub-sub.rst @@ -111,8 +111,8 @@ cluster aware router where the routees dynamically can register themselves. The message will be delivered to one recipient with a matching path, if any such exists in the registry. If several entries match the path because it has been registered -on several nodes the message will be sent via the supplied ``RoutingLogic`` (default random) -to one destination. The sender() of the message can specify that local affinity is preferred, +on several nodes the message will be sent via the supplied ``RoutingLogic`` (default random) +to one 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 mediator actor, if any such exists, otherwise route to any other matching entry. diff --git a/akka-docs/rst/java/event-bus.rst b/akka-docs/rst/java/event-bus.rst index 30c2751f6a..c7a8c104f9 100644 --- a/akka-docs/rst/java/event-bus.rst +++ b/akka-docs/rst/java/event-bus.rst @@ -9,7 +9,7 @@ Originally conceived as a way to send messages to groups of actors, the :class:`EventBus` has been generalized into a set of abstract base classes implementing a simple interface: -.. includecode:: code/docs/event/EventBusDocTest.java#event-bus-api +.. includecode:: code/jdocs/event/EventBusDocTest.java#event-bus-api .. note:: @@ -51,11 +51,11 @@ compare subscribers and how exactly to classify. The necessary methods to be implemented are illustrated with the following example: -.. includecode:: code/docs/event/EventBusDocTest.java#lookup-bus +.. includecode:: code/jdocs/event/EventBusDocTest.java#lookup-bus A test for this implementation may look like this: -.. includecode:: code/docs/event/EventBusDocTest.java#lookup-bus-test +.. includecode:: code/jdocs/event/EventBusDocTest.java#lookup-bus-test This classifier is efficient in case no subscribers exist for a particular event. @@ -72,11 +72,11 @@ classifier hierarchy. The necessary methods to be implemented are illustrated with the following example: -.. includecode:: code/docs/event/EventBusDocTest.java#subchannel-bus +.. includecode:: code/jdocs/event/EventBusDocTest.java#subchannel-bus A test for this implementation may look like this: -.. includecode:: code/docs/event/EventBusDocTest.java#subchannel-bus-test +.. includecode:: code/jdocs/event/EventBusDocTest.java#subchannel-bus-test This classifier is also efficient in case no subscribers are found for an event, but it uses conventional locking to synchronize an internal classifier @@ -95,11 +95,11 @@ stations by geographical reachability (for old-school radio-wave transmission). The necessary methods to be implemented are illustrated with the following example: -.. includecode:: code/docs/event/EventBusDocTest.java#scanning-bus +.. includecode:: code/jdocs/event/EventBusDocTest.java#scanning-bus A test for this implementation may look like this: -.. includecode:: code/docs/event/EventBusDocTest.java#scanning-bus-test +.. includecode:: code/jdocs/event/EventBusDocTest.java#scanning-bus-test This classifier takes always a time which is proportional to the number of subscriptions, independent of how many actually match. @@ -120,11 +120,11 @@ takes care of unsubscribing terminated actors automatically. The necessary methods to be implemented are illustrated with the following example: -.. includecode:: code/docs/event/EventBusDocTest.java#actor-bus +.. includecode:: code/jdocs/event/EventBusDocTest.java#actor-bus A test for this implementation may look like this: -.. includecode:: code/docs/event/EventBusDocTest.java#actor-bus-test +.. includecode:: code/jdocs/event/EventBusDocTest.java#actor-bus-test This classifier is still is generic in the event type, and it is efficient for all use cases. @@ -141,18 +141,18 @@ Classification`_ which enables registering to related sets of channels (as is used for :class:`RemotingLifecycleEvent`). The following example demonstrates how a simple subscription works. Given a simple actor: -.. includecode:: code/docs/event/LoggingDocTest.java#imports-deadletter -.. includecode:: code/docs/event/LoggingDocTest.java#deadletter-actor +.. includecode:: code/jdocs/event/LoggingDocTest.java#imports-deadletter +.. includecode:: code/jdocs/event/LoggingDocTest.java#deadletter-actor it can be subscribed like this: -.. includecode:: code/docs/event/LoggingDocTest.java#deadletters +.. includecode:: code/jdocs/event/LoggingDocTest.java#deadletters It is also worth pointing out that thanks to the way the subchannel classification is implemented in the event stream, it is possible to subscribe to a group of events, by subscribing to their common superclass as demonstrated in the following example: -.. includecode:: code/docs/event/LoggingDocTest.java#superclass-subscription-eventstream +.. includecode:: code/jdocs/event/LoggingDocTest.java#superclass-subscription-eventstream Similarly to `Actor Classification`_, :class:`EventStream` will automatically remove subscribers when they terminate. @@ -200,11 +200,11 @@ and since they are nothing to worry about, they are suppressed from the default However, in case you find yourself in need of debugging these kinds of low level suppressed dead letters, it's still possible to subscribe to them explicitly: -.. includecode:: code/docs/event/LoggingDocTest.java#suppressed-deadletters +.. includecode:: code/jdocs/event/LoggingDocTest.java#suppressed-deadletters or all dead letters (including the suppressed ones): -.. includecode:: code/docs/event/LoggingDocTest.java#all-deadletters +.. includecode:: code/jdocs/event/LoggingDocTest.java#all-deadletters Other Uses ---------- diff --git a/akka-docs/rst/java/extending-akka.rst b/akka-docs/rst/java/extending-akka.rst index 5d3a3b7170..ca98d40b08 100644 --- a/akka-docs/rst/java/extending-akka.rst +++ b/akka-docs/rst/java/extending-akka.rst @@ -25,28 +25,28 @@ So let's create a sample extension that just lets us count the number of times s First, we define what our ``Extension`` should do: -.. includecode:: code/docs/extension/ExtensionDocTest.java +.. includecode:: code/jdocs/extension/ExtensionDocTest.java :include: imports -.. includecode:: code/docs/extension/ExtensionDocTest.java +.. includecode:: code/jdocs/extension/ExtensionDocTest.java :include: extension Then we need to create an ``ExtensionId`` for our extension so we can grab a hold of it. -.. includecode:: code/docs/extension/ExtensionDocTest.java +.. includecode:: code/jdocs/extension/ExtensionDocTest.java :include: imports -.. includecode:: code/docs/extension/ExtensionDocTest.java +.. includecode:: code/jdocs/extension/ExtensionDocTest.java :include: extensionid Wicked! Now all we need to do is to actually use it: -.. includecode:: code/docs/extension/ExtensionDocTest.java +.. includecode:: code/jdocs/extension/ExtensionDocTest.java :include: extension-usage Or from inside of an Akka Actor: -.. includecode:: code/docs/extension/ExtensionDocTest.java +.. includecode:: code/jdocs/extension/ExtensionDocTest.java :include: extension-usage-actor That's all there is to it! @@ -83,15 +83,15 @@ Sample configuration: The ``Extension``: -.. includecode:: code/docs/extension/SettingsExtensionDocTest.java +.. includecode:: code/jdocs/extension/SettingsExtensionDocTest.java :include: imports -.. includecode:: code/docs/extension/SettingsExtensionDocTest.java +.. includecode:: code/jdocs/extension/SettingsExtensionDocTest.java :include: extension,extensionid Use it: -.. includecode:: code/docs/extension/SettingsExtensionDocTest.java +.. includecode:: code/jdocs/extension/SettingsExtensionDocTest.java :include: extension-usage-actor Library extensions diff --git a/akka-docs/rst/java/fault-tolerance-sample.rst b/akka-docs/rst/java/fault-tolerance-sample.rst index 91d0b5f4cf..c114ce06ce 100644 --- a/akka-docs/rst/java/fault-tolerance-sample.rst +++ b/akka-docs/rst/java/fault-tolerance-sample.rst @@ -49,5 +49,5 @@ Step Description Full Source Code of the Fault Tolerance Sample ------------------------------------------------------ -.. includecode:: code/docs/actorlambda/japi/FaultHandlingDocSample.java#all +.. includecode:: code/jdocs/actor/japi/FaultHandlingDocSample.java#all diff --git a/akka-docs/rst/java/fault-tolerance.rst b/akka-docs/rst/java/fault-tolerance.rst index 47cfe6467c..5d996be115 100644 --- a/akka-docs/rst/java/fault-tolerance.rst +++ b/akka-docs/rst/java/fault-tolerance.rst @@ -32,7 +32,7 @@ in more depth. For the sake of demonstration let us consider the following strategy: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: strategy I have chosen a few well-known exception types in order to demonstrate the @@ -110,49 +110,49 @@ Test Application The following section shows the effects of the different directives in practice, where a test setup is needed. First off, we need a suitable supervisor: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: supervisor This supervisor will be used to create a child, with which we can experiment: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: child The test is easier by using the utilities described in :ref:`akka-testkit`, where ``TestProbe`` provides an actor ref useful for receiving and inspecting replies. -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: testkit Let us create actors: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: create The first test shall demonstrate the ``Resume`` directive, so we try it out by setting some non-initial state in the actor and have it fail: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: resume As you can see the value 42 survives the fault handling directive. Now, if we change the failure to a more serious ``NullPointerException``, that will no longer be the case: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: restart And finally in case of the fatal ``IllegalArgumentException`` the child will be terminated by the supervisor: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: stop Up to now the supervisor was completely unaffected by the child’s failure, because the directives set did handle it. In case of an ``Exception``, this is not true anymore and the supervisor escalates the failure. -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: escalate-kill The supervisor itself is supervised by the top-level actor provided by the @@ -165,12 +165,12 @@ child not to survive this failure. In case this is not desired (which depends on the use case), we need to use a different supervisor which overrides this behavior. -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: supervisor2 With this parent, the child survives the escalated restart, as demonstrated in the last test: -.. includecode:: code/docs/actorlambda/FaultHandlingTest.java +.. includecode:: code/jdocs/actor/FaultHandlingTest.java :include: escalate-restart diff --git a/akka-docs/rst/java/fsm.rst b/akka-docs/rst/java/fsm.rst index 8c69ffba4b..80da914c36 100644 --- a/akka-docs/rst/java/fsm.rst +++ b/akka-docs/rst/java/fsm.rst @@ -31,11 +31,11 @@ send them on after the burst ended or a flush request is received. First, consider all of the below to use these import statements: -.. includecode:: code/docs/actorlambda/fsm/Buncher.java#simple-imports +.. includecode:: code/jdocs/actor/fsm/Buncher.java#simple-imports The contract of our “Buncher” actor is that it accepts or produces the following messages: -.. includecode:: code/docs/actorlambda/fsm/Events.java +.. includecode:: code/jdocs/actor/fsm/Events.java :include: simple-events :exclude: boilerplate @@ -46,7 +46,7 @@ The contract of our “Buncher” actor is that it accepts or produces the follo The actor can be in two states: no message queued (aka ``Idle``) or some message queued (aka ``Active``). The states and the state data is defined like this: -.. includecode:: code/docs/actorlambda/fsm/Buncher.java +.. includecode:: code/jdocs/actor/fsm/Buncher.java :include: simple-state :exclude: boilerplate @@ -57,7 +57,7 @@ reference to send the batches to and the actual queue of messages. Now let’s take a look at the skeleton for our FSM actor: -.. includecode:: code/docs/actorlambda/fsm/Buncher.java +.. includecode:: code/jdocs/actor/fsm/Buncher.java :include: simple-fsm :exclude: transition-elided,unhandled-elided @@ -86,7 +86,7 @@ shall work identically in both states, we make use of the fact that any event which is not handled by the ``when()`` block is passed to the ``whenUnhandled()`` block: -.. includecode:: code/docs/actorlambda/fsm/Buncher.java#unhandled-elided +.. includecode:: code/jdocs/actor/fsm/Buncher.java#unhandled-elided The first case handled here is adding ``Queue()`` requests to the internal queue and going to the ``Active`` state (this does the obvious thing of staying @@ -100,7 +100,7 @@ target, for which we use the ``onTransition`` mechanism: you can declare multiple such blocks and all of them will be tried for matching behavior in case a state transition occurs (i.e. only when the state actually changes). -.. includecode:: code/docs/actorlambda/fsm/Buncher.java#transition-elided +.. includecode:: code/jdocs/actor/fsm/Buncher.java#transition-elided The transition callback is a partial function which takes as input a pair of states—the current and the next state. During the state change, the old state @@ -110,7 +110,7 @@ available as ``nextStateData``. To verify that this buncher actually works, it is quite easy to write a test using the :ref:`akka-testkit`, here using JUnit as an example: -.. includecode:: code/docs/actorlambda/fsm/BuncherTest.java +.. includecode:: code/jdocs/actor/fsm/BuncherTest.java :include: test-code Reference @@ -122,7 +122,7 @@ The AbstractFSM Class The :class:`AbstractFSM` abstract class is the base class used to implement an FSM. It implements Actor since an Actor is created to drive the FSM. -.. includecode:: code/docs/actorlambda/fsm/Buncher.java +.. includecode:: code/jdocs/actor/fsm/Buncher.java :include: simple-fsm :exclude: fsm-body @@ -174,7 +174,7 @@ The :meth:`stateFunction` argument is a :class:`PartialFunction[Event, State]`, which is conveniently given using the state function builder syntax as demonstrated below: -.. includecode:: code/docs/actorlambda/fsm/Buncher.java +.. includecode:: code/jdocs/actor/fsm/Buncher.java :include: when-syntax .. warning:: @@ -186,7 +186,7 @@ It is recommended practice to declare the states as an enum and then verify that ``when`` clause for each of the states. If you want to leave the handling of a state “unhandled” (more below), it still needs to be declared like this: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java#NullFunction +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java#NullFunction Defining the Initial State -------------------------- @@ -206,7 +206,7 @@ If a state doesn't handle a received event a warning is logged. If you want to do something else in this case you can specify that with :func:`whenUnhandled(stateFunction)`: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: unhandled-syntax Within this handler the state of the FSM may be queried using the @@ -250,7 +250,7 @@ of the modifiers described in the following: All modifiers can be chained to achieve a nice and concise description: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: modifier-syntax The parentheses are not actually needed in all cases, but they visually @@ -287,14 +287,14 @@ The handler is a partial function which takes a pair of states as input; no resulting state is needed as it is not possible to modify the transition in progress. -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: transition-syntax It is also possible to pass a function object accepting two states to :func:`onTransition`, in case your transition handling logic is implemented as a method: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: alt-transition-syntax The handlers registered with this method are stacked, so you can intersperse @@ -370,14 +370,14 @@ state data which is available during termination handling. the same way as a state transition (but note that the ``return`` statement may not be used within a :meth:`when` block). -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: stop-syntax You can use :func:`onTermination(handler)` to specify custom code that is executed when the FSM is stopped. The handler is a partial function which takes a :class:`StopEvent(reason, stateName, stateData)` as argument: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: termination-syntax As for the :func:`whenUnhandled` case, this handler is not stacked, so each @@ -411,7 +411,7 @@ Event Tracing The setting ``akka.actor.debug.fsm`` in :ref:`configuration` enables logging of an event trace by :class:`LoggingFSM` instances: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: logging-fsm :exclude: body-elided @@ -432,7 +432,7 @@ The :class:`AbstractLoggingFSM` class adds one more feature to the FSM: a rollin log which may be used during debugging (for tracing how the FSM entered a certain failure state) or for other creative uses: -.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java +.. includecode:: code/jdocs/actor/fsm/FSMDocTest.java :include: logging-fsm The :meth:`logDepth` defaults to zero, which turns off the event log. diff --git a/akka-docs/rst/java/futures.rst b/akka-docs/rst/java/futures.rst index 80d84ec2c7..f9105480ea 100644 --- a/akka-docs/rst/java/futures.rst +++ b/akka-docs/rst/java/futures.rst @@ -21,10 +21,10 @@ which is very similar to a ``java.util.concurrent.Executor``. if you have an ``A it will use its default dispatcher as the ``ExecutionContext``, or you can use the factory methods provided by the ``ExecutionContexts`` class to wrap ``Executors`` and ``ExecutorServices``, or even create your own. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports1,imports7 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: diy-execution-context Use with Actors @@ -36,10 +36,10 @@ which only works if the original sender was an ``AbstractActor``) and the second Using the ``ActorRef``\'s ``ask`` method to send a message will return a ``Future``. To wait for and retrieve the actual result the simplest method is: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports1 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: ask-blocking This will cause the current thread to block and wait for the ``AbstractActor`` to 'complete' the ``Future`` with it's reply. @@ -57,7 +57,7 @@ That is why the cast to ``String`` is used in the above sample. To send the result of a ``Future`` to an ``Actor``, you can use the ``pipe`` construct: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: pipe-to Use Directly @@ -67,10 +67,10 @@ A common use case within Akka is to have some computation performed concurrently the extra utility of an ``AbstractActor``. If you find yourself creating a pool of ``AbstractActor``\s for the sole reason of performing a calculation in parallel, there is an easier (and faster) way: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports2 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: future-eval In the above code the block passed to ``future`` will be executed by the default ``Dispatcher``, @@ -80,21 +80,21 @@ and we also avoid the overhead of managing an ``AbstractActor``. You can also create already completed Futures using the ``Futures`` class, which can be either successes: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: successful Or failures: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: failed It is also possible to create an empty ``Promise``, to be filled later, and obtain the corresponding ``Future``: -.. includecode:: code/docs/future/FutureDocTest.java#promise +.. includecode:: code/jdocs/future/FutureDocTest.java#promise For these examples ``PrintResult`` is defined as follows: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: print-result Functional Futures @@ -110,10 +110,10 @@ The first method for working with ``Future`` functionally is ``map``. This metho some operation on the result of the ``Future``, and returning a new result. The return value of the ``map`` method is another ``Future`` that will contain the new result: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports2 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: map In this example we are joining two strings together within a ``Future``. Instead of waiting for f1 to complete, @@ -132,10 +132,10 @@ Composing Futures It is very often desirable to be able to combine different Futures with each other, below are some examples on how that can be done in a non-blocking fashion. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports3 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: sequence To better explain what happened in the example, ``Future.sequence`` is taking the ``Iterable>`` @@ -145,10 +145,10 @@ and we aggregate the sum of the ``Iterable``. The ``traverse`` method is similar to ``sequence``, but it takes a sequence of ``A`` and applies a function from ``A`` to ``Future`` and returns a ``Future>``, enabling parallel ``map`` over the sequence, if you use ``Futures.future`` to create the ``Future``. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports4 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: traverse It's as simple as that! @@ -159,10 +159,10 @@ and the type of the futures and returns something with the same type as the star and then applies the function to all elements in the sequence of futures, non-blockingly, the execution will be started when the last of the Futures is completed. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports5 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: fold That's all it takes! @@ -172,10 +172,10 @@ If the sequence passed to ``fold`` is empty, it will return the start-value, in In some cases you don't have a start-value and you're able to use the value of the first completing ``Future`` in the sequence as the start-value, you can use ``reduce``, it works like this: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports6 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: reduce Same as with ``fold``, the execution will be started when the last of the Futures is completed, you can also parallelize @@ -189,13 +189,13 @@ Callbacks Sometimes you just want to listen to a ``Future`` being completed, and react to that not by creating a new Future, but by side-effecting. For this Scala supports ``onComplete``, ``onSuccess`` and ``onFailure``, of which the last two are specializations of the first. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: onSuccess -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: onFailure -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: onComplete Ordering @@ -207,7 +207,7 @@ But there's a solution! And it's name is ``andThen``, and it creates a new ``Fut the specified callback, a ``Future`` that will have the same result as the ``Future`` it's called on, which allows for ordering like in the following sample: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: and-then Auxiliary methods @@ -216,13 +216,13 @@ Auxiliary methods ``Future`` ``fallbackTo`` combines 2 Futures into a new ``Future``, and will hold the successful value of the second ``Future`` if the first ``Future`` fails. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: fallback-to You can also combine two Futures into a new ``Future`` that will hold a tuple of the two Futures successful results, using the ``zip`` operation. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: zip Exceptions @@ -236,7 +236,7 @@ calling ``Await.result`` will cause it to be thrown again so it can be handled p It is also possible to handle an ``Exception`` by returning a different result. This is done with the ``recover`` method. For example: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: recover In this example, if the actor replied with a ``akka.actor.Status.Failure`` containing the ``ArithmeticException``, @@ -247,7 +247,7 @@ it will behave as if we hadn't used the ``recover`` method. You can also use the ``recoverWith`` method, which has the same relationship to ``recover`` as ``flatMap`` has to ``map``, and is use like this: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: try-recover After @@ -255,10 +255,10 @@ After ``akka.pattern.Patterns.after`` makes it easy to complete a ``Future`` with a value or exception after a timeout. -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: imports8 -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: after Java 8, CompletionStage and CompletableFuture @@ -290,7 +290,7 @@ Non-async methods When non-async methods are applied on a not yet completed ``CompletionStage``, they are completed by the thread which completes initial ``CompletionStage``: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: apply-completion-thread In this example Scala ``Future`` is converted to ``CompletionStage`` just like Akka does. @@ -307,7 +307,7 @@ default ``thenApply`` breaks the chain and executes on ``ForkJoinPool.commonPool In the next example ``thenApply`` methods are executed on an already completed ``Future``/``CompletionStage``: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: apply-main-thread First ``thenApply`` is still executed on ``ForkJoinPool.commonPool()`` (because it is actually ``thenApplyAsync`` @@ -322,13 +322,13 @@ Async methods As mentioned above, default *async* methods are always executed on ``ForkJoinPool.commonPool()``: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: apply-async-default ``CompletionStage`` also has *async* methods which take ``Executor`` as a second parameter, just like ``Future``: -.. includecode:: code/docs/future/FutureDocTest.java +.. includecode:: code/jdocs/future/FutureDocTest.java :include: apply-async-executor This example is behaving like ``Future``: every stage is executed on an explicitly specified ``Executor``. @@ -339,9 +339,9 @@ This example is behaving like ``Future``: every stage is executed on an explicit See also: -- `CompletionStage `_ +- `CompletionStage `_ -- `CompletableFuture `_ +- `CompletableFuture `_ - `scala-java8-compat `_ diff --git a/akka-docs/rst/java/howto.rst b/akka-docs/rst/java/howto.rst index e5437cb5a1..1a0eb93870 100644 --- a/akka-docs/rst/java/howto.rst +++ b/akka-docs/rst/java/howto.rst @@ -33,7 +33,7 @@ message sends to the same actor. off based on when you restart the scheduled message sends relative to the time that the last message was sent, and how long the initial delay is. Worst case scenario is ``interval`` plus ``initialDelay``. -.. includecode:: code/docs/pattern/SchedulerPatternTest.java#schedule-constructor +.. includecode:: code/jdocs/pattern/SchedulerPatternTest.java#schedule-constructor The second variant sets up an initial one shot message send in the ``preStart`` method of the actor, and the then the actor when it receives this message sets up a new one shot @@ -45,7 +45,7 @@ and schedule the initial message send again. With this approach we won't fill up the mailbox with tick messages if the actor is under pressure, but only schedule a new tick message when we have seen the previous one. -.. includecode:: code/docs/pattern/SchedulerPatternTest.java#schedule-receive +.. includecode:: code/jdocs/pattern/SchedulerPatternTest.java#schedule-receive Single-Use Actor Trees with High-Level Error Reporting ====================================================== @@ -70,7 +70,7 @@ Finally the promise returned by Patterns.ask() is fulfilled as a failure, includ Let's have a look at the example code: -.. includecode:: code/docs/pattern/SupervisedAsk.java +.. includecode:: code/jdocs/pattern/SupervisedAsk.java In the askOf method the SupervisorCreator is sent the user message. The SupervisorCreator creates a SupervisorActor and forwards the message. @@ -83,5 +83,5 @@ Afterwards the actor hierarchy is stopped. Finally we are able to execute an actor and receive the results or exceptions. -.. includecode:: code/docs/pattern/SupervisedAskSpec.java +.. includecode:: code/jdocs/pattern/SupervisedAskSpec.java diff --git a/akka-docs/rst/java/http/index.rst b/akka-docs/rst/java/http/index.rst index b8934cf2a9..6da7dc95a1 100644 --- a/akka-docs/rst/java/http/index.rst +++ b/akka-docs/rst/java/http/index.rst @@ -2,4 +2,4 @@ Akka HTTP Documentation (Java) moved! ===================================== Akka HTTP has been released as independent stable module (from Akka HTTP 10.x onwards). -The documentation is available under `doc.akka.io/akka-http/current/ `_. +The documentation is available under `doc.akka.io/akka-http/current/ `_. diff --git a/akka-docs/rst/java/io-tcp.rst b/akka-docs/rst/java/io-tcp.rst index 1ad4b7b51d..17e3c856ec 100644 --- a/akka-docs/rst/java/io-tcp.rst +++ b/akka-docs/rst/java/io-tcp.rst @@ -5,12 +5,12 @@ Using TCP The code snippets through-out this section assume the following imports: -.. includecode:: code/docs/io/japi/IODocTest.java#imports +.. includecode:: code/jdocs/io/japi/IODocTest.java#imports All of the Akka I/O APIs are accessed through manager objects. When using an I/O API, the first step is to acquire a reference to the appropriate manager. The code below shows how to acquire a reference to the ``Tcp`` manager. -.. includecode:: code/docs/io/japi/EchoManager.java#manager +.. includecode:: code/jdocs/io/japi/EchoManager.java#manager The manager is an actor that handles the underlying low level I/O resources (selectors, channels) and instantiates workers for specific tasks, such as listening to incoming connections. @@ -18,7 +18,7 @@ workers for specific tasks, such as listening to incoming connections. Connecting ---------- -.. includecode:: code/docs/io/japi/IODocTest.java#client +.. includecode:: code/jdocs/io/japi/IODocTest.java#client The first step of connecting to a remote address is sending a :class:`Connect` message to the TCP manager; in addition to the simplest form shown above there @@ -59,7 +59,7 @@ fine-grained connection close events, see `Closing Connections`_ below. Accepting connections --------------------- -.. includecode:: code/docs/io/japi/IODocTest.java#server +.. includecode:: code/jdocs/io/japi/IODocTest.java#server To create a TCP server and listen for inbound connections, a :class:`Bind` command has to be sent to the TCP manager. This will instruct the TCP manager @@ -78,7 +78,7 @@ handler when sending the :class:`Register` message. Writes can be sent from any actor in the system to the connection actor (i.e. the actor which sent the :class:`Connected` message). The simplistic handler is defined as: -.. includecode:: code/docs/io/japi/IODocTest.java#simplistic-handler +.. includecode:: code/jdocs/io/japi/IODocTest.java#simplistic-handler For a more complete sample which also takes into account the possibility of failures when sending please see `Throttling Reads and Writes`_ below. @@ -189,7 +189,7 @@ For back-pressuring writes there are three modes of operation These write models (with the exception of the second which is rather specialised) are demonstrated in complete examples below. The full and contiguous source is -available `on GitHub <@github@/akka-docs/rst/java/code/docs/io/japi>`_. +available `on GitHub <@github@/akka-docs/rst/java/code/jdocs/io/japi>`_. For back-pressuring reads there are two modes of operation @@ -220,11 +220,11 @@ this allows the example :class:`EchoHandler` to write all outstanding data back to the client before fully closing the connection. This is enabled using a flag upon connection activation (observe the :class:`Register` message): -.. includecode:: code/docs/io/japi/EchoManager.java#echo-manager +.. includecode:: code/jdocs/io/japi/EchoManager.java#echo-manager With this preparation let us dive into the handler itself: -.. includecode:: code/docs/io/japi/SimpleEchoHandler.java#simple-echo-handler +.. includecode:: code/jdocs/io/japi/SimpleEchoHandler.java#simple-echo-handler :exclude: storage-omitted The principle is simple: when having written a chunk always wait for the @@ -232,7 +232,7 @@ The principle is simple: when having written a chunk always wait for the behavior such that new incoming data are buffered. The helper functions used are a bit lengthy but not complicated: -.. includecode:: code/docs/io/japi/SimpleEchoHandler.java#simple-helpers +.. includecode:: code/jdocs/io/japi/SimpleEchoHandler.java#simple-helpers The most interesting part is probably the last: an ``Ack`` removes the oldest data chunk from the buffer, and if that was the last chunk then we either close @@ -254,7 +254,7 @@ how end-to-end back-pressure is realized across a TCP connection. NACK-Based Write Back-Pressure with Suspending ---------------------------------------------- -.. includecode:: code/docs/io/japi/EchoHandler.java#echo-handler +.. includecode:: code/jdocs/io/japi/EchoHandler.java#echo-handler :exclude: buffering,closing,storage-omitted The principle here is to keep writing until a :class:`CommandFailed` is @@ -262,7 +262,7 @@ received, using acknowledgements only to prune the resend buffer. When a such a failure was received, transition into a different state for handling and handle resending of all queued data: -.. includecode:: code/docs/io/japi/EchoHandler.java#buffering +.. includecode:: code/jdocs/io/japi/EchoHandler.java#buffering It should be noted that all writes which are currently buffered have also been sent to the connection actor upon entering this state, which means that the @@ -275,7 +275,7 @@ is exploited by the :class:`EchoHandler` to switch to an ACK-based approach for the first ten writes after a failure before resuming the optimistic write-through behavior. -.. includecode:: code/docs/io/japi/EchoHandler.java#closing +.. includecode:: code/jdocs/io/japi/EchoHandler.java#closing Closing the connection while still sending all data is a bit more involved than in the ACK-based approach: the idea is to always send all outstanding messages @@ -284,7 +284,7 @@ behavior to await the :class:`WritingResumed` event and start over. The helper functions are very similar to the ACK-based case: -.. includecode:: code/docs/io/japi/EchoHandler.java#helpers +.. includecode:: code/jdocs/io/japi/EchoHandler.java#helpers Read Back-Pressure with Pull Mode --------------------------------- @@ -297,7 +297,7 @@ since the rate of writing might be slower than the rate of the arrival of new da With the Pull mode this buffer can be completely eliminated as the following snippet demonstrates: -.. includecode:: code/docs/io/JavaReadBackPressure.java#pull-reading-echo +.. includecode:: code/jdocs/io/JavaReadBackPressure.java#pull-reading-echo The idea here is that reading is not resumed until the previous write has been completely acknowledged by the connection actor. Every pull mode connection @@ -310,7 +310,7 @@ a buffer. To enable pull reading on an outbound connection the ``pullMode`` parameter of the :class:`Connect` should be set to ``true``: -.. includecode:: code/docs/io/JavaReadBackPressure.java#pull-mode-connect +.. includecode:: code/jdocs/io/JavaReadBackPressure.java#pull-mode-connect Pull Mode Reading for Inbound Connections ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -319,7 +319,7 @@ The previous section demonstrated how to enable pull reading mode for outbound connections but it is possible to create a listener actor with this mode of reading by setting the ``pullMode`` parameter of the :class:`Bind` command to ``true``: -.. includecode:: code/docs/io/JavaReadBackPressure.java#pull-mode-bind +.. includecode:: code/jdocs/io/JavaReadBackPressure.java#pull-mode-bind One of the effects of this setting is that all connections accepted by this listener actor will use pull mode reading. @@ -332,7 +332,7 @@ it a :class:`ResumeAccepting` message. Listener actors with pull mode start suspended so to start accepting connections a :class:`ResumeAccepting` command has to be sent to the listener actor after binding was successful: -.. includecode:: code/docs/io/JavaReadBackPressure.java#pull-accepting +.. includecode:: code/jdocs/io/JavaReadBackPressure.java#pull-accepting As shown in the example after handling an incoming connection we need to resume accepting again. The :class:`ResumeAccepting` message accepts a ``batchSize`` parameter that specifies how diff --git a/akka-docs/rst/java/io-udp.rst b/akka-docs/rst/java/io-udp.rst index f186c4d26f..702383e769 100644 --- a/akka-docs/rst/java/io-udp.rst +++ b/akka-docs/rst/java/io-udp.rst @@ -23,7 +23,7 @@ Unconnected UDP Simple Send ^^^^^^^^^^^ -.. includecode:: code/docs/io/UdpDocTest.java#sender +.. includecode:: code/jdocs/io/UdpDocTest.java#sender The simplest form of UDP usage is to just send datagrams without the need of getting a reply. To this end a “simple sender” facility is provided as @@ -43,7 +43,7 @@ destinations; in this example it will just send any UTF-8 encoded Bind (and Send) ^^^^^^^^^^^^^^^ -.. includecode:: code/docs/io/UdpDocTest.java#listener +.. includecode:: code/jdocs/io/UdpDocTest.java#listener If you want to implement a UDP server which listens on a socket for incoming datagrams then you need to use the :meth:`bind` command as shown above. The @@ -69,7 +69,7 @@ bind-and-send service we saw earlier, but the main difference is that a connection is only able to send to the ``remoteAddress`` it was connected to, and will receive datagrams only from that address. -.. includecode:: code/docs/io/UdpDocTest.java#connected +.. includecode:: code/jdocs/io/UdpDocTest.java#connected Consequently the example shown here looks quite similar to the previous one, the biggest difference is the absence of remote address information in @@ -95,12 +95,12 @@ To select a Protocol Family you must extend ``akka.io.Inet.DatagramChannelCreato class which implements ``akka.io.Inet.SocketOption``. Provide custom logic for opening a datagram channel by overriding :meth:`create` method. -.. includecode:: code/docs/io/JavaUdpMulticast.java#inet6-protocol-family +.. includecode:: code/jdocs/io/JavaUdpMulticast.java#inet6-protocol-family Another socket option will be needed to join a multicast group. -.. includecode:: code/docs/io/JavaUdpMulticast.java#multicast-group +.. includecode:: code/jdocs/io/JavaUdpMulticast.java#multicast-group Socket options must be provided to :meth:`UdpMessage.bind` command. -.. includecode:: code/docs/io/JavaUdpMulticast.java#bind +.. includecode:: code/jdocs/io/JavaUdpMulticast.java#bind diff --git a/akka-docs/rst/java/io.rst b/akka-docs/rst/java/io.rst index 61ab3c3c28..1c75fc0f2a 100644 --- a/akka-docs/rst/java/io.rst +++ b/akka-docs/rst/java/io.rst @@ -26,7 +26,7 @@ as an entry point for the API. I/O is broken into several drivers. The manager f is accessible by querying an ``ActorSystem``. For example the following code looks up the TCP manager and returns its ``ActorRef``: -.. includecode:: code/docs/io/japi/EchoManager.java#manager +.. includecode:: code/jdocs/io/japi/EchoManager.java#manager The manager receives I/O command messages and instantiates worker actors in response. The worker actors present themselves to the API user in the reply to the command that was sent. For example after a ``Connect`` command sent to diff --git a/akka-docs/rst/java/logging.rst b/akka-docs/rst/java/logging.rst index 4720bea797..a153db30bc 100644 --- a/akka-docs/rst/java/logging.rst +++ b/akka-docs/rst/java/logging.rst @@ -17,10 +17,10 @@ How to Log Create a ``LoggingAdapter`` and use the ``error``, ``warning``, ``info``, or ``debug`` methods, as illustrated in this example: -.. includecode:: code/docs/event/LoggingDocTest.java +.. includecode:: code/jdocs/event/LoggingDocTest.java :include: imports -.. includecode:: code/docs/event/LoggingDocTest.java +.. includecode:: code/jdocs/event/LoggingDocTest.java :include: my-actor The first parameter to ``Logging.getLogger`` could also be any @@ -42,7 +42,7 @@ placeholders results in a warning being appended to the log statement (i.e. on the same line with the same severity). You may pass a Java array as the only substitution argument to have its elements be treated individually: -.. includecode:: code/docs/event/LoggingDocTest.java#array +.. includecode:: code/jdocs/event/LoggingDocTest.java#array The Java :class:`Class` of the log source is also included in the generated :class:`LogEvent`. In case of a simple string this is replaced with a “marker” @@ -255,10 +255,10 @@ logger available in the 'akka-slf4j' module. Example of creating a listener: -.. includecode:: code/docs/event/LoggingDocTest.java +.. includecode:: code/jdocs/event/LoggingDocTest.java :include: imports,imports-listener -.. includecode:: code/docs/event/LoggingDocTest.java +.. includecode:: code/jdocs/event/LoggingDocTest.java :include: my-event-listener Logging to stdout during startup and shutdown @@ -414,10 +414,10 @@ This way, the values will be put in the SLF4J MDC right before appending the log otherwise, the next message will log with same MDC values, if it is not set to a new map. Use ``log.clearMDC()``. -.. includecode:: code/docs/event/LoggingDocTest.java +.. includecode:: code/jdocs/event/LoggingDocTest.java :include: imports-mdc -.. includecode:: code/docs/event/LoggingDocTest.java +.. includecode:: code/jdocs/event/LoggingDocTest.java :include: mdc-actor Now, the values will be available in the MDC, so you can use them in the layout pattern:: @@ -456,7 +456,7 @@ A more advanced (including most Akka added information) example pattern would be java.util.logging ================= -Akka includes a logger for `java.util.logging `_. +Akka includes a logger for `java.util.logging `_. You need to enable the ``akka.event.jul.JavaLogger`` in the ``loggers`` element in the :ref:`configuration`. Here you can also define the log level of the event bus. diff --git a/akka-docs/rst/java/mailboxes.rst b/akka-docs/rst/java/mailboxes.rst index d3c33378c8..817875af2a 100644 --- a/akka-docs/rst/java/mailboxes.rst +++ b/akka-docs/rst/java/mailboxes.rst @@ -17,7 +17,7 @@ It is possible to require a certain type of message queue for a certain type of by having that actor implement the parameterized interface :class:`RequiresMessageQueue`. Here is an example: -.. includecode:: code/docs/actorlambda/MyBoundedActor.java#my-bounded-untyped-actor +.. includecode:: code/jdocs/actor/MyBoundedActor.java#my-bounded-untyped-actor The type parameter to the :class:`RequiresMessageQueue` interface needs to be mapped to a mailbox in configuration like this: @@ -239,7 +239,7 @@ PriorityMailbox How to create a PriorityMailbox: -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#prio-mailbox +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#prio-mailbox And then add it to the configuration: @@ -247,7 +247,7 @@ And then add it to the configuration: And then an example on how you would use it: -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#prio-dispatcher +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#prio-dispatcher It is also possible to configure a mailbox type directly like this: @@ -256,11 +256,11 @@ It is also possible to configure a mailbox type directly like this: And then use it either from deployment like this: -.. includecode:: code/docs/dispatcher/DispatcherDocTest.java#defining-mailbox-in-config +.. includecode:: code/jdocs/dispatcher/DispatcherDocTest.java#defining-mailbox-in-config Or code like this: -.. includecode:: code/docs/dispatcher/DispatcherDocTest.java#defining-mailbox-in-code +.. includecode:: code/jdocs/dispatcher/DispatcherDocTest.java#defining-mailbox-in-code ControlAwareMailbox ------------------- @@ -274,20 +274,20 @@ It can be configured like this: Control messages need to extend the ``ControlMessage`` trait: -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#control-aware-mailbox-messages +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#control-aware-mailbox-messages And then an example on how you would use it: -.. includecode:: ../java/code/docs/dispatcher/DispatcherDocTest.java#control-aware-dispatcher +.. includecode:: ../java/code/jdocs/dispatcher/DispatcherDocTest.java#control-aware-dispatcher Creating your own Mailbox type ============================== An example is worth a thousand quacks: -.. includecode:: code/docs/dispatcher/MyUnboundedJMailbox.java#mailbox-implementation-example +.. includecode:: code/jdocs/dispatcher/MyUnboundedJMailbox.java#mailbox-implementation-example -.. includecode:: code/docs/dispatcher/MyUnboundedJMessageQueueSemantics.java#mailbox-implementation-example +.. includecode:: code/jdocs/dispatcher/MyUnboundedJMessageQueueSemantics.java#mailbox-implementation-example And then you just specify the FQCN of your MailboxType as the value of the "mailbox-type" in the dispatcher configuration, or the mailbox configuration. @@ -309,7 +309,7 @@ You can also use the mailbox as a requirement on the dispatcher like this: Or by defining the requirement on your actor class like this: -.. includecode:: code/docs/dispatcher/DispatcherDocTest.java#require-mailbox-on-actor +.. includecode:: code/jdocs/dispatcher/DispatcherDocTest.java#require-mailbox-on-actor Special Semantics of ``system.actorOf`` diff --git a/akka-docs/rst/java/persistence-query-leveldb.rst b/akka-docs/rst/java/persistence-query-leveldb.rst index 08d030932f..5d5cb1b213 100644 --- a/akka-docs/rst/java/persistence-query-leveldb.rst +++ b/akka-docs/rst/java/persistence-query-leveldb.rst @@ -26,7 +26,7 @@ How to get the ReadJournal The ``ReadJournal`` is retrieved via the ``akka.persistence.query.PersistenceQuery`` extension: -.. includecode:: code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java#get-read-journal +.. includecode:: code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java#get-read-journal Supported Queries ================= @@ -37,7 +37,7 @@ EventsByPersistenceIdQuery and CurrentEventsByPersistenceIdQuery ``eventsByPersistenceId`` is used for retrieving events for a specific ``PersistentActor`` identified by ``persistenceId``. -.. includecode:: code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java#EventsByPersistenceId +.. includecode:: code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java#EventsByPersistenceId You can retrieve a subset of all events by specifying ``fromSequenceNr`` and ``toSequenceNr`` or use ``0L`` and ``Long.MAX_VALUE`` respectively to retrieve all events. Note that @@ -66,7 +66,7 @@ AllPersistenceIdsQuery and CurrentPersistenceIdsQuery ``allPersistenceIds`` is used for retrieving all ``persistenceIds`` of all persistent actors. -.. includecode:: code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java#AllPersistenceIds +.. includecode:: code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java#AllPersistenceIds The returned event stream is unordered and you can expect different order for multiple executions of the query. @@ -88,12 +88,12 @@ EventsByTag and CurrentEventsByTag ``eventsByTag`` is used for retrieving events that were marked with a given tag, e.g. all domain events of an Aggregate Root type. -.. includecode:: code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java#EventsByTag +.. includecode:: code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java#EventsByTag To tag events you create an :ref:`event-adapters-java` that wraps the events in a ``akka.persistence.journal.Tagged`` with the given ``tags``. -.. includecode:: code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java#tagger +.. includecode:: code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java#tagger You can use ``NoOffset`` to retrieve all events with a given tag or retrieve a subset of all events by specifying a ``Sequence`` ``offset``. The ``offset`` corresponds to an ordered sequence number for diff --git a/akka-docs/rst/java/persistence-query.rst b/akka-docs/rst/java/persistence-query.rst index e6c2fa26e9..2ebd9fd5d6 100644 --- a/akka-docs/rst/java/persistence-query.rst +++ b/akka-docs/rst/java/persistence-query.rst @@ -47,7 +47,7 @@ Read journals are implemented as `Community plugins`_, each targeting a specific databases). For example, given a library that provides a ``akka.persistence.query.my-read-journal`` obtaining the related journal is as simple as: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#basic-usage +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#basic-usage Journal implementers are encouraged to put this identifier in a variable known to the user, such that one can access it via ``getJournalFor(NoopJournal.class, NoopJournal.identifier)``, however this is not enforced. @@ -75,11 +75,11 @@ AllPersistenceIdsQuery and CurrentPersistenceIdsQuery By default this stream should be assumed to be a "live" stream, which means that the journal should keep emitting new persistence ids as they come into the system: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#all-persistence-ids-live +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#all-persistence-ids-live If your usage does not require a live stream, you can use the ``currentPersistenceIds`` query: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#all-persistence-ids-snap +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#all-persistence-ids-snap EventsByPersistenceIdQuery and CurrentEventsByPersistenceIdQuery ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -88,7 +88,7 @@ EventsByPersistenceIdQuery and CurrentEventsByPersistenceIdQuery however, since it is a stream it is possible to keep it alive and watch for additional incoming events persisted by the persistent actor identified by the given ``persistenceId``. -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#events-by-persistent-id +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#events-by-persistent-id Most journals will have to revert to polling in order to achieve this, which can typically be configured with a ``refresh-interval`` configuration property. @@ -108,7 +108,7 @@ Some journals may support tagging of events via an :ref:`event-adapters-java` th ``akka.persistence.journal.Tagged`` with the given ``tags``. The journal may support other ways of doing tagging - again, how exactly this is implemented depends on the used journal. Here is an example of such a tagging event adapter: -.. includecode:: code/docs/persistence/query/LeveldbPersistenceQueryDocTest.java#tagger +.. includecode:: code/jdocs/persistence/query/LeveldbPersistenceQueryDocTest.java#tagger .. note:: A very important thing to keep in mind when using queries spanning multiple persistenceIds, such as ``EventsByTag`` @@ -122,7 +122,7 @@ In the example below we query all events which have been tagged (we assume this :ref:`EventAdapter `, or that the journal is smart enough that it can figure out what we mean by this tag - for example if the journal stored the events as json it may try to find those with the field ``tag`` set to this value etc.). -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#events-by-tag +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#events-by-tag As you can see, we can use all the usual stream combinators available from :ref:`streams-java` on the resulting query stream, including for example taking the first 10 and cancelling the stream. It is worth pointing out that the built-in ``EventsByTag`` @@ -142,11 +142,11 @@ stream, for example if it's finite or infinite, strictly ordered or not ordered is defined as the second type parameter of the returned ``Source``, which allows journals to provide users with their specialised query object, as demonstrated in the sample below: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#advanced-journal-query-types +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#advanced-journal-query-types -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#advanced-journal-query-definition +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#advanced-journal-query-definition -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#advanced-journal-query-usage +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#advanced-journal-query-usage .. _Community plugins: http://akka.io/community/#plugins-to-akka-persistence-query @@ -177,7 +177,7 @@ Materialize view to Reactive Streams compatible datastore If the read datastore exposes a `Reactive Streams`_ interface then implementing a simple projection is as simple as, using the read-journal and feeding it into the databases driver interface, for example like so: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-rs +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-rs .. _Reactive Streams: http://reactive-streams.org @@ -190,8 +190,8 @@ you may have to implement the write logic using plain functions or Actors instea In case your write logic is state-less and you just need to convert the events from one data type to another before writing into the alternative datastore, then the projection is as simple as: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-simple-classes -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-simple +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-simple-classes +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-simple Resumable projections --------------------- @@ -204,9 +204,9 @@ The example below additionally highlights how you would use Actors to implement you need to do some complex logic that would be best handled inside an Actor before persisting the event into the other datastore: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-actor-run +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-actor-run -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-actor +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#projection-into-different-store-actor .. _Command & Query Responsibility Segregation: https://msdn.microsoft.com/en-us/library/jj554200.aspx @@ -240,11 +240,11 @@ As illustrated below one of the implementations can delegate to the other. Below is a simple journal implementation: -.. includecode:: code/docs/persistence/PersistenceQueryDocTest.java#my-read-journal +.. includecode:: code/jdocs/persistence/PersistenceQueryDocTest.java#my-read-journal And the ``EventsByTag`` could be backed by such an Actor for example: -.. includecode:: code/docs/persistence/query/MyEventsByTagJavaPublisher.java#events-by-tag-publisher +.. includecode:: code/jdocs/persistence/query/MyEventsByTagJavaPublisher.java#events-by-tag-publisher The ``ReadJournalProvider`` class must have a constructor with one of these signatures: diff --git a/akka-docs/rst/java/persistence-schema-evolution.rst b/akka-docs/rst/java/persistence-schema-evolution.rst index cf31056e37..eb78f6485a 100644 --- a/akka-docs/rst/java/persistence-schema-evolution.rst +++ b/akka-docs/rst/java/persistence-schema-evolution.rst @@ -162,11 +162,11 @@ For more in-depth explanations on how serialization picks the serializer to use First we start by defining our domain model class, here representing a person: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#simplest-custom-serializer-model +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#simplest-custom-serializer-model Next we implement a serializer (or extend an existing one to be able to handle the new ``Person`` class): -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#simplest-custom-serializer +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#simplest-custom-serializer And finally we register the serializer and bind it to handle the ``docs.persistence.Person`` class: @@ -208,7 +208,7 @@ While being able to read messages with missing fields is half of the solution, y values somehow. This is usually modeled as some kind of default value, or by representing the field as an ``Optional`` See below for an example how reading an optional field from a serialized protocol buffers message might look like. -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#protobuf-read-optional-model +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#protobuf-read-optional-model Next we prepare an protocol definition using the protobuf Interface Description Language, which we'll use to generate the serializer code to be used on the Akka Serialization layer (notice that the schema aproach allows us to easily rename @@ -221,7 +221,7 @@ Optional fields can be handled explicitly or missing values by calling the ``has which we do for ``seatType`` in order to use a ``Unknown`` type in case the event was stored before we had introduced the field to this event type: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#protobuf-read-optional +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#protobuf-read-optional .. _rename-field-java: @@ -278,7 +278,7 @@ or using a library like `Stamina`_ which helps to create those ``V1->V2->V3->... The following snippet showcases how one could apply renames if working with plain JSON (using a ``JsObject`` as an example JSON representation): -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#rename-plain-json +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#rename-plain-json As you can see, manually handling renames induces some boilerplate onto the EventAdapter, however much of it you will find is common infrastructure code that can be either provided by an external library (for promotion management) @@ -347,12 +347,12 @@ that the type is no longer needed, and skip the deserialization all-together: The serializer detects that the string manifest points to a removed event type and skips attempting to deserialize it: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#string-serializer-skip-deleved-event-by-manifest +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#string-serializer-skip-deleved-event-by-manifest The EventAdapter we implemented is aware of ``EventDeserializationSkipped`` events (our "Tombstones"), and emits and empty ``EventSeq`` whenever such object is encoutered: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#string-serializer-skip-deleved-event-by-manifest-adapter +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#string-serializer-skip-deleved-event-by-manifest-adapter .. _detach-domain-from-data-model-java: @@ -384,13 +384,13 @@ these types in a 1:1 style as illustrated below: We will use the following domain and data models to showcase how the separation can be implemented by the adapter: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#detach-models +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#detach-models The :class:`EventAdapter` takes care of converting from one model to the other one (in both directions), alowing the models to be completely detached from each other, such that they can be optimised independently as long as the mapping logic is able to convert between them: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#detach-models-adapter +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#detach-models-adapter The same technique could also be used directly in the Serializer if the end result of marshalling is bytes. Then the serializer can simply convert the bytes do the domain object by using the generated protobuf builders. @@ -413,7 +413,7 @@ In this aproach, the :class:`EventAdapter` is used as the marshalling layer: it The journal plugin notices that the incoming event type is JSON (for example by performing a ``match`` on the incoming event) and stores the incoming object directly. -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#detach-models-adapter-json +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#detach-models-adapter-json .. note:: This technique only applies if the Akka Persistence plugin you are using provides this capability. @@ -467,7 +467,7 @@ During recovery however, we now need to convert the old ``V1`` model into the `` Depending if the old event contains a name change, we either emit the ``UserNameChanged`` or we don't, and the address change is handled similarily: -.. includecode:: code/docs/persistence/PersistenceSchemaEvolutionDocTest.java#split-events-during-recovery +.. includecode:: code/jdocs/persistence/PersistenceSchemaEvolutionDocTest.java#split-events-during-recovery By returning an :class:`EventSeq` from the event adapter, the recovered event can be converted to multiple events before being delivered to the persistent actor. diff --git a/akka-docs/rst/java/persistence.rst b/akka-docs/rst/java/persistence.rst index 3618ccb16c..f77a328efd 100644 --- a/akka-docs/rst/java/persistence.rst +++ b/akka-docs/rst/java/persistence.rst @@ -87,7 +87,7 @@ Akka persistence supports event sourcing with the ``AbstractPersistentActor`` ab class uses the ``persist`` method to persist and handle events. The behavior of an ``AbstractPersistentActor`` is defined by implementing ``createReceiveRecover`` and ``createReceive``. This is demonstrated in the following example. -.. includecode:: ../../../akka-docs/rst/java/code/docs/persistence/PersistentActorExample.java#persistent-actor-example +.. includecode:: ../../../akka-docs/rst/java/code/jdocs/persistence/PersistentActorExample.java#persistent-actor-example The example defines two data types, ``Cmd`` and ``Evt`` to represent commands and events, respectively. The ``state`` of the ``ExamplePersistentActor`` is a list of persisted event data contained in ``ExampleState``. @@ -135,7 +135,7 @@ Identifiers A persistent actor must have an identifier that doesn't change across different actor incarnations. The identifier must be defined with the ``persistenceId`` method. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#persistence-id-override +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#persistence-id-override .. note:: ``persistenceId`` must be unique to a given entity in the journal (database table/keyspace). @@ -153,7 +153,7 @@ New messages sent to a persistent actor during recovery do not interfere with re only be received by a persistent actor after recovery completes. .. note:: - Accessing the ``sender()`` for replayed messages will always result in a ``deadLetters`` reference, + Accessing the sender with ``getSender()`` for replayed messages will always result in a ``deadLetters`` reference, as the original sender is presumed to be long gone. If you indeed have to notify an actor during recovery in the future, store its ``ActorPath`` explicitly in your persisted events. @@ -169,7 +169,7 @@ To skip loading snapshots and replay all events you can use ``SnapshotSelectionC This can be useful if snapshot serialization format has changed in an incompatible way. It should typically not be used when events have been deleted. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#recovery-no-snap +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#recovery-no-snap Another example, which can be fun for experiments but probably not in a real application, is setting an upper bound to the replay which allows the actor to be replayed to a certain point "in the past" @@ -177,25 +177,25 @@ instead to its most up to date state. Note that after that it is a bad idea to p events because a later recovery will probably be confused by the new events that follow the events that were previously skipped. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#recovery-custom +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#recovery-custom Recovery can be disabled by returning ``Recovery.none()`` in the ``recovery`` method of a ``PersistentActor``: -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#recovery-disabled +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#recovery-disabled Recovery status ^^^^^^^^^^^^^^^ A persistent actor can query its own recovery status via the methods -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#recovery-status +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#recovery-status Sometimes there is a need for performing additional initialization when the recovery has completed before processing any other message sent to the persistent actor. The persistent actor will receive a special :class:`RecoveryCompleted` message right after recovery and before any other received messages. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#recovery-completed +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#recovery-completed If there is a problem with recovering the state of the actor from the journal, ``onRecoveryFailure`` is called (logging the error by default), and the actor will be stopped. @@ -235,7 +235,7 @@ The ``DiscardToDeadLetterStrategy`` strategy also has a pre-packaged companion c You can also query the default strategy via the Akka persistence extension singleton:: - Persistence.get(getContext().system()).defaultInternalStashOverflowStrategy(); + Persistence.get(getContext().getSystem()).defaultInternalStashOverflowStrategy(); .. note:: The bounded mailbox should be avoided in the persistent actor, by which the messages come from storage backends may @@ -258,7 +258,7 @@ stash incoming Commands while the Journal is still working on persisting and/or In the below example, the event callbacks may be called "at any time", even after the next Command has been processed. The ordering between events is still guaranteed ("evt-b-1" will be sent after "evt-a-2", which will be sent after "evt-a-1" etc.). -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#persist-async +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#persist-async .. note:: In order to implement the pattern known as "*command sourcing*" simply call ``persistAsync`` on all incoming messages right away @@ -281,12 +281,12 @@ use it for *read* operations, and actions which do not have corresponding events Using this method is very similar to the persist family of methods, yet it does **not** persist the passed in event. It will be kept in memory and used when invoking the handler. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#defer +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#defer -Notice that the ``sender()`` is **safe** to access in the handler callback, and will be pointing to the original sender +Notice that the ``getSender()`` method is **safe** to call in the handler callback, and will be pointing to the original sender of the command for which this ``deferAsync`` handler was called. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#defer-caller +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#defer-caller .. warning:: The callback will not be invoked if the actor is restarted (or stopped) in between the call to @@ -297,18 +297,18 @@ of the command for which this ``deferAsync`` handler was called. Nested persist calls -------------------- It is possible to call ``persist`` and ``persistAsync`` inside their respective callback blocks and they will properly -retain both the thread safety (including the right value of ``sender()``) as well as stashing guarantees. +retain both the thread safety (including the right return value of ``getSender()``) as well as stashing guarantees. In general it is encouraged to create command handlers which do not need to resort to nested event persisting, however there are situations where it may be useful. It is important to understand the ordering of callback execution in those situations, as well as their implication on the stashing behaviour (that ``persist()`` enforces). In the following example two persist calls are issued, and each of them issues another persist inside its callback: -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#nested-persist-persist +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#nested-persist-persist When sending two commands to this ``PersistentActor``, the persist handlers will be executed in the following order: -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#nested-persist-persist-caller +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#nested-persist-persist-caller First the "outer layer" of persist calls is issued and their callbacks are applied. After these have successfully completed, the inner callbacks will be invoked (once the events they are persisting have been confirmed to be persisted by the journal). @@ -318,11 +318,11 @@ is extended until all nested ``persist`` callbacks have been handled. It is also possible to nest ``persistAsync`` calls, using the same pattern: -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#nested-persistAsync-persistAsync +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#nested-persistAsync-persistAsync In this case no stashing is happening, yet the events are still persisted and callbacks executed in the expected order: -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#nested-persistAsync-persistAsync-caller +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#nested-persistAsync-persistAsync-caller While it is possible to nest mixed ``persist`` and ``persistAsync`` with keeping their respective semantics it is not a recommended practice, as it may lead to overly complex nesting. @@ -348,7 +348,7 @@ will most likely fail anyway, since the journal is probably unavailable. It is b actor and after a back-off timeout start it again. The ``akka.pattern.BackoffSupervisor`` actor is provided to support such restarts. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#backoff +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#backoff If persistence of an event is rejected before it is stored, e.g. due to serialization error, ``onPersistRejected`` will be invoked (logging a warning by default), and the actor continues with @@ -465,9 +465,9 @@ before it processes the other messages which have been put into its stash**, cau The example below highlights how messages arrive in the Actor's mailbox and how they interact with its internal stashing mechanism when ``persist()`` is used. Notice the early stop behaviour that occurs when ``PoisonPill`` is used: -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#safe-shutdown -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#safe-shutdown-example-bad -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#safe-shutdown-example-good +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#safe-shutdown +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#safe-shutdown-example-bad +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#safe-shutdown-example-good .. _replay-filter-java: @@ -509,12 +509,12 @@ in context of persistent actors but this is also applicable to persistent views. Persistent actor can save snapshots of internal state by calling the ``saveSnapshot`` method. If saving of a snapshot succeeds, the persistent actor receives a ``SaveSnapshotSuccess`` message, otherwise a ``SaveSnapshotFailure`` message -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#save-snapshot +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#save-snapshot During recovery, the persistent actor is offered a previously saved snapshot via a ``SnapshotOffer`` message from which it can initialize internal state. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#snapshot-offer +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#snapshot-offer The replayed messages that follow the ``SnapshotOffer`` message, if any, are younger than the offered snapshot. They finally recover the persistent actor to its current (i.e. latest) state. @@ -522,7 +522,7 @@ They finally recover the persistent actor to its current (i.e. latest) state. In general, a persistent actor is only offered a snapshot if that persistent actor has previously saved one or more snapshots and at least one of these snapshots matches the ``SnapshotSelectionCriteria`` that can be specified for recovery. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#snapshot-criteria +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#snapshot-criteria If not specified, they default to ``SnapshotSelectionCriteria.latest()`` which selects the latest (= youngest) snapshot. To disable snapshot-based recovery, applications should use ``SnapshotSelectionCriteria.none()``. A recovery where no @@ -617,7 +617,7 @@ between ``deliver`` and ``confirmDelivery`` is possible. The ``deliveryId`` must of the message, the destination actor will send the same``deliveryId`` wrapped in a confirmation message back to the sender. The sender will then use it to call ``confirmDelivery`` method to complete the delivery routine. -.. includecode:: code/docs/persistence/LambdaPersistenceDocTest.java#at-least-once-example +.. includecode:: code/jdocs/persistence/LambdaPersistenceDocTest.java#at-least-once-example The ``deliveryId`` generated by the persistence module is a strictly monotonically increasing sequence number without gaps. The same sequence is used for all destinations of the actor, i.e. when sending to multiple @@ -693,7 +693,7 @@ Event Adapters help in situations where: Implementing an EventAdapter is rather stright forward: -.. includecode:: code/docs/persistence/PersistenceEventAdapterDocTest.java#identity-event-adapter +.. includecode:: code/jdocs/persistence/PersistenceEventAdapterDocTest.java#identity-event-adapter Then in order for it to be used on events coming to and from the journal you must bind it using the below configuration syntax: @@ -798,7 +798,7 @@ For an example of snapshot store plugin which writes snapshots as individual fil Applications can provide their own plugins by implementing a plugin API and activate them by configuration. Plugin development requires the following imports: -.. includecode:: code/docs/persistence/LambdaPersistencePluginDocTest.java#plugin-imports +.. includecode:: code/jdocs/persistence/LambdaPersistencePluginDocTest.java#plugin-imports Eager initialization of persistence plugin ------------------------------------------ @@ -821,7 +821,7 @@ A journal plugin extends ``AsyncWriteJournal``. If the storage backend API only supports synchronous, blocking writes, the methods should be implemented as: -.. includecode:: code/docs/persistence/LambdaPersistencePluginDocTest.java#sync-journal-plugin-api +.. includecode:: code/jdocs/persistence/LambdaPersistencePluginDocTest.java#sync-journal-plugin-api A journal plugin must also implement the methods defined in ``AsyncRecovery`` for replays and sequence number recovery: @@ -893,7 +893,7 @@ The TCK is usable from Java as well as Scala projects. For Java you need to incl To include the Journal TCK tests in your test suite simply extend the provided ``JavaJournalSpec``: -.. includecode:: ./code/docs/persistence/LambdaPersistencePluginDocTest.java#journal-tck-java +.. includecode:: ./code/jdocs/persistence/LambdaPersistencePluginDocTest.java#journal-tck-java Please note that some of the tests are optional, and by overriding the ``supports...`` methods you give the TCK the needed information about which tests to run. You can implement these methods using the provided @@ -906,12 +906,12 @@ typical scenarios. In order to include the ``SnapshotStore`` TCK tests in your test suite simply extend the ``SnapshotStoreSpec``: -.. includecode:: ./code/docs/persistence/LambdaPersistencePluginDocTest.java#snapshot-store-tck-java +.. includecode:: ./code/jdocs/persistence/LambdaPersistencePluginDocTest.java#snapshot-store-tck-java In case your plugin requires some setting up (starting a mock database, removing temporary files etc.) you can override the ``beforeAll`` and ``afterAll`` methods to hook into the tests lifecycle: -.. includecode:: ./code/docs/persistence/LambdaPersistencePluginDocTest.java#journal-tck-before-after-java +.. includecode:: ./code/jdocs/persistence/LambdaPersistencePluginDocTest.java#journal-tck-before-after-java We *highly recommend* including these specifications in your test suite, as they cover a broad range of cases you might have otherwise forgotten to test for when writing a plugin from scratch. @@ -969,7 +969,7 @@ backup node. A shared LevelDB instance is started by instantiating the ``SharedLeveldbStore`` actor. -.. includecode:: code/docs/persistence/LambdaPersistencePluginDocTest.java#shared-store-creation +.. includecode:: code/jdocs/persistence/LambdaPersistencePluginDocTest.java#shared-store-creation By default, the shared instance writes journaled messages to a local directory named ``journal`` in the current working directory. The storage location can be changed by configuration: @@ -984,7 +984,7 @@ plugin. This plugin must be initialized by injecting the (remote) ``SharedLeveldbStore`` actor reference. Injection is done by calling the ``SharedLeveldbJournal.setStore`` method with the actor reference as argument. -.. includecode:: code/docs/persistence/LambdaPersistencePluginDocTest.java#shared-store-usage +.. includecode:: code/jdocs/persistence/LambdaPersistencePluginDocTest.java#shared-store-usage Internal journal commands (sent by persistent actors) are buffered until injection completes. Injection is idempotent i.e. only the first injection is used. @@ -1098,12 +1098,12 @@ configured in the following sections of the ``reference.conf`` configuration res Note that in this case the actor or view overrides only ``persistenceId`` method: -.. includecode:: ../java/code/docs/persistence/PersistenceMultiDocTest.java#default-plugins +.. includecode:: ../java/code/jdocs/persistence/PersistenceMultiDocTest.java#default-plugins When a persistent actor or view overrides ``journalPluginId`` and ``snapshotPluginId`` methods, the actor or view will be serviced by these specific persistence plugins instead of the defaults: -.. includecode:: ../java/code/docs/persistence/PersistenceMultiDocTest.java#override-plugins +.. includecode:: ../java/code/jdocs/persistence/PersistenceMultiDocTest.java#override-plugins Note that ``journalPluginId`` and ``snapshotPluginId`` must refer to properly configured ``reference.conf`` plugin entries with a standard ``class`` property as well as settings which are specific for those plugins, i.e.: diff --git a/akka-docs/rst/java/remoting-artery.rst b/akka-docs/rst/java/remoting-artery.rst index f9bfe4e1a9..ebeac251ac 100644 --- a/akka-docs/rst/java/remoting-artery.rst +++ b/akka-docs/rst/java/remoting-artery.rst @@ -117,7 +117,7 @@ In order to communicate with an actor, it is necessary to have its :class:`Actor the creator of the actor (the caller of ``actorOf()``) is who gets the :class:`ActorRef` for an actor that it can then send to other actors. In other words: -* An Actor can get a remote Actor's reference simply by receiving a message from it (as it's available as `sender()` then), +* An Actor can get a remote Actor's reference simply by receiving a message from it (as it's available as ``getSender()`` then), or inside of a remote message (e.g. `PleaseReply(message: String, remoteActorRef: ActorRef)`) Alternatively, an actor can look up another located at a known path using @@ -194,7 +194,7 @@ which in this sample corresponds to ``sampleActorSystem@127.0.0.1:2553``. Once you have configured the properties above you would do the following in code: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#sample-actor +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#sample-actor The actor class ``SampleActor`` has to be available to the runtimes using it, i.e. the classloader of the actor systems has to have a JAR containing the class. @@ -229,15 +229,15 @@ precedence. With these imports: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#import +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#import and a remote address like this: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#make-address-artery +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#make-address-artery you can advise the system to create a child on that remote node like so: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#deploy +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#deploy Remote deployment whitelist ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -472,7 +472,7 @@ remained the same, we recommend reading the :ref:`serialization-java` documentat Implementing an :class:`akka.serialization.ByteBufferSerializer` works the same way as any other serializer, -.. includecode:: code/docs/actor/ByteBufferSerializerDocTest.java#ByteBufferSerializer-interface +.. includecode:: code/jdocs/actor/ByteBufferSerializerDocTest.java#ByteBufferSerializer-interface Implementing a serializer for Artery is therefore as simple as implementing this interface, and binding the serializer as usual (which is explained in :ref:`serialization-java`). @@ -483,7 +483,7 @@ The array based methods will be used when ``ByteBuffer`` is not used, e.g. in Ak Note that the array based methods can be implemented by delegation like this: -.. includecode:: code/docs/actor/ByteBufferSerializerDocTest.java#bytebufserializer-with-manifest +.. includecode:: code/jdocs/actor/ByteBufferSerializerDocTest.java#bytebufserializer-with-manifest .. _disable-java-serializer-java-artery: @@ -745,7 +745,7 @@ There are lots of configuration properties that are related to remoting in Akka. Setting properties like the listening IP and port number programmatically is best done by using something like the following: - .. includecode:: ../java/code/docs/remoting/RemoteDeploymentDocTest.java#programmatic-artery + .. includecode:: ../java/code/jdocs/remoting/RemoteDeploymentDocTest.java#programmatic-artery .. _remote-configuration-nat-artery-java: diff --git a/akka-docs/rst/java/remoting.rst b/akka-docs/rst/java/remoting.rst index c75b0c5b57..1ff3ce90cc 100644 --- a/akka-docs/rst/java/remoting.rst +++ b/akka-docs/rst/java/remoting.rst @@ -73,7 +73,7 @@ As you can see from the example above the following pattern is used to find an a Once you obtained a selection to the actor you can interact with it they same way you would with a local actor, e.g.:: - selection.tell("Pretty awesome feature", self()); + selection.tell("Pretty awesome feature", getSelf()); 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 @@ -121,7 +121,7 @@ which in this sample corresponds to ``sampleActorSystem@127.0.0.1:2553``. Once you have configured the properties above you would do the following in code: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#sample-actor +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#sample-actor The actor class ``SampleActor`` has to be available to the runtimes using it, i.e. the classloader of the actor systems has to have a JAR containing the class. @@ -158,15 +158,15 @@ precedence. With these imports: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#import +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#import and a remote address like this: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#make-address +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#make-address you can advise the system to create a child on that remote node like so: -.. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#deploy +.. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#deploy .. _remote-deployment-whitelist-java: @@ -480,7 +480,7 @@ section of Lightbend's SSL-Config library. Since an Akka remoting is inherently :ref:`peer-to-peer ` both the key-store as well as trust-store need to be configured on each remoting node participating in the cluster. -The official `Java Secure Socket Extension documentation `_ +The official `Java Secure Socket Extension documentation `_ as well as the `Oracle documentation on creating KeyStore and TrustStores `_ are both great resources to research when setting up security on the JVM. Please consult those resources when troubleshooting and configuring SSL. @@ -574,7 +574,7 @@ There are lots of configuration properties that are related to remoting in Akka. Setting properties like the listening IP and port number programmatically is best done by using something like the following: - .. includecode:: code/docs/remoting/RemoteDeploymentDocTest.java#programmatic + .. includecode:: code/jdocs/remoting/RemoteDeploymentDocTest.java#programmatic .. _remote-configuration-nat-java: diff --git a/akka-docs/rst/java/routing.rst b/akka-docs/rst/java/routing.rst index 665b94847d..0a3659dce2 100644 --- a/akka-docs/rst/java/routing.rst +++ b/akka-docs/rst/java/routing.rst @@ -19,7 +19,7 @@ A Simple Router The following example illustrates how to use a ``Router`` and manage the routees from within an actor. -.. includecode:: code/docs/jrouting/RouterDocTest.java#router-in-actor +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#router-in-actor We create a ``Router`` and specify that it should use ``RoundRobinRoutingLogic`` when routing the messages to the routees. @@ -89,12 +89,12 @@ routees will be created as the router's children. .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-round-robin-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-pool-1 Here is the same example, but with the router configuration provided programmatically instead of from configuration. -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-pool-2 Remote Deployed Routees *********************** @@ -105,7 +105,7 @@ fashion. In order to deploy routees remotely, wrap the router configuration in a ``RemoteRouterConfig``, attaching the remote addresses of the nodes to deploy to. Remote deployment requires the ``akka-remote`` module to be included in the classpath. -.. includecode:: code/docs/jrouting/RouterDocTest.java#remoteRoutees +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#remoteRoutees Senders ******* @@ -114,13 +114,13 @@ Senders When a routee sends a message, it can :ref:`set itself as the sender `. -.. includecode:: code/docs/jrouting/RouterDocTest.java#reply-with-self +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#reply-with-self However, it is often useful for routees to set the *router* as a sender. For example, you might want to set the router as the sender if you want to hide the details of the routees behind the router. The following code snippet shows how to set the parent router as sender. -.. includecode:: code/docs/jrouting/RouterDocTest.java#reply-with-parent +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#reply-with-parent Supervision @@ -150,7 +150,7 @@ by specifying the strategy when defining the router. Setting the strategy is easily done: -.. includecode:: code/docs/jrouting/RouterDocTest.java#supervision +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#supervision .. _note-router-terminated-children-java: @@ -174,18 +174,18 @@ routee actors. .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-round-robin-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-group-1 Here is the same example, but with the router configuration provided programmatically instead of from configuration. -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-group-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-group-2 The routee actors are created externally from the router: -.. includecode:: code/docs/jrouting/RouterDocTest.java#create-workers +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#create-workers -.. includecode:: code/docs/jrouting/RouterDocTest.java#create-worker-actors +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#create-worker-actors The paths may contain protocol and address information for actors running on remote hosts. Remoting requires the ``akka-remote`` module to be included in the classpath. @@ -201,7 +201,7 @@ The router actors in this section are created from within a top level actor name Note that deployment paths in the configuration starts with ``/parent/`` followed by the name of the router actor. -.. includecode:: code/docs/jrouting/RouterDocTest.java#create-parent +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#create-parent .. _round-robin-router-java: @@ -214,21 +214,21 @@ RoundRobinPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-round-robin-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-pool-1 RoundRobinPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-pool-2 RoundRobinGroup defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-round-robin-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#round-robin-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#round-robin-group-1 RoundRobinGroup defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java +.. includecode:: code/jdocs/jrouting/RouterDocTest.java :include: paths,round-robin-group-2 RandomPool and RandomGroup @@ -240,21 +240,21 @@ RandomPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-random-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#random-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#random-pool-1 RandomPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#random-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#random-pool-2 RandomGroup defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-random-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#random-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#random-group-1 RandomGroup defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java +.. includecode:: code/jdocs/jrouting/RouterDocTest.java :include: paths,random-group-2 .. _balancing-pool-java: @@ -286,11 +286,11 @@ BalancingPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-balancing-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#balancing-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#balancing-pool-1 BalancingPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#balancing-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#balancing-pool-2 Addition configuration for the balancing dispatcher, which is used by the pool, can be configured in the ``pool-dispatcher`` section of the router deployment @@ -343,11 +343,11 @@ SmallestMailboxPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-smallest-mailbox-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#smallest-mailbox-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#smallest-mailbox-pool-1 SmallestMailboxPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#smallest-mailbox-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#smallest-mailbox-pool-2 There is no Group variant of the SmallestMailboxPool because the size of the mailbox and the internal dispatching state of the actor is not practically available from the paths @@ -362,21 +362,21 @@ BroadcastPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-broadcast-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#broadcast-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#broadcast-pool-1 BroadcastPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#broadcast-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#broadcast-pool-2 BroadcastGroup defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-broadcast-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#broadcast-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#broadcast-group-1 BroadcastGroup defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java +.. includecode:: code/jdocs/jrouting/RouterDocTest.java :include: paths,broadcast-group-2 .. note:: @@ -400,21 +400,21 @@ ScatterGatherFirstCompletedPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-scatter-gather-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#scatter-gather-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#scatter-gather-pool-1 ScatterGatherFirstCompletedPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#scatter-gather-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#scatter-gather-pool-2 ScatterGatherFirstCompletedGroup defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-scatter-gather-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#scatter-gather-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#scatter-gather-group-1 ScatterGatherFirstCompletedGroup defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java +.. includecode:: code/jdocs/jrouting/RouterDocTest.java :include: paths,scatter-gather-group-2 TailChoppingPool and TailChoppingGroup @@ -434,21 +434,21 @@ TailChoppingPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-tail-chopping-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#tail-chopping-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#tail-chopping-pool-1 TailChoppingPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#tail-chopping-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#tail-chopping-pool-2 TailChoppingGroup defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-tail-chopping-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#tail-chopping-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#tail-chopping-group-1 TailChoppingGroup defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java +.. includecode:: code/jdocs/jrouting/RouterDocTest.java :include: paths,tail-chopping-group-2 ConsistentHashingPool and ConsistentHashingGroup @@ -479,9 +479,9 @@ the same time for one router. The ``withHashMapper`` is tried first. Code example: -.. includecode:: code/docs/jrouting/ConsistentHashingRouterDocTest.java#cache-actor +.. includecode:: code/jdocs/jrouting/ConsistentHashingRouterDocTest.java#cache-actor -.. includecode:: code/docs/jrouting/ConsistentHashingRouterDocTest.java#consistent-hashing-router +.. includecode:: code/jdocs/jrouting/ConsistentHashingRouterDocTest.java#consistent-hashing-router In the above example you see that the ``Get`` message implements ``ConsistentHashable`` itself, while the ``Entry`` message is wrapped in a ``ConsistentHashableEnvelope``. The ``Evict`` @@ -491,21 +491,21 @@ ConsistentHashingPool defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-consistent-hashing-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#consistent-hashing-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#consistent-hashing-pool-1 ConsistentHashingPool defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#consistent-hashing-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#consistent-hashing-pool-2 ConsistentHashingGroup defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-consistent-hashing-group -.. includecode:: code/docs/jrouting/RouterDocTest.java#consistent-hashing-group-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#consistent-hashing-group-1 ConsistentHashingGroup defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java +.. includecode:: code/jdocs/jrouting/RouterDocTest.java :include: paths,consistent-hashing-group-2 @@ -536,7 +536,7 @@ matter how that router would normally route its messages. The example below shows how you would use a ``Broadcast`` message to send a very important message to every routee of a router. -.. includecode:: code/docs/jrouting/RouterDocTest.java#broadcastDavyJonesWarning +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#broadcastDavyJonesWarning In this example the router receives the ``Broadcast`` message, extracts its payload (``"Watch out for Davy Jones' locker"``), and then sends the payload on to all of the router's @@ -554,7 +554,7 @@ A ``PoisonPill`` message has special handling for all actors, including for rout receives a ``PoisonPill`` message, that actor will be stopped. See the :ref:`poison-pill-java` documentation for details. -.. includecode:: code/docs/jrouting/RouterDocTest.java#poisonPill +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#poisonPill For a router, which normally passes on messages to routees, it is important to realise that ``PoisonPill`` messages are processed by the router only. ``PoisonPill`` messages sent to a router @@ -572,7 +572,7 @@ router. Instead you should wrap a ``PoisonPill`` message inside a ``Broadcast`` routee will receive the ``PoisonPill`` message. Note that this will stop all routees, even if the routees aren't children of the router, i.e. even routees programmatically provided to the router. -.. includecode:: code/docs/jrouting/RouterDocTest.java#broadcastPoisonPill +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#broadcastPoisonPill With the code shown above, each routee will receive a ``PoisonPill`` message. Each routee will continue to process its messages as normal, eventually processing the ``PoisonPill``. This will @@ -600,14 +600,14 @@ Routees that are children of the router will also be suspended, and will be affe supervision directive that is applied to the router. Routees that are not the routers children, i.e. those that were created externally to the router, will not be affected. -.. includecode:: code/docs/jrouting/RouterDocTest.java#kill +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#kill As with the ``PoisonPill`` message, there is a distinction between killing a router, which indirectly kills its children (who happen to be routees), and killing routees directly (some of whom may not be children.) To kill routees directly the router should be sent a ``Kill`` message wrapped in a ``Broadcast`` message. -.. includecode:: code/docs/jrouting/RouterDocTest.java#broadcastKill +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#broadcastKill Management Messages ------------------- @@ -645,14 +645,14 @@ Pool with default resizer defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-resize-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#resize-pool-1 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#resize-pool-1 Several more configuration options are available and described in ``akka.actor.deployment.default.resizer`` section of the reference :ref:`configuration`. Pool with resizer defined in code: -.. includecode:: code/docs/jrouting/RouterDocTest.java#resize-pool-2 +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#resize-pool-2 *It is also worth pointing out that if you define the ``router`` in the configuration file then this value will be used instead of any programmatically sent parameters.* @@ -687,7 +687,7 @@ Pool with ``OptimalSizeExploringResizer`` defined in configuration: .. includecode:: ../scala/code/docs/routing/RouterDocSpec.scala#config-optimal-size-exploring-resize-pool -.. includecode:: code/docs/jrouting/RouterDocTest.java#optimal-size-exploring-resize-pool +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#optimal-size-exploring-resize-pool Several more configuration options are available and described in ``akka.actor.deployment.default.optimal-size-exploring-resizer`` section of the reference :ref:`configuration`. @@ -743,7 +743,7 @@ The router created in this example is replicating each message to a few destinat Start with the routing logic: -.. includecode:: code/docs/jrouting/CustomRouterDocTest.java#routing-logic +.. includecode:: code/jdocs/jrouting/CustomRouterDocTest.java#routing-logic ``select`` will be called for each message and in this example pick a few destinations by round-robin, by reusing the existing ``RoundRobinRoutingLogic`` and wrap the result in a ``SeveralRoutees`` @@ -753,7 +753,7 @@ The implementation of the routing logic must be thread safe, since it might be u A unit test of the routing logic: -.. includecode:: code/docs/jrouting/CustomRouterDocTest.java#unit-test-logic +.. includecode:: code/jdocs/jrouting/CustomRouterDocTest.java#unit-test-logic You could stop here and use the ``RedundancyRoutingLogic`` with a ``akka.routing.Router`` as described in :ref:`simple-router-java`. @@ -763,11 +763,11 @@ Let us continue and make this into a self contained, configurable, router actor. Create a class that extends ``PoolBase``, ``GroupBase`` or ``CustomRouterConfig``. That class is a factory for the routing logic and holds the configuration for the router. Here we make it a ``Group``. -.. includecode:: code/docs/jrouting/RedundancyGroup.java#group +.. includecode:: code/jdocs/jrouting/RedundancyGroup.java#group This can be used exactly as the router actors provided by Akka. -.. includecode:: code/docs/jrouting/CustomRouterDocTest.java#usage-1 +.. includecode:: code/jdocs/jrouting/CustomRouterDocTest.java#usage-1 Note that we added a constructor in ``RedundancyGroup`` that takes a ``Config`` parameter. That makes it possible to define it in configuration. @@ -779,7 +779,7 @@ Note the fully qualified class name in the ``router`` property. The router class constructor with one ``com.typesafe.config.Config`` parameter. The deployment section of the configuration is passed to the constructor. -.. includecode:: code/docs/jrouting/CustomRouterDocTest.java#usage-2 +.. includecode:: code/jdocs/jrouting/CustomRouterDocTest.java#usage-2 Configuring Dispatchers ^^^^^^^^^^^^^^^^^^^^^^^ @@ -809,7 +809,7 @@ the actor system’s default dispatcher. All standard routers allow setting this property in their constructor or factory method, custom routers have to implement the method in a suitable way. -.. includecode:: code/docs/jrouting/RouterDocTest.java#dispatchers +.. includecode:: code/jdocs/jrouting/RouterDocTest.java#dispatchers .. note:: diff --git a/akka-docs/rst/java/scheduler.rst b/akka-docs/rst/java/scheduler.rst index ad2a02ed92..12e31b0681 100644 --- a/akka-docs/rst/java/scheduler.rst +++ b/akka-docs/rst/java/scheduler.rst @@ -28,15 +28,15 @@ Some examples Schedule to send the "foo"-message to the testActor after 50ms: -.. includecode:: code/docs/actor/SchedulerDocTest.java +.. includecode:: code/jdocs/actor/SchedulerDocTest.java :include: imports1 -.. includecode:: code/docs/actor/SchedulerDocTest.java +.. includecode:: code/jdocs/actor/SchedulerDocTest.java :include: schedule-one-off-message Schedule a Runnable, that sends the current time to the testActor, to be executed after 50ms: -.. includecode:: code/docs/actor/SchedulerDocTest.java +.. includecode:: code/jdocs/actor/SchedulerDocTest.java :include: schedule-one-off-thunk .. warning:: @@ -50,10 +50,10 @@ Schedule a Runnable, that sends the current time to the testActor, to be execute Schedule to send the "Tick"-message to the ``tickActor`` after 0ms repeating every 50ms: -.. includecode:: code/docs/actor/SchedulerDocTest.java +.. includecode:: code/jdocs/actor/SchedulerDocTest.java :include: imports1,imports2 -.. includecode:: code/docs/actor/SchedulerDocTest.java +.. includecode:: code/jdocs/actor/SchedulerDocTest.java :include: schedule-recurring From ``akka.actor.ActorSystem`` diff --git a/akka-docs/rst/java/serialization.rst b/akka-docs/rst/java/serialization.rst index ded0f59a63..e96ccca7bd 100644 --- a/akka-docs/rst/java/serialization.rst +++ b/akka-docs/rst/java/serialization.rst @@ -83,10 +83,10 @@ Programmatic If you want to programmatically serialize/deserialize using Akka Serialization, here's some examples: -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: imports -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: programmatic For more information, have a look at the ``ScalaDoc`` for ``akka.serialization._`` @@ -104,10 +104,10 @@ Creating new Serializers First you need to create a class definition of your ``Serializer``, which is done by extending ``akka.serialization.JSerializer``, like this: -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: imports -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: my-own-serializer :exclude: ... @@ -140,7 +140,7 @@ class name if you used ``includeManifest=true``, otherwise it will be the empty This is how a ``SerializerWithStringManifest`` looks like: -.. includecode:: code/docs/serialization/SerializationDocTest.java#my-own-serializer2 +.. includecode:: code/jdocs/serialization/SerializationDocTest.java#my-own-serializer2 You must also bind it to a name in your :ref:`configuration` and then list which classes that should be serialized using it. @@ -164,10 +164,10 @@ In the general case, the local address to be used depends on the type of remote address which shall be the recipient of the serialized information. Use :meth:`Serialization.serializedActorPath(actorRef)` like this: -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: imports -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: actorref-serializer This assumes that serialization happens in the context of sending a message @@ -183,7 +183,7 @@ transport per se, which makes this question a bit more interesting. To find out the appropriate address to use when sending to ``remoteAddr`` you can use :meth:`ActorRefProvider.getExternalAddressFor(remoteAddr)` like this: -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: external-address .. note:: @@ -209,7 +209,7 @@ lenient as Akka’s RemoteActorRefProvider). There is also a default remote address which is the one used by cluster support (and typical systems have just this one); you can get it like this: -.. includecode:: code/docs/serialization/SerializationDocTest.java +.. includecode:: code/jdocs/serialization/SerializationDocTest.java :include: external-address-default Deep serialization of Actors diff --git a/akka-docs/rst/java/stream/stream-composition.rst b/akka-docs/rst/java/stream/stream-composition.rst index 6afacf27b8..8df4628f6c 100644 --- a/akka-docs/rst/java/stream/stream-composition.rst +++ b/akka-docs/rst/java/stream/stream-composition.rst @@ -85,7 +85,7 @@ with the rest of the graph), but this demonstrates the uniform underlying model. If we try to build a code snippet that corresponds to the above diagram, our first try might look like this: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#non-nested-flow +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#non-nested-flow It is clear however that there is no nesting present in our first attempt, since the library cannot figure out where we intended to put composite module boundaries, it is our responsibility to do that. If we are using the @@ -94,7 +94,7 @@ methods ``withAttributes()`` or ``named()`` (where the latter is just a shorthan The following code demonstrates how to achieve the desired nesting: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#nested-flow +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#nested-flow Once we have hidden the internals of our components, they act like any other built-in component of similar shape. If we hide some of the internals of our composites, the result looks just like if any other predefine component has been @@ -110,7 +110,7 @@ used: If we look at usage of built-in components, and our custom components, there is no difference in usage as the code snippet below demonstrates. -.. includecode:: ../code/docs/stream/CompositionDocTest.java#reuse +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#reuse Composing complex systems ------------------------- @@ -136,12 +136,12 @@ can be materialized) that encapsulates a non-trivial stream processing network. directed and non-directed cycles. The ``runnable()`` method of the :class:`GraphDSL` factory object allows the creation of a general, closed, and runnable graph. For example the network on the diagram can be realized like this: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#complex-graph +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#complex-graph In the code above we used the implicit port numbering feature to make the graph more readable and similar to the diagram. It is possible to refer to the ports, so another version might look like this: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#complex-graph-alt +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#complex-graph-alt | @@ -159,7 +159,7 @@ from the previous example, what remains is a partial graph: We can recreate a similar graph in code, using the DSL in a similar way than before: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#partial-graph +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#partial-graph The only new addition is the return value of the builder block, which is a :class:`Shape`. All graphs (including :class:`Source`, :class:`BidiFlow`, etc) have a shape, which encodes the *typed* ports of the module. In our example @@ -179,7 +179,7 @@ it is a good practice to give names to modules to help debugging. Since our partial graph has the right shape, it can be already used in the simpler, linear DSL: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#partial-use +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#partial-use It is not possible to use it as a :class:`Flow` yet, though (i.e. we cannot call ``.filter()`` on it), but :class:`Flow` has a ``fromGraph()`` method that just adds the DSL to a :class:`FlowShape`. There are similar methods on :class:`Source`, @@ -196,7 +196,7 @@ To demonstrate this, we will create the following graph: The code version of the above closed graph might look like this: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#partial-flow-dsl +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#partial-flow-dsl .. note:: All graph builder sections check if the resulting graph has all ports connected except the exposed ones and will @@ -205,7 +205,7 @@ The code version of the above closed graph might look like this: We are still in debt of demonstrating that :class:`RunnableGraph` is a component just like any other, which can be embedded in graphs. In the following snippet we embed one closed graph in another: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#embed-closed +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#embed-closed The type of the imported module indicates that the imported module has a :class:`ClosedShape`, and so we are not able to wire it to anything else inside the enclosing closed graph. Nevertheless, this "island" is embedded properly, @@ -257,29 +257,29 @@ To implement the above, first, we create a composite :class:`Source`, where the materialized type of :class:`CompletableFuture>>`. By using the combiner function ``Keep.left()``, the resulting materialized type is of the nested module (indicated by the color *red* on the diagram): -.. includecode:: ../code/docs/stream/CompositionDocTest.java#mat-combine-1 +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#mat-combine-1 Next, we create a composite :class:`Flow` from two smaller components. Here, the second enclosed :class:`Flow` has a materialized type of :class:`CompletionStage`, and we propagate this to the parent by using ``Keep.right()`` as the combiner function (indicated by the color *yellow* on the diagram): -.. includecode:: ../code/docs/stream/CompositionDocTest.java#mat-combine-2 +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#mat-combine-2 As a third step, we create a composite :class:`Sink`, using our ``nestedFlow`` as a building block. In this snippet, both the enclosed :class:`Flow` and the folding :class:`Sink` has a materialized value that is interesting for us, so we use ``Keep.both()`` to get a :class:`Pair` of them as the materialized type of ``nestedSink`` (indicated by the color *blue* on the diagram) -.. includecode:: ../code/docs/stream/CompositionDocTest.java#mat-combine-3 +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#mat-combine-3 As the last example, we wire together ``nestedSource`` and ``nestedSink`` and we use a custom combiner function to create a yet another materialized type of the resulting :class:`RunnableGraph`. This combiner function just ignores the :class:`CompletionStage` part, and wraps the other two values in a custom case class :class:`MyClass` (indicated by color *purple* on the diagram): -.. includecode:: ../code/docs/stream/CompositionDocTest.java#mat-combine-4a +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#mat-combine-4a -.. includecode:: ../code/docs/stream/CompositionDocTest.java#mat-combine-4b +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#mat-combine-4b .. note:: The nested structure in the above example is not necessary for combining the materialized values, it just @@ -299,7 +299,7 @@ by nested modules, unless they override them with a custom value. The code below, a modification of an earlier example sets the ``inputBuffer`` attribute on certain modules, but not on others: -.. includecode:: ../code/docs/stream/CompositionDocTest.java#attributes-inheritance +.. includecode:: ../code/jdocs/stream/CompositionDocTest.java#attributes-inheritance The effect is, that each module inherits the ``inputBuffer`` attribute from its enclosing parent, unless it has the same attribute explicitly set. ``nestedSource`` gets the default attributes from the materializer itself. ``nestedSink`` diff --git a/akka-docs/rst/java/stream/stream-cookbook.rst b/akka-docs/rst/java/stream/stream-cookbook.rst index b44f5d334e..862f04dbe9 100644 --- a/akka-docs/rst/java/stream/stream-cookbook.rst +++ b/akka-docs/rst/java/stream/stream-cookbook.rst @@ -32,12 +32,12 @@ Logging elements of a stream The simplest solution is to simply use a ``map`` operation and use ``println`` to print the elements received to the console. While this recipe is rather simplistic, it is often suitable for a quick debug session. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeLoggingElements.java#println-debug +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java#println-debug Another approach to logging is to use ``log()`` operation which allows configuring logging for elements flowing through the stream as well as completion and erroring. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeLoggingElements.java#log-custom +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeLoggingElements.java#log-custom Flattening a stream of sequences -------------------------------- @@ -49,7 +49,7 @@ The ``mapConcat`` operation can be used to implement a one-to-many transformatio in the form of ``In -> List``. In this case we want to map a ``List`` of elements to the elements in the collection itself, so we can just call ``mapConcat(l -> l)``. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeFlattenList.java#flattening-lists +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeFlattenList.java#flattening-lists Draining a stream to a strict collection ---------------------------------------- @@ -63,11 +63,11 @@ The function ``limit`` or ``take`` should always be used in conjunction in order For example, this is best avoided: -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeSeq.java#draining-to-list-unsafe +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeSeq.java#draining-to-list-unsafe Rather, use ``limit`` or ``take`` to ensure that the resulting ``List`` will contain only up to ``MAX_ALLOWED_SIZE`` elements: -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeSeq.java#draining-to-list-safe +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeSeq.java#draining-to-list-safe Calculating the digest of a ByteString stream --------------------------------------------- @@ -85,9 +85,9 @@ At this point we want to emit the digest value, but we cannot do it with ``push` be no downstream demand. Instead we call ``emit`` which will temporarily replace the handlers, emit the provided value when demand comes in and then reset the stage state. It will then complete the stage. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeDigest.java#calculating-digest +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeDigest.java#calculating-digest -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeDigest.java#calculating-digest2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeDigest.java#calculating-digest2 .. _cookbook-parse-lines-java: @@ -100,7 +100,7 @@ needs to be parsed. The :class:`Framing` helper class contains a convenience method to parse messages from a stream of ``ByteString`` s: -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeParseLines.java#parse-lines +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeParseLines.java#parse-lines Dealing with compressed data streams ------------------------------------ @@ -110,7 +110,7 @@ Dealing with compressed data streams The :class:`Compression` helper class contains convenience methods for decompressing data streams compressed with Gzip or Deflate. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeDecompress.java#decompress-gzip +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeDecompress.java#decompress-gzip Implementing reduce-by-key @@ -141,7 +141,7 @@ If the ``groupBy`` operator encounters more keys than this number then the stream cannot continue without violating its resource bound, in this case ``groupBy`` will terminate with a failure. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java#word-count +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java#word-count By extracting the parts specific to *wordcount* into @@ -151,9 +151,9 @@ By extracting the parts specific to *wordcount* into we get a generalized version below: -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java#reduce-by-key-general +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java#reduce-by-key-general -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java#reduce-by-key-general2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeReduceByKeyTest.java#reduce-by-key-general2 .. note:: Please note that the reduce-by-key version we discussed above is sequential @@ -174,7 +174,7 @@ To achieve the desired result, we attack the problem in two steps: * Then we take this new stream of message topic pairs (containing a separate pair for each topic a given message belongs to) and feed it into groupBy, using the topic as the group key. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java#multi-groupby +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeMultiGroupByTest.java#multi-groupby Working with Graphs =================== @@ -191,14 +191,14 @@ trigger signal arrives. This recipe solves the problem by simply zipping the stream of ``Message`` elements with the stream of ``Trigger`` signals. Since ``Zip`` produces pairs, we simply map the output stream selecting the first element of the pair. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeManualTrigger.java#manually-triggered-stream +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java#manually-triggered-stream Alternatively, instead of using a ``Zip``, and then using ``map`` to get the first element of the pairs, we can avoid creating the pairs in the first place by using ``ZipWith`` which takes a two argument function to produce the output element. If this function would return a pair of the two argument it would be exactly the behavior of ``Zip`` so ``ZipWith`` is a generalization of zipping. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeManualTrigger.java#manually-triggered-stream-zipwith +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeManualTrigger.java#manually-triggered-stream-zipwith Balancing jobs to a fixed pool of workers @@ -217,9 +217,9 @@ we wire the outputs of these workers to a ``Merge`` element that will collect th To make the worker stages run in parallel we mark them as asynchronous with `async()`. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeWorkerPool.java#worker-pool +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java#worker-pool -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeWorkerPool.java#worker-pool2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeWorkerPool.java#worker-pool2 Working with rate ================= @@ -240,7 +240,7 @@ the speed of the upstream unaffected by the downstream. When the upstream is faster, the reducing process of the ``conflate`` starts. Our reducer function simply takes the freshest element. This in a simple dropping operation. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeSimpleDrop.java#simple-drop +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeSimpleDrop.java#simple-drop There is a version of ``conflate`` named ``conflateWithSeed`` that allows to express more complex aggregations, more similar to a ``fold``. @@ -258,9 +258,9 @@ defining a dropping strategy instead of the default ``Backpressure``. This allow between the different consumers (the buffer smooths out small rate variances), but also allows faster consumers to progress by dropping from the buffer of the slow consumers if necessary. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java#droppy-bcast +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java#droppy-bcast -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java#droppy-bcast2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeDroppyBroadcast.java#droppy-bcast2 Collecting missed ticks ----------------------- @@ -280,7 +280,7 @@ We will use ``conflateWithSeed`` to solve the problem. Conflate takes two functi As a result, we have a flow of ``Int`` where the number represents the missed ticks. A number 0 means that we were able to consume the tick fast enough (i.e. zero means: 1 non-missed tick + 0 missed ticks) -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeMissedTicks.java#missed-ticks +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeMissedTicks.java#missed-ticks Create a stream processor that repeats the last element seen ------------------------------------------------------------ @@ -295,7 +295,7 @@ to feed the downstream if no upstream element is ready yet. In the ``onPush()`` ``currentValue`` variable and immediately relieve the upstream by calling ``pull()``. The downstream ``onPull`` handler is very similar, we immediately relieve the downstream by emitting ``currentValue``. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeHold.java#hold-version-1 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeHold.java#hold-version-1 While it is relatively simple, the drawback of the first version is that it needs an arbitrary initial element which is not always possible to provide. Hence, we create a second version where the downstream might need to wait in one single @@ -308,7 +308,7 @@ version is that we check if we have received the first value and only emit if we first element comes in we must check if there possibly already was demand from downstream so that we in that case can push the element directly. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeHold.java#hold-version-2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeHold.java#hold-version-2 Globally limiting the rate of a set of streams ---------------------------------------------- @@ -329,13 +329,13 @@ of the sender is added to a queue. Once the timer for replenishing the pending p message, we increment the pending permits counter and send a reply to each of the waiting senders. If there are more waiting senders than permits available we will stay in the ``closed`` state. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java#global-limiter-actor +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java#global-limiter-actor To create a Flow that uses this global limiter actor we use the ``mapAsync`` function with the combination of the ``ask`` pattern. We also define a timeout, so if a reply is not received during the configured maximum wait period the returned future from ``ask`` will fail, which will fail the corresponding stream as well. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java#global-limiter-flow +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeGlobalRateLimit.java#global-limiter-flow .. note:: The global actor used for limiting introduces a global bottleneck. You might want to assign a dedicated dispatcher @@ -361,9 +361,9 @@ which implements the following logic: Both ``onPush()`` and ``onPull()`` calls ``emitChunk()`` the only difference is that the push handler also stores the incoming chunk by appending to the end of the buffer. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeByteStrings.java#bytestring-chunker +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java#bytestring-chunker -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeByteStrings.java#bytestring-chunker2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java#bytestring-chunker2 Limit the number of bytes passing through a stream of ByteStrings ----------------------------------------------------------------- @@ -375,9 +375,9 @@ This recipe uses a :class:`GraphStage` to implement the desired feature. In the ``onPush()`` we just update a counter and see if it gets larger than ``maximumBytes``. If a violation happens we signal failure, otherwise we forward the chunk we have received. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeByteStrings.java#bytes-limiter +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java#bytes-limiter -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeByteStrings.java#bytes-limiter2 +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java#bytes-limiter2 Compact ByteStrings in a stream of ByteStrings ---------------------------------------------- @@ -389,7 +389,7 @@ chain we want to have clean copies that are no longer referencing the original ` The recipe is a simple use of map, calling the ``compact()`` method of the :class:`ByteString` elements. This does copying of the underlying arrays, so this should be the last element of a long chain if used. -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeByteStrings.java#compacting-bytestrings +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeByteStrings.java#compacting-bytestrings Injecting keep-alive messages into a stream of ByteStrings ---------------------------------------------------------- @@ -399,4 +399,4 @@ but only if this does not interfere with normal traffic. There is a built-in operation that allows to do this directly: -.. includecode:: ../code/docs/stream/javadsl/cookbook/RecipeKeepAlive.java#inject-keepalive +.. includecode:: ../code/jdocs/stream/javadsl/cookbook/RecipeKeepAlive.java#inject-keepalive diff --git a/akka-docs/rst/java/stream/stream-customize.rst b/akka-docs/rst/java/stream/stream-customize.rst index 48ed03029b..3fb422796e 100644 --- a/akka-docs/rst/java/stream/stream-customize.rst +++ b/akka-docs/rst/java/stream/stream-customize.rst @@ -29,7 +29,7 @@ As a first motivating example, we will build a new :class:`Source` that will sim cancelled. To start, we need to define the "interface" of our stage, which is called *shape* in Akka Streams terminology (this is explained in more detail in the section :ref:`composition-java`). -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#simple-source +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#simple-source As you see, in itself the :class:`GraphStage` only defines the ports of this stage and a shape that contains the ports. It also has a user implemented method called ``createLogic``. If you recall, stages are reusable in multiple @@ -56,7 +56,7 @@ that they are already usable in many situations, but do not provide the DSL meth ``Source.fromGraph`` (see :ref:`composition-java` for more details about graphs and DSLs). Now we can use the source as any other built-in one: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#simple-source-usage +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#simple-source-usage Similarly, to create a custom :class:`Sink` one can register a subclass :class:`InHandler` with the stage :class:`Inlet`. The ``onPush()`` callback is used to signal the handler a new element has been pushed to the stage, @@ -64,7 +64,7 @@ and can hence be grabbed and used. ``onPush()`` can be overridden to provide cus Please note, most Sinks would need to request upstream elements as soon as they are created: this can be done by calling ``pull(inlet)`` in the ``preStart()`` callback. -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#simple-sink +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#simple-sink Port states, AbstractInHandler and AbstractOutHandler ----------------------------------------------------- @@ -199,7 +199,7 @@ To illustrate these concepts we create a small :class:`GraphStage` that implemen Map calls ``push(out)`` from the ``onPush()`` handler and it also calls ``pull()`` from the ``onPull`` handler resulting in the conceptual wiring above, and fully expressed in code below: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#one-to-one +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#one-to-one Map is a typical example of a one-to-one transformation of a stream where demand is passed along upstream elements passed on downstream. @@ -221,7 +221,7 @@ we return the “ball” to our upstream so that we get the new element. This is example by adding a conditional in the ``onPush`` handler and decide between a ``pull(in)`` or ``push(out)`` call (and of course not having a mapping ``f`` function). -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#many-to-one +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#many-to-one To complete the picture we define a one-to-many transformation as the next step. We chose a straightforward example stage that emits every upstream element twice downstream. The conceptual wiring of this stage looks like this: @@ -238,7 +238,7 @@ This is a stage that has state: an option with the last element it has seen indi has duplicated this last element already or not. We must also make sure to emit the extra element if the upstream completes. -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#one-to-many +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#one-to-many In this case a pull from downstream might be consumed by the stage itself rather than passed along upstream as the stage might contain an element it wants to @@ -251,7 +251,7 @@ This example can be simplified by replacing the usage of a mutable state with ca ``emitMultiple`` which will replace the handlers, emit each of multiple elements and then reinstate the original handlers: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#simpler-one-to-many +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#simpler-one-to-many Finally, to demonstrate all of the stages above, we put them together into a processing chain, which conceptually would correspond to the following structure: @@ -267,7 +267,7 @@ which conceptually would correspond to the following structure: In code this is only a few lines, using the ``via`` use our custom stages in a stream: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#graph-stage-chain +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#graph-stage-chain If we attempt to draw the sequence of events, it shows that there is one "event token" in circulation in a potential chain of stages, just like our conceptual "railroad tracks" representation predicts. @@ -313,7 +313,7 @@ the ``Materializer`` you're using is able to provide you with a logger. The stage then gets access to the ``log`` field which it can safely use from any ``GraphStage`` callbacks: -.. includecode:: ../code/docs/stream/GraphStageLoggingDocTest.java#stage-with-logging +.. includecode:: ../code/jdocs/stream/GraphStageLoggingDocTest.java#stage-with-logging .. note:: **SPI Note:** If you're implementing a Materializer, you can add this ability to your materializer by implementing @@ -336,7 +336,7 @@ In this sample the stage toggles between open and closed, where open means no el stage starts out as closed but as soon as an element is pushed downstream the gate becomes open for a duration of time during which it will consume and drop upstream messages: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#timed +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#timed Using asynchronous side-channels -------------------------------- @@ -355,7 +355,7 @@ Sharing the AsyncCallback from the constructor risks race conditions, therefore This example shows an asynchronous side channel graph stage that starts dropping elements when a future completes: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#async-side-channel +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#async-side-channel Integration with actors @@ -391,7 +391,7 @@ stage logic the materialized value must be provided In this sample the materialized value is a future containing the first element to go through the stream: -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#materialized +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#materialized Using attributes to affect the behavior of a stage -------------------------------------------------- @@ -451,7 +451,7 @@ initialization. The buffer has demand for up to two elements without any downstr The following code example demonstrates a buffer class corresponding to the message sequence chart above. -.. includecode:: ../code/docs/stream/GraphStageDocTest.java#detached +.. includecode:: ../code/jdocs/stream/GraphStageDocTest.java#detached Thread safety of custom processing stages ========================================= diff --git a/akka-docs/rst/java/stream/stream-dynamic.rst b/akka-docs/rst/java/stream/stream-dynamic.rst index df4ac69e4c..16f60cb73f 100644 --- a/akka-docs/rst/java/stream/stream-dynamic.rst +++ b/akka-docs/rst/java/stream/stream-dynamic.rst @@ -34,11 +34,11 @@ below for usage examples. * **Shutdown** -.. includecode:: ../code/docs/stream/KillSwitchDocTest.java#unique-shutdown +.. includecode:: ../code/jdocs/stream/KillSwitchDocTest.java#unique-shutdown * **Abort** -.. includecode:: ../code/docs/stream/KillSwitchDocTest.java#unique-abort +.. includecode:: ../code/jdocs/stream/KillSwitchDocTest.java#unique-abort .. _shared-kill-switch-java: @@ -51,11 +51,11 @@ Refer to the below for usage examples. * **Shutdown** -.. includecode:: ../code/docs/stream/KillSwitchDocTest.java#shared-shutdown +.. includecode:: ../code/jdocs/stream/KillSwitchDocTest.java#shared-shutdown * **Abort** -.. includecode:: ../code/docs/stream/KillSwitchDocTest.java#shared-abort +.. includecode:: ../code/jdocs/stream/KillSwitchDocTest.java#shared-abort .. note:: A ``UniqueKillSwitch`` is always a result of a materialization, whilst ``SharedKillSwitch`` needs to be constructed @@ -79,7 +79,7 @@ producers are backpressured. The hub itself comes as a :class:`Source` to which It is not possible to attach any producers until this :class:`Source` has been materialized (started). This is ensured by the fact that we only get the corresponding :class:`Sink` as a materialized value. Usage might look like this: -.. includecode:: ../code/docs/stream/HubDocTest.java#merge-hub +.. includecode:: ../code/jdocs/stream/HubDocTest.java#merge-hub This sequence, while might look odd at first, ensures proper startup order. Once we get the :class:`Sink`, we can use it as many times as wanted. Everything that is fed to it will be delivered to the consumer we attached @@ -93,7 +93,7 @@ rate of the producer will be automatically adapted to the slowest consumer. In t to which the single producer must be attached first. Consumers can only be attached once the :class:`Sink` has been materialized (i.e. the producer has been started). One example of using the :class:`BroadcastHub`: -.. includecode:: ../code/docs/stream/HubDocTest.java#broadcast-hub +.. includecode:: ../code/jdocs/stream/HubDocTest.java#broadcast-hub The resulting :class:`Source` can be materialized any number of times, each materialization effectively attaching a new subscriber. If there are no subscribers attached to this hub then it will not drop any elements but instead @@ -114,13 +114,13 @@ First, we connect a :class:`MergeHub` and a :class:`BroadcastHub` together to fo we materialize this small stream, we get back a pair of :class:`Source` and :class:`Sink` that together define the publish and subscribe sides of our channel. -.. includecode:: ../code/docs/stream/HubDocTest.java#pub-sub-1 +.. includecode:: ../code/jdocs/stream/HubDocTest.java#pub-sub-1 We now use a few tricks to add more features. First of all, we attach a ``Sink.ignore`` at the broadcast side of the channel to keep it drained when there are no subscribers. If this behavior is not the desired one this line can be simply dropped. -.. includecode:: ../code/docs/stream/HubDocTest.java#pub-sub-2 +.. includecode:: ../code/jdocs/stream/HubDocTest.java#pub-sub-2 We now wrap the :class:`Sink` and :class:`Source` in a :class:`Flow` using ``Flow.fromSinkAndSource``. This bundles up the two sides of the channel into one and forces users of it to always define a publisher and subscriber side @@ -130,11 +130,11 @@ same time. Finally, we add ``backpressureTimeout`` on the consumer side to ensure that subscribers that block the channel for more than 3 seconds are forcefully removed (and their stream failed). -.. includecode:: ../code/docs/stream/HubDocTest.java#pub-sub-3 +.. includecode:: ../code/jdocs/stream/HubDocTest.java#pub-sub-3 The resulting Flow now has a type of ``Flow[String, String, UniqueKillSwitch]`` representing a publish-subscribe channel which can be used any number of times to attach new producers or consumers. In addition, it materializes to a :class:`UniqueKillSwitch` (see :ref:`unique-kill-switch-java`) that can be used to deregister a single user externally: -.. includecode:: ../code/docs/stream/HubDocTest.java#pub-sub-4 +.. includecode:: ../code/jdocs/stream/HubDocTest.java#pub-sub-4 diff --git a/akka-docs/rst/java/stream/stream-error.rst b/akka-docs/rst/java/stream/stream-error.rst index c7dbde6d2d..a701b6f648 100644 --- a/akka-docs/rst/java/stream/stream-error.rst +++ b/akka-docs/rst/java/stream/stream-error.rst @@ -28,11 +28,11 @@ There are three ways to handle exceptions from application code: By default the stopping strategy is used for all exceptions, i.e. the stream will be completed with failure when an exception is thrown. -.. includecode:: ../code/docs/stream/FlowErrorDocTest.java#stop +.. includecode:: ../code/jdocs/stream/FlowErrorDocTest.java#stop The default supervision strategy for a stream can be defined on the settings of the materializer. -.. includecode:: ../code/docs/stream/FlowErrorDocTest.java#resume +.. includecode:: ../code/jdocs/stream/FlowErrorDocTest.java#resume Here you can see that all ``ArithmeticException`` will resume the processing, i.e. the elements that cause the division by zero are effectively dropped. @@ -44,12 +44,12 @@ elements that cause the division by zero are effectively dropped. The supervision strategy can also be defined for all operators of a flow. -.. includecode:: ../code/docs/stream/FlowErrorDocTest.java#resume-section +.. includecode:: ../code/jdocs/stream/FlowErrorDocTest.java#resume-section ``Restart`` works in a similar way as ``Resume`` with the addition that accumulated state, if any, of the failing processing stage will be reset. -.. includecode:: ../code/docs/stream/FlowErrorDocTest.java#restart-section +.. includecode:: ../code/jdocs/stream/FlowErrorDocTest.java#restart-section Errors from mapAsync ==================== @@ -61,11 +61,11 @@ discard those that cannot be found. We start with the tweet stream of authors: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#tweet-authors +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#tweet-authors Assume that we can lookup their email address using: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#email-address-lookup2 +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#email-address-lookup2 The ``CompletionStage`` is completed normally if the email is not found. @@ -73,7 +73,7 @@ Transforming the stream of authors to a stream of email addresses by using the ` service can be done with ``mapAsync`` and we use ``Supervision.getResumingDecider`` to drop unknown email addresses: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#email-addresses-mapAsync-supervision +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#email-addresses-mapAsync-supervision If we would not use ``Resume`` the default stopping strategy would complete the stream with failure on the first ``CompletionStage`` that was completed exceptionally. diff --git a/akka-docs/rst/java/stream/stream-flows-and-basics.rst b/akka-docs/rst/java/stream/stream-flows-and-basics.rst index 0f17291a1a..81e7c0767b 100644 --- a/akka-docs/rst/java/stream/stream-flows-and-basics.rst +++ b/akka-docs/rst/java/stream/stream-flows-and-basics.rst @@ -75,7 +75,7 @@ starting up Actors). Thanks to Flows being simply a description of the processin thread-safe, and freely shareable*, which means that it is for example safe to share and send them between actors, to have one actor prepare the work, and then have it be materialized at some completely different place in the code. -.. includecode:: ../code/docs/stream/FlowDocTest.java#materialization-in-steps +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#materialization-in-steps After running (materializing) the ``RunnableGraph`` we get a special container object, the ``MaterializedMap``. Both sources and sinks are able to put specific objects into this map. Whether they put something in or not is implementation @@ -86,12 +86,12 @@ there is a convenience method called ``runWith()`` available for ``Sink``, ``Sou a supplied ``Source`` (in order to run a ``Sink``), a ``Sink`` (in order to run a ``Source``) or both a ``Source`` and a ``Sink`` (in order to run a ``Flow``, since it has neither attached yet). -.. includecode:: ../code/docs/stream/FlowDocTest.java#materialization-runWith +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#materialization-runWith It is worth pointing out that since processing stages are *immutable*, connecting them returns a new processing stage, instead of modifying the existing instance, so while constructing long flows, remember to assign the new value to a variable or run it: -.. includecode:: ../code/docs/stream/FlowDocTest.java#source-immutable +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#source-immutable .. note:: By default Akka Streams elements support **exactly one** downstream processing stage. @@ -107,7 +107,7 @@ In the example below we create two running materialized instance of the stream t variable, and both materializations give us a different ``CompletionStage`` from the map even though we used the same ``sink`` to refer to the future: -.. includecode:: ../code/docs/stream/FlowDocTest.java#stream-reuse +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#stream-reuse Defining sources, sinks and flows --------------------------------- @@ -115,11 +115,11 @@ Defining sources, sinks and flows The objects :class:`Source` and :class:`Sink` define various ways to create sources and sinks of elements. The following examples show some of the most useful constructs (refer to the API documentation for more details): -.. includecode:: ../code/docs/stream/FlowDocTest.java#source-sink +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#source-sink There are various ways to wire up different parts of a stream, the following examples show some of the available options: -.. includecode:: ../code/docs/stream/FlowDocTest.java#flow-connecting +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#flow-connecting Illegal stream elements ----------------------- @@ -239,7 +239,7 @@ To allow for parallel processing you will have to insert asynchronous boundaries graphs by way of adding ``Attributes.asyncBoundary`` using the method ``async`` on ``Source``, ``Sink`` and ``Flow`` to pieces that shall communicate with the rest of the graph in an asynchronous fashion. -.. includecode:: ../code/docs/stream/FlowDocTest.java#flow-async +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#flow-async In this example we create two regions within the flow which will be executed in one Actor each—assuming that adding and multiplying integers is an extremely costly operation this will lead to a performance gain since two CPUs can @@ -280,7 +280,7 @@ to somehow express how these values should be composed to a final value when we many combinator methods have variants that take an additional argument, a function, that will be used to combine the resulting values. Some examples of using these combiners are illustrated in the example below. -.. includecode:: ../code/docs/stream/FlowDocTest.java#flow-mat-combine +.. includecode:: ../code/jdocs/stream/FlowDocTest.java#flow-mat-combine .. note:: diff --git a/akka-docs/rst/java/stream/stream-graphs.rst b/akka-docs/rst/java/stream/stream-graphs.rst index 2c5675e034..8c71ea12c3 100644 --- a/akka-docs/rst/java/stream/stream-graphs.rst +++ b/akka-docs/rst/java/stream/stream-graphs.rst @@ -51,7 +51,7 @@ Such graph is simple to translate to the Graph DSL since each linear element cor and each circle corresponds to either a :class:`Junction` or a :class:`Source` or :class:`Sink` if it is beginning or ending a :class:`Flow`. -.. includecode:: ../code/docs/stream/GraphDSLDocTest.java#simple-graph-dsl +.. includecode:: ../code/jdocs/stream/GraphDSLDocTest.java#simple-graph-dsl .. note:: Junction *reference equality* defines *graph node equality* (i.e. the same merge *instance* used in a GraphDSL @@ -75,7 +75,7 @@ In the example below we prepare a graph that consists of two parallel streams, in which we re-use the same instance of :class:`Flow`, yet it will properly be materialized as two connections between the corresponding Sources and Sinks: -.. includecode:: ../code/docs/stream/GraphDSLDocTest.java#graph-dsl-reusing-a-flow +.. includecode:: ../code/jdocs/stream/GraphDSLDocTest.java#graph-dsl-reusing-a-flow .. _partial-graph-dsl-java: @@ -97,7 +97,7 @@ Let's imagine we want to provide users with a specialized element that given 3 i the greatest int value of each zipped triple. We'll want to expose 3 input ports (unconnected sources) and one output port (unconnected sink). -.. includecode:: ../code/docs/stream/StreamPartialGraphDSLDocTest.java#simple-partial-graph-dsl +.. includecode:: ../code/jdocs/stream/StreamPartialGraphDSLDocTest.java#simple-partial-graph-dsl As you can see, first we construct the partial graph that describes how to compute the maximum of two input streams, then we reuse that twice while constructing the partial graph that extends this to three input streams, @@ -136,12 +136,12 @@ be attached before this Source can run”. Refer to the example below, in which we create a Source that zips together two numbers, to see this graph construction in action: -.. includecode:: ../code/docs/stream/StreamPartialGraphDSLDocTest.java#source-from-partial-graph-dsl +.. includecode:: ../code/jdocs/stream/StreamPartialGraphDSLDocTest.java#source-from-partial-graph-dsl Similarly the same can be done for a ``Sink`` using ``SinkShape.of`` in which case the provided value must be an ``Inlet``. For defining a ``Flow`` we need to expose both an undefined source and sink: -.. includecode:: ../code/docs/stream/StreamPartialGraphDSLDocTest.java#flow-from-partial-graph-dsl +.. includecode:: ../code/jdocs/stream/StreamPartialGraphDSLDocTest.java#flow-from-partial-graph-dsl Combining Sources and Sinks with simplified API ----------------------------------------------- @@ -150,11 +150,11 @@ There is simplified API you can use to combine sources and sinks with junctions ``Merge`` and ``Concat`` without the need for using the Graph DSL. The combine method takes care of constructing the necessary graph underneath. In following example we combine two sources into one (fan-in): -.. includecode:: ../code/docs/stream/StreamPartialGraphDSLDocTest.java#source-combine +.. includecode:: ../code/jdocs/stream/StreamPartialGraphDSLDocTest.java#source-combine The same can be done for a ``Sink`` but in this case it will be fan-out: -.. includecode:: ../code/docs/stream/StreamPartialGraphDSLDocTest.java#sink-combine +.. includecode:: ../code/jdocs/stream/StreamPartialGraphDSLDocTest.java#sink-combine .. _bidi-flow-java: @@ -178,7 +178,7 @@ called :class:`BidiShape` and is defined like this: A bidirectional flow is defined just like a unidirectional :class:`Flow` as demonstrated for the codec mentioned above: -.. includecode:: ../code/docs/stream/BidiFlowDocTest.java +.. includecode:: ../code/jdocs/stream/BidiFlowDocTest.java :include: codec :exclude: implementation-details-elided @@ -187,7 +187,7 @@ case of a functional 1:1 transformation there is a concise convenience method as shown on the last line. The implementation of the two functions is not difficult either: -.. includecode:: ../code/docs/stream/BidiFlowDocTest.java#codec-impl +.. includecode:: ../code/jdocs/stream/BidiFlowDocTest.java#codec-impl In this way you could easily integrate any other serialization library that turns an object into a sequence of bytes. @@ -197,11 +197,11 @@ a framing protocol means that any received chunk of bytes may correspond to zero or more messages. This is best implemented using a :class:`GraphStage` (see also :ref:`graphstage-java`). -.. includecode:: ../code/docs/stream/BidiFlowDocTest.java#framing +.. includecode:: ../code/jdocs/stream/BidiFlowDocTest.java#framing With these implementations we can build a protocol stack and test it: -.. includecode:: ../code/docs/stream/BidiFlowDocTest.java#compose +.. includecode:: ../code/jdocs/stream/BidiFlowDocTest.java#compose This example demonstrates how :class:`BidiFlow` subgraphs can be hooked together and also turned around with the ``.reversed()`` method. The test @@ -219,12 +219,12 @@ can be used in the graph as an ordinary source or outlet, and which will eventua If the materialized value is needed at more than one place, it is possible to call ``materializedValue`` any number of times to acquire the necessary number of outlets. -.. includecode:: ../code/docs/stream/GraphDSLDocTest.java#graph-dsl-matvalue +.. includecode:: ../code/jdocs/stream/GraphDSLDocTest.java#graph-dsl-matvalue Be careful not to introduce a cycle where the materialized value actually contributes to the materialized value. The following example demonstrates a case where the materialized ``CompletionStage`` of a fold is fed back to the fold itself. -.. includecode:: ../code/docs/stream/GraphDSLDocTest.java#graph-dsl-matvalue-cycle +.. includecode:: ../code/jdocs/stream/GraphDSLDocTest.java#graph-dsl-matvalue-cycle .. _graph-cycles-java: @@ -243,7 +243,7 @@ The graph takes elements from the source, prints them, then broadcasts those ele to a consumer (we just used ``Sink.ignore`` for now) and to a feedback arc that is merged back into the main via a ``Merge`` junction. -.. includecode:: ../code/docs/stream/GraphCyclesDocTest.java#deadlocked +.. includecode:: ../code/jdocs/stream/GraphCyclesDocTest.java#deadlocked Running this we observe that after a few numbers have been printed, no more elements are logged to the console - all processing stops after some time. After some investigation we observe that: @@ -261,7 +261,7 @@ If we modify our feedback loop by replacing the ``Merge`` junction with a ``Merg before trying the other lower priority input ports. Since we feed back through the preferred port it is always guaranteed that the elements in the cycles can flow. -.. includecode:: ../code/docs/stream/GraphCyclesDocTest.java#unfair +.. includecode:: ../code/jdocs/stream/GraphCyclesDocTest.java#unfair If we run the example we see that the same sequence of numbers are printed over and over again, but the processing does not stop. Hence, we avoided the deadlock, but ``source`` is still @@ -276,7 +276,7 @@ of initial elements from ``source``. To make our cycle both live (not deadlocking) and fair we can introduce a dropping element on the feedback arc. In this case we chose the ``buffer()`` operation giving it a dropping strategy ``OverflowStrategy.dropHead``. -.. includecode:: ../code/docs/stream/GraphCyclesDocTest.java#dropping +.. includecode:: ../code/jdocs/stream/GraphCyclesDocTest.java#dropping If we run this example we see that @@ -295,7 +295,7 @@ the beginning instead. To achieve this we modify our first graph by replacing th Since ``ZipWith`` takes one element from ``source`` *and* from the feedback arc to inject one element into the cycle, we maintain the balance of elements. -.. includecode:: ../code/docs/stream/GraphCyclesDocTest.java#zipping-dead +.. includecode:: ../code/jdocs/stream/GraphCyclesDocTest.java#zipping-dead Still, when we try to run the example it turns out that no element is printed at all! After some investigation we realize that: @@ -307,7 +307,7 @@ These two conditions are a typical "chicken-and-egg" problem. The solution is to element into the cycle that is independent from ``source``. We do this by using a ``Concat`` junction on the backwards arc that injects a single element using ``Source.single``. -.. includecode:: ../code/docs/stream/GraphCyclesDocTest.java#zipping-live +.. includecode:: ../code/jdocs/stream/GraphCyclesDocTest.java#zipping-live When we run the above example we see that processing starts and never stops. The important takeaway from this example is that balanced cycles often need an initial "kick-off" element to be injected into the cycle. diff --git a/akka-docs/rst/java/stream/stream-integrations.rst b/akka-docs/rst/java/stream/stream-integrations.rst index bdc7645c50..6f46ed73cc 100644 --- a/akka-docs/rst/java/stream/stream-integrations.rst +++ b/akka-docs/rst/java/stream/stream-integrations.rst @@ -21,7 +21,7 @@ use ``ask`` in ``mapAsync``. The back-pressure of the stream is maintained by the ``CompletionStage`` of the ``ask`` and the mailbox of the actor will not be filled with more messages than the given ``parallelism`` of the ``mapAsync`` stage. -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#mapAsync-ask +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#mapAsync-ask Note that the messages received in the actor will be in the same order as the stream elements, i.e. the ``parallelism`` does not change the ordering @@ -30,11 +30,11 @@ even though the actor will only process one message at a time because then there is already a message in the mailbox when the actor has completed previous message. -The actor must reply to the ``sender()`` for each message from the stream. That +The actor must reply to the ``getSender()`` for each message from the stream. That reply will complete the ``CompletionStage`` of the ``ask`` and it will be the element that is emitted downstreams from ``mapAsync``. -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#ask-actor +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#ask-actor The stream can be completed with failure by sending ``akka.actor.Status.Failure`` as reply from the actor. @@ -121,24 +121,24 @@ performed with ``mapAsync`` or ``mapAsyncUnordered``. For example, sending emails to the authors of selected tweets using an external email service: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#email-server-send +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#email-server-send We start with the tweet stream of authors: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#tweet-authors +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#tweet-authors Assume that we can lookup their email address using: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#email-address-lookup +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#email-address-lookup Transforming the stream of authors to a stream of email addresses by using the ``lookupEmail`` service can be done with ``mapAsync``: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#email-addresses-mapAsync +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#email-addresses-mapAsync Finally, sending the emails: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#send-emails +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#send-emails ``mapAsync`` is applying the given function that is calling out to the external service to each of the elements as they pass through this processing step. The function returns a :class:`CompletionStage` @@ -160,14 +160,14 @@ result stream onwards for further processing or storage. Note that ``mapAsync`` preserves the order of the stream elements. In this example the order is not important and then we can use the more efficient ``mapAsyncUnordered``: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#external-service-mapAsyncUnordered +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#external-service-mapAsyncUnordered In the above example the services conveniently returned a :class:`CompletionStage` of the result. If that is not the case you need to wrap the call in a :class:`CompletionStage`. If the service call involves blocking you must also make sure that you run it on a dedicated execution context, to avoid starvation and disturbance of other tasks in the system. -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#blocking-mapAsync +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#blocking-mapAsync The configuration of the ``"blocking-dispatcher"`` may look something like: @@ -176,7 +176,7 @@ The configuration of the ``"blocking-dispatcher"`` may look something like: An alternative for blocking calls is to perform them in a ``map`` operation, still using a dedicated dispatcher for that operation. -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#blocking-map +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#blocking-map However, that is not exactly the same as ``mapAsync``, since the ``mapAsync`` may run several calls concurrently, but ``map`` performs them one at a time. @@ -184,7 +184,7 @@ several calls concurrently, but ``map`` performs them one at a time. For a service that is exposed as an actor, or if an actor is used as a gateway in front of an external service, you can use ``ask``: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#save-tweets +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#save-tweets Note that if the ``ask`` is not completed within the given timeout the stream is completed with failure. If that is not desired outcome you can use ``recover`` on the ``ask`` :class:`CompletionStage`. @@ -213,14 +213,14 @@ successive calls as long as there is downstream demand of several elements. Here is a fictive service that we can use to illustrate these aspects. -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#sometimes-slow-service +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#sometimes-slow-service Elements starting with a lower case character are simulated to take longer time to process. Here is how we can use it with ``mapAsync``: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#sometimes-slow-mapAsync +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#sometimes-slow-mapAsync The output may look like this: @@ -277,7 +277,7 @@ calls are limited by the buffer size (4) of the :class:`ActorMaterializerSetting Here is how we can use the same service with ``mapAsyncUnordered``: -.. includecode:: ../code/docs/stream/IntegrationDocTest.java#sometimes-slow-mapAsyncUnordered +.. includecode:: ../code/jdocs/stream/IntegrationDocTest.java#sometimes-slow-mapAsyncUnordered The output may look like this: @@ -355,19 +355,19 @@ An incomplete list of other implementations: The two most important interfaces in Reactive Streams are the :class:`Publisher` and :class:`Subscriber`. -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#imports +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#imports Let us assume that a library provides a publisher of tweets: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#tweets-publisher +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#tweets-publisher and another library knows how to store author handles in a database: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#author-storage-subscriber +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#author-storage-subscriber Using an Akka Streams :class:`Flow` we can transform the stream and connect those: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java :include: authors,connect-all The :class:`Publisher` is used as an input :class:`Source` to the flow and the @@ -377,24 +377,24 @@ A :class:`Flow` can also be also converted to a :class:`RunnableGraph[Processor[ materializes to a :class:`Processor` when ``run()`` is called. ``run()`` itself can be called multiple times, resulting in a new :class:`Processor` instance each time. -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#flow-publisher-subscriber +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#flow-publisher-subscriber A publisher can be connected to a subscriber with the ``subscribe`` method. It is also possible to expose a :class:`Source` as a :class:`Publisher` by using the Publisher-:class:`Sink`: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#source-publisher +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#source-publisher A publisher that is created with ``Sink.asPublisher(AsPublisher.WITHOUT_FANOUT)`` supports only a single subscription. Additional subscription attempts will be rejected with an :class:`IllegalStateException`. A publisher that supports multiple subscribers using fan-out/broadcasting is created as follows: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java :include: author-alert-subscriber,author-storage-subscriber -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#source-fanoutPublisher +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#source-fanoutPublisher The input buffer size of the stage controls how far apart the slowest subscriber can be from the fastest subscriber before slowing down the stream. @@ -402,12 +402,12 @@ before slowing down the stream. To make the picture complete, it is also possible to expose a :class:`Sink` as a :class:`Subscriber` by using the Subscriber-:class:`Source`: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#sink-subscriber +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#sink-subscriber It is also possible to use re-wrap :class:`Processor` instances as a :class:`Flow` by passing a factory function that will create the :class:`Processor` instances: -.. includecode:: ../code/docs/stream/ReactiveStreamsDocTest.java#use-processor +.. includecode:: ../code/jdocs/stream/ReactiveStreamsDocTest.java#use-processor Please note that a factory is necessary to achieve reusability of the resulting :class:`Flow`. @@ -450,7 +450,7 @@ stream publisher that keeps track of the subscription life cycle and requested e Here is an example of such an actor. It dispatches incoming jobs to the attached subscriber: -.. includecode:: ../code/docs/stream/ActorPublisherDocTest.java#job-manager +.. includecode:: ../code/jdocs/stream/ActorPublisherDocTest.java#job-manager You send elements to the stream by calling ``onNext``. You are allowed to send as many elements as have been requested by the stream subscriber. This amount can be inquired with @@ -482,7 +482,7 @@ More detailed information can be found in the API documentation. This is how it can be used as input :class:`Source` to a :class:`Flow`: -.. includecode:: ../code/docs/stream/ActorPublisherDocTest.java#actor-publisher-usage +.. includecode:: ../code/jdocs/stream/ActorPublisherDocTest.java#actor-publisher-usage You can only attach one subscriber to this publisher. Use a ``Broadcast``-element or attach a ``Sink.asPublisher(AsPublisher.WITH_FANOUT)`` to enable multiple subscribers. @@ -505,7 +505,7 @@ messages from the stream. It can also receive other, non-stream messages, in the Here is an example of such an actor. It dispatches incoming jobs to child worker actors: -.. includecode:: ../code/docs/stream/ActorSubscriberDocTest.java#worker-pool +.. includecode:: ../code/jdocs/stream/ActorSubscriberDocTest.java#worker-pool Subclass must define the ``RequestStrategy`` to control stream back pressure. After each incoming message the ``AbstractActorSubscriber`` will automatically invoke @@ -523,4 +523,4 @@ More detailed information can be found in the API documentation. This is how it can be used as output :class:`Sink` to a :class:`Flow`: -.. includecode:: ../code/docs/stream/ActorSubscriberDocTest.java#actor-subscriber-usage +.. includecode:: ../code/jdocs/stream/ActorSubscriberDocTest.java#actor-subscriber-usage diff --git a/akka-docs/rst/java/stream/stream-io.rst b/akka-docs/rst/java/stream/stream-io.rst index 0e1080bf77..b80f421b15 100644 --- a/akka-docs/rst/java/stream/stream-io.rst +++ b/akka-docs/rst/java/stream/stream-io.rst @@ -17,7 +17,7 @@ Accepting connections: Echo Server In order to implement a simple EchoServer we ``bind`` to a given address, which returns a ``Source>``, which will emit an :class:`IncomingConnection` element for each new connection that the Server should handle: -.. includecode:: ../code/docs/stream/io/StreamTcpDocTest.java#echo-server-simple-bind +.. includecode:: ../code/jdocs/stream/io/StreamTcpDocTest.java#echo-server-simple-bind .. image:: ../../images/tcp-stream-bind.png @@ -28,7 +28,7 @@ helper Flow from ``akka.stream.javadsl.Framing`` to chunk the inputs up into act argument indicates that we require an explicit line ending even for the last message before the connection is closed. In this example we simply add exclamation marks to each incoming text message and push it through the flow: -.. includecode:: ../code/docs/stream/io/StreamTcpDocTest.java#echo-server-simple-handle +.. includecode:: ../code/jdocs/stream/io/StreamTcpDocTest.java#echo-server-simple-handle .. image:: ../../images/tcp-stream-run.png @@ -54,7 +54,7 @@ Let's say we know a server has exposed a simple command line interface over TCP, and would like to interact with it using Akka Streams over TCP. To open an outgoing connection socket we use the ``outgoingConnection`` method: -.. includecode:: ../code/docs/stream/io/StreamTcpDocTest.java#repl-client +.. includecode:: ../code/jdocs/stream/io/StreamTcpDocTest.java#repl-client The ``repl`` flow we use to handle the server interaction first prints the servers response, then awaits on input from the command line (this blocking call is used here just for the sake of simplicity) and converts it to a @@ -86,7 +86,7 @@ Thankfully in most situations finding the right spot to start the conversation i to the protocol we are trying to implement using Streams. In chat-like applications, which our examples resemble, it makes sense to make the Server initiate the conversation by emitting a "hello" message: -.. includecode:: ../code/docs/stream/io/StreamTcpDocTest.java#welcome-banner-chat-server +.. includecode:: ../code/jdocs/stream/io/StreamTcpDocTest.java#welcome-banner-chat-server To emit the initial message we merge a ``Source`` with a single element, after the command processing but before the framing and transformation to ``ByteString`` s this way we do not have to repeat such logic. @@ -105,7 +105,7 @@ on files. Streaming data from a file is as easy as creating a `FileIO.fromPath` given a target path, and an optional ``chunkSize`` which determines the buffer size determined as one "element" in such stream: -.. includecode:: ../code/docs/stream/io/StreamFileDocTest.java#file-source +.. includecode:: ../code/jdocs/stream/io/StreamFileDocTest.java#file-source Please note that these processing stages are backed by Actors and by default are configured to run on a pre-configured threadpool-backed dispatcher dedicated for File IO. This is very important as it isolates the blocking file IO operations from the rest @@ -113,4 +113,4 @@ of the ActorSystem allowing each dispatcher to be utilised in the most efficient dispatcher for file IO operations globally, you can do so by changing the ``akka.stream.blocking-io-dispatcher``, or for a specific stage by specifying a custom Dispatcher in code, like this: -.. includecode:: ../code/docs/stream/io/StreamFileDocTest.java#custom-dispatcher-code +.. includecode:: ../code/jdocs/stream/io/StreamFileDocTest.java#custom-dispatcher-code diff --git a/akka-docs/rst/java/stream/stream-parallelism.rst b/akka-docs/rst/java/stream/stream-parallelism.rst index c505d77e30..2b60e5f63a 100644 --- a/akka-docs/rst/java/stream/stream-parallelism.rst +++ b/akka-docs/rst/java/stream/stream-parallelism.rst @@ -28,7 +28,7 @@ are two pancakes being cooked at the same time, one being cooked on its first si completion. This is how this setup would look like implemented as a stream: -.. includecode:: ../code/docs/stream/FlowParallelismDocTest.java#pipelining +.. includecode:: ../code/jdocs/stream/FlowParallelismDocTest.java#pipelining The two ``map`` stages in sequence (encapsulated in the "frying pan" flows) will be executed in a pipelined way, basically doing the same as Roland with his frying pans: @@ -57,7 +57,7 @@ the results on a shared plate. Whenever a pan becomes empty, he takes the next s In essence he parallelizes the same process over multiple pans. This is how this setup will look like if implemented using streams: -.. includecode:: ../code/docs/stream/FlowParallelismDocTest.java#parallelism +.. includecode:: ../code/jdocs/stream/FlowParallelismDocTest.java#parallelism The benefit of parallelizing is that it is easy to scale. In the pancake example it is easy to add a third frying pan with Patrik's method, but Roland cannot add a third frying pan, @@ -80,7 +80,7 @@ First, let's look at how we can parallelize pipelined processing stages. In the will employ two chefs, each working using Roland's pipelining method, but we use the two chefs in parallel, just like Patrik used the two frying pans. This is how it looks like if expressed as streams: -.. includecode:: ../code/docs/stream/FlowParallelismDocTest.java#parallel-pipeline +.. includecode:: ../code/jdocs/stream/FlowParallelismDocTest.java#parallel-pipeline The above pattern works well if there are many independent jobs that do not depend on the results of each other, but the jobs themselves need multiple processing steps where each step builds on the result of @@ -97,7 +97,7 @@ It is also possible to organize parallelized stages into pipelines. This would m This is again straightforward to implement with the streams API: -.. includecode:: ../code/docs/stream/FlowParallelismDocTest.java#pipelined-parallel +.. includecode:: ../code/jdocs/stream/FlowParallelismDocTest.java#pipelined-parallel This usage pattern is less common but might be usable if a certain step in the pipeline might take wildly different times to finish different jobs. The reason is that there are more balance-merge steps in this pattern diff --git a/akka-docs/rst/java/stream/stream-quickstart.rst b/akka-docs/rst/java/stream/stream-quickstart.rst index d3cc071543..92ef0188df 100644 --- a/akka-docs/rst/java/stream/stream-quickstart.rst +++ b/akka-docs/rst/java/stream/stream-quickstart.rst @@ -6,15 +6,15 @@ Quick Start Guide A stream usually begins at a source, so this is also how we start an Akka Stream. Before we create one, we import the full complement of streaming tools: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#stream-imports +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#stream-imports If you want to execute the code samples while you read through the quick start guide, you will also need the following imports: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#other-imports +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#other-imports Now we will start with a rather simple source, emitting the integers 1 to 100: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#create-source +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#create-source The :class:`Source` type is parameterized with two types: the first one is the type of element that this source emits and the second one may signal that @@ -27,7 +27,7 @@ Having created this source means that we have a description of how to emit the first 100 natural numbers, but this source is not yet active. In order to get those numbers out we have to run it: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#run-source +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#run-source This line will complement the source with a consumer function—in this example we simply print out the numbers to the console—and pass this little stream @@ -39,7 +39,7 @@ You may wonder where the Actor gets created that runs the stream, and you are probably also asking yourself what this ``materializer`` means. In order to get this value we first need to create an Actor system: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#create-materializer +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#create-materializer There are other ways to create a materializer, e.g. from an :class:`ActorContext` when using streams from within Actors. The @@ -53,7 +53,7 @@ description of what you want to run, and like an architect’s blueprint it can be reused, incorporated into a larger design. We may choose to transform the source of integers and write it to a file instead: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#transform-source +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#transform-source First we use the ``scan`` combinator to run a computation over the whole stream: starting with the number 1 (``BigInteger.ONE``) we multiple by each of @@ -81,7 +81,7 @@ language for writing these streams always flows from left to right (just like plain English), we need a starting point that is like a source but with an “open” input. In Akka Streams this is called a :class:`Flow`: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#transform-sink +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#transform-sink Starting from a flow of strings we convert each to :class:`ByteString` and then feed to the already known file-writing :class:`Sink`. The resulting blueprint @@ -97,7 +97,7 @@ We can use the new and shiny :class:`Sink` we just created by attaching it to our ``factorials`` source—after a small adaptation to turn the numbers into strings: -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#use-transformed-sink +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#use-transformed-sink Time-Based Processing --------------------- @@ -110,7 +110,7 @@ number emitted by the ``factorials`` source is the factorial of zero, the second is the factorial of one, and so on. We combine these two by forming strings like ``"3! = 6"``. -.. includecode:: ../code/docs/stream/QuickStartDocTest.java#add-streams +.. includecode:: ../code/jdocs/stream/QuickStartDocTest.java#add-streams All operations so far have been time-independent and could have been performed in the same fashion on strict collections of elements. The next line @@ -153,7 +153,7 @@ allow to control what should happen in such scenarios. Here's the data model we'll be working with throughout the quickstart examples: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#model +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#model .. note:: @@ -169,7 +169,7 @@ like for example finding all twitter handles of users who tweet about ``#akka``. In order to prepare our environment by creating an :class:`ActorSystem` and :class:`ActorMaterializer`, which will be responsible for materializing and running the streams we are about to create: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#materializer-setup +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#materializer-setup The :class:`ActorMaterializer` can optionally take :class:`ActorMaterializerSettings` which can be used to define materialization properties, such as default buffer sizes (see also :ref:`async-stream-buffers-java`), the dispatcher to @@ -177,7 +177,7 @@ be used by the pipeline etc. These can be overridden with ``withAttributes`` on Let's assume we have a stream of tweets readily available. In Akka this is expressed as a :class:`Source`: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#tweet-source +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#tweet-source Streams always start flowing from a ``Source`` then can continue through ``Flow`` elements or more advanced graph elements to finally be consumed by a ``Sink``. @@ -191,7 +191,7 @@ The operations should look familiar to anyone who has used the Scala Collections however they operate on streams and not collections of data (which is a very important distinction, as some operations only make sense in streaming and vice versa): -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#authors-filter-map +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#authors-filter-map Finally in order to :ref:`materialize ` and run the stream computation we need to attach the Flow to a ``Sink`` that will get the Flow running. The simplest way to do this is to call @@ -199,18 +199,18 @@ the Flow to a ``Sink`` that will get the Flow running. The simplest way to the ``Sink class``. For now let's simply print each author: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#authors-foreachsink-println +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#authors-foreachsink-println or by using the shorthand version (which are defined only for the most popular Sinks such as :class:`Sink.fold` and :class:`Sink.foreach`): -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#authors-foreach-println +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#authors-foreach-println Materializing and running a stream always requires a :class:`Materializer` to be passed in explicitly, like this: ``.run(mat)``. The complete snippet looks like this: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#first-sample +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#first-sample Flattening sequences in streams ------------------------------- @@ -219,7 +219,7 @@ we might want to map from one element to a number of elements and receive a "fla works on Scala Collections. In order to get a flattened stream of hashtags from our stream of tweets we can use the ``mapConcat`` combinator: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#hashtags-mapConcat +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#hashtags-mapConcat .. note:: The name ``flatMap`` was consciously avoided due to its proximity with for-comprehensions and monadic composition. @@ -247,7 +247,7 @@ at the expense of not reading as familiarly as collection transformations. Graphs are constructed using :class:`GraphDSL` like this: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#graph-dsl-broadcast +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#graph-dsl-broadcast As you can see, we use graph builder ``b`` to construct the graph using ``UniformFanOutShape`` and ``Flow`` s. @@ -278,7 +278,7 @@ in either ``OutOfMemoryError`` s or other severe degradations of service respons and must be handled explicitly. For example, if we are only interested in the "*most recent tweets, with a buffer of 10 elements*" this can be expressed using the ``buffer`` element: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#tweets-slow-consumption-dropHead +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#tweets-slow-consumption-dropHead The ``buffer`` element takes an explicit and required ``OverflowStrategy``, which defines how the buffer should react when it receives another element while it is full. Strategies provided include dropping the oldest element (``dropHead``), @@ -297,7 +297,7 @@ but in general it is possible to deal with finite streams and come up with a nic First, let's write such an element counter using ``Flow.of(Class)`` and ``Sink.fold`` to see how the types look like: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#tweets-fold-count +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#tweets-fold-count First we prepare a reusable ``Flow`` that will change each incoming tweet into an integer of value ``1``. We'll use this in order to combine those with a ``Sink.fold`` that will sum all ``Integer`` elements of the stream and make its result available as @@ -323,13 +323,13 @@ and materialized multiple times, because it is just the "blueprint" of the strea for example one that consumes a live stream of tweets within a minute, the materialized values for those two materializations will be different, as illustrated by this example: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#tweets-runnable-flow-materialized-twice +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#tweets-runnable-flow-materialized-twice Many elements in Akka Streams provide materialized values which can be used for obtaining either results of computation or steering these elements which will be discussed in detail in :ref:`stream-materialization-java`. Summing up this section, now we know what happens behind the scenes when we run this one-liner, which is equivalent to the multi line version above: -.. includecode:: ../code/docs/stream/TwitterStreamQuickstartDocTest.java#tweets-fold-count-oneline +.. includecode:: ../code/jdocs/stream/TwitterStreamQuickstartDocTest.java#tweets-fold-count-oneline .. note:: ``runWith()`` is a convenience method that automatically ignores the materialized value of any other stages except diff --git a/akka-docs/rst/java/stream/stream-rate.rst b/akka-docs/rst/java/stream/stream-rate.rst index febf3218b8..ee674909cb 100644 --- a/akka-docs/rst/java/stream/stream-rate.rst +++ b/akka-docs/rst/java/stream/stream-rate.rst @@ -19,7 +19,7 @@ To run a stage asynchronously it has to be marked explicitly as such using the ` asynchronously means that a stage, after handing out an element to its downstream consumer is able to immediately process the next message. To demonstrate what we mean by this, let's take a look at the following example: -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#pipelining +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#pipelining Running the above example, one of the possible outputs looks like this: @@ -71,16 +71,16 @@ can be set through configuration: Alternatively they can be set by passing a :class:`ActorMaterializerSettings` to the materializer: -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#materializer-buffer +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#materializer-buffer If the buffer size needs to be set for segments of a :class:`Flow` only, it is possible by defining a separate :class:`Flow` with these attributes: -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#section-buffer +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#section-buffer Here is an example of a code that demonstrate some of the issues caused by internal buffers: -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#buffering-abstraction-leak +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#buffering-abstraction-leak Running the above example one would expect the number *3* to be printed in every 3 seconds (the ``conflateWithSeed`` step here is configured so that it counts the number of elements received before the downstream ``ZipWith`` consumes @@ -103,7 +103,7 @@ pipeline of an application. The example below will ensure that 1000 jobs (but not more) are dequeued from an external (imaginary) system and stored locally in memory - relieving the external system: -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#explicit-buffers-backpressure +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#explicit-buffers-backpressure The next example will also queue up 1000 jobs locally, but if there are more jobs waiting in the imaginary external systems, it makes space for the new element by @@ -111,12 +111,12 @@ dropping one element from the *tail* of the buffer. Dropping from the tail is a it must be noted that this will drop the *youngest* waiting job. If some "fairness" is desired in the sense that we want to be nice to jobs that has been waiting for long, then this option can be useful. -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#explicit-buffers-droptail +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#explicit-buffers-droptail Instead of dropping the youngest element from the tail of the buffer a new element can be dropped without enqueueing it to the buffer at all. -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#explicit-buffers-dropnew +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#explicit-buffers-dropnew Here is another example with a queue of 1000 jobs, but it makes space for the new element by dropping one element from the *head* of the buffer. This is the *oldest* @@ -125,13 +125,13 @@ resent if not processed in a certain period. The oldest element will be retransmitted soon, (in fact a retransmitted duplicate might be already in the queue!) so it makes sense to drop it first. -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#explicit-buffers-drophead +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#explicit-buffers-drophead Compared to the dropping strategies above, dropBuffer drops all the 1000 jobs it has enqueued once the buffer gets full. This aggressive strategy is useful when dropping jobs is preferred to delaying jobs. -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#explicit-buffers-dropbuffer +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#explicit-buffers-dropbuffer If our imaginary external job provider is a client using our API, we might want to enforce that the client cannot have more than 1000 queued jobs @@ -139,7 +139,7 @@ otherwise we consider it flooding and terminate the connection. This is easily achievable by the error strategy which simply fails the stream once the buffer gets full. -.. includecode:: ../code/docs/stream/StreamBuffersRateDocTest.java#explicit-buffers-fail +.. includecode:: ../code/jdocs/stream/StreamBuffersRateDocTest.java#explicit-buffers-fail Rate transformation =================== @@ -153,7 +153,7 @@ useful to combine elements from a producer until a demand signal comes from a co Below is an example snippet that summarizes fast stream of elements to a standard deviation, mean and count of elements that have arrived while the stats have been calculated. -.. includecode:: ../code/docs/stream/RateTransformationDocTest.java#conflate-summarize +.. includecode:: ../code/jdocs/stream/RateTransformationDocTest.java#conflate-summarize This example demonstrates that such flow's rate is decoupled. The element rate at the start of the flow can be much higher that the element rate at the end of the flow. @@ -162,7 +162,7 @@ Another possible use of ``conflate`` is to not consider all elements for summary Example below demonstrates how ``conflate`` can be used to implement random drop of elements when consumer is not able to keep up with the producer. -.. includecode:: ../code/docs/stream/RateTransformationDocTest.java#conflate-sample +.. includecode:: ../code/jdocs/stream/RateTransformationDocTest.java#conflate-sample Understanding expand -------------------- @@ -173,12 +173,12 @@ allows to extrapolate a value to be sent as an element to a consumer. As a simple use of ``expand`` here is a flow that sends the same element to consumer when producer does not send any new elements. -.. includecode:: ../code/docs/stream/RateTransformationDocTest.java#expand-last +.. includecode:: ../code/jdocs/stream/RateTransformationDocTest.java#expand-last Expand also allows to keep some state between demand requests from the downstream. Leveraging this, here is a flow that tracks and reports a drift between fast consumer and slow producer. -.. includecode:: ../code/docs/stream/RateTransformationDocTest.java#expand-drift +.. includecode:: ../code/jdocs/stream/RateTransformationDocTest.java#expand-drift Note that all of the elements coming from upstream will go through ``expand`` at least once. This means that the output of this flow is going to report a drift of zero if producer is fast enough, or a larger drift otherwise. diff --git a/akka-docs/rst/java/stream/stream-testkit.rst b/akka-docs/rst/java/stream/stream-testkit.rst index e604fa2529..37db70dd90 100644 --- a/akka-docs/rst/java/stream/stream-testkit.rst +++ b/akka-docs/rst/java/stream/stream-testkit.rst @@ -25,20 +25,20 @@ elements from a predefined collection, running a constructed test flow and asserting on the results that sink produced. Here is an example of a test for a sink: -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#strict-collection +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#strict-collection The same strategy can be applied for sources as well. In the next example we have a source that produces an infinite stream of elements. Such source can be tested by asserting that first arbitrary number of elements hold some condition. Here the ``take`` combinator and ``Sink.seq`` are very useful. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#grouped-infinite +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#grouped-infinite When testing a flow we need to attach a source and a sink. As both stream ends are under our control, we can choose sources that tests various edge cases of the flow and sinks that ease assertions. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#folded-stream +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#folded-stream TestKit ======= @@ -51,7 +51,7 @@ One of the more straightforward tests would be to materialize stream to a :class:`CompletionStage` and then use ``PatternsCS.pipe`` pattern to pipe the result of that future to the probe. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#pipeto-testprobe +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#pipeto-testprobe Instead of materializing to a future, we can use a :class:`Sink.actorRef` that sends all incoming elements to the given :class:`ActorRef`. Now we can use @@ -59,13 +59,13 @@ assertion methods on :class:`TestProbe` and expect elements one by one as they arrive. We can also assert stream completion by expecting for ``onCompleteMessage`` which was given to :class:`Sink.actorRef`. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#sink-actorref +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#sink-actorref Similarly to :class:`Sink.actorRef` that provides control over received elements, we can use :class:`Source.actorRef` and have full control over elements to be sent. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#source-actorref +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#source-actorref Streams TestKit =============== @@ -83,18 +83,18 @@ provide sources and sinks that materialize to probes that allow fluent API. A sink returned by ``TestSink.probe`` allows manual control over demand and assertions over elements coming downstream. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#test-sink-probe +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#test-sink-probe A source returned by ``TestSource.probe`` can be used for asserting demand or controlling when stream is completed or ended with an error. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#test-source-probe +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#test-source-probe You can also inject exceptions and test sink behaviour on error conditions. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#injecting-failure +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#injecting-failure Test source and sink can be used together in combination when testing flows. -.. includecode:: ../code/docs/stream/StreamTestKitDocTest.java#test-source-and-sink +.. includecode:: ../code/jdocs/stream/StreamTestKitDocTest.java#test-source-and-sink diff --git a/akka-docs/rst/java/testing.rst b/akka-docs/rst/java/testing.rst index bac90883bc..2594bb036b 100644 --- a/akka-docs/rst/java/testing.rst +++ b/akka-docs/rst/java/testing.rst @@ -68,7 +68,7 @@ Having access to the actual :class:`Actor` object allows application of all traditional unit testing techniques on the contained methods. Obtaining a reference is done like this: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-actor-ref +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-actor-ref Since :class:`TestActorRef` is generic in the actor type it returns the underlying actor with its proper static type. From this point on you may bring @@ -91,7 +91,7 @@ usual. This trick is made possible by the :class:`CallingThreadDispatcher` described below (see `CallingThreadDispatcher`_); this dispatcher is set implicitly for any actor instantiated into a :class:`TestActorRef`. -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-behavior +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-behavior As the :class:`TestActorRef` is a subclass of :class:`LocalActorRef` with a few special extras, also aspects like supervision and restarting work properly, but @@ -120,7 +120,7 @@ any thrown exceptions, then there is another mode available for you: just use the :meth:`receive` method on :class:`TestActorRef`, which will be forwarded to the underlying actor: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-expecting-exceptions +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-expecting-exceptions Use Cases --------- @@ -156,7 +156,7 @@ principle stays the same in that a single procedure drives the test. The :class:`JavaTestKit` class contains a collection of tools which makes this common task easy. -.. includecode:: code/docs/testkit/TestKitSampleTest.java#fullsample +.. includecode:: code/jdocs/testkit/TestKitSampleTest.java#fullsample The :class:`JavaTestKit` contains an actor named :obj:`testActor` which is the entry point for messages to be examined with the various ``expectMsg...`` @@ -181,7 +181,7 @@ Built-In Assertions The above mentioned :meth:`expectMsgEquals` is not the only method for formulating assertions concerning received messages, the full set is this: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-expect +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-expect In these examples, the maximum durations you will find mentioned below are left out, in which case they use the default value from configuration item @@ -243,7 +243,7 @@ code blocks: * **ExpectMsg** - .. includecode:: code/docs/testkit/TestKitDocTest.java#test-expectmsg + .. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-expectmsg The :meth:`match(Object in)` method will be evaluated once a message has been received within the allotted time (which may be given as constructor @@ -257,7 +257,7 @@ code blocks: * **ReceiveWhile** - .. includecode:: code/docs/testkit/TestKitDocTest.java#test-receivewhile + .. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-receivewhile This construct works like ExpectMsg, but it continually collects messages as long as they match the criteria, and it does not fail when a @@ -265,7 +265,7 @@ code blocks: time is up, when too much time passes between messages or when enough messages have been received. - .. includecode:: code/docs/testkit/TestKitDocTest.java#test-receivewhile-full + .. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-receivewhile-full :exclude: match-elided The need to specify the ``String`` result type twice results from the need @@ -274,7 +274,7 @@ code blocks: * **AwaitCond** - .. includecode:: code/docs/testkit/TestKitDocTest.java#test-awaitCond + .. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-awaitCond This general construct is not connected with the test kit’s message reception, the embedded condition can compute the boolean result from @@ -282,7 +282,7 @@ code blocks: * **AwaitAssert** - .. includecode:: code/docs/testkit/TestKitDocTest.java#test-awaitAssert + .. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-awaitAssert This general construct is not connected with the test kit’s message reception, the embedded assert can check anything in scope. @@ -293,7 +293,7 @@ test. For this purpose it is possible to ignore certain messages: * **IgnoreMsg** - .. includecode:: code/docs/testkit/TestKitDocTest.java#test-ignoreMsg + .. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-ignoreMsg Expecting Log Messages ---------------------- @@ -305,7 +305,7 @@ handler with the :class:`TestEventListener` and using an :class:`EventFilter` allows assertions on log messages, including those which are generated by exceptions: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-event-filter +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-event-filter If a number of occurrences is specific—as demonstrated above—then ``exec()`` will block until that number of matching messages have been received or the @@ -333,7 +333,7 @@ the positive or negative result must be obtained. Lower time limits need to be checked external to the examination, which is facilitated by a new construct for managing time constraints: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-within +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-within The block in :meth:`Within.run()` must complete after a :ref:`Duration` which is between :obj:`min` and :obj:`max`, where the former defaults to zero. The @@ -365,7 +365,7 @@ internally scaled by a factor taken from the :ref:`configuration`, You can scale other durations with the same factor by using ``dilated`` method in :class:`JavaTestKit`. -.. includecode:: code/docs/testkit/TestKitDocTest.java#duration-dilation +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#duration-dilation Using Multiple Probe Actors --------------------------- @@ -377,7 +377,7 @@ Another approach is to use it for creation of simple probe actors to be inserted in the message flows. The functionality is best explained using a small example: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-probe +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-probe This simple test verifies an equally simple Forwarder actor by injecting a probe as the forwarder’s target. Another example would be two actors A and B @@ -389,12 +389,12 @@ the test setup. If you have many test probes, you can name them to get meaningful actor names in test logs and assertions: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-probe-with-custom-name +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-probe-with-custom-name Probes may also be equipped with custom assertions to make your test code even more concise and clear: -.. includecode:: code/docs/testkit/TestKitDocTest.java +.. includecode:: code/jdocs/testkit/TestKitDocTest.java :include: test-special-probe You have complete flexibility here in mixing and matching the @@ -416,7 +416,7 @@ Watching Other Actors from Probes A :class:`JavaTestKit` can register itself for DeathWatch of any other actor: -.. includecode:: code/docs/testkit/TestKitDocTest.java +.. includecode:: code/jdocs/testkit/TestKitDocTest.java :include: test-probe-watch Replying to Messages Received by Probes @@ -427,7 +427,7 @@ The probe stores the sender of the last dequeued message (i.e. after its :meth:`getLastSender()` method. This information can also implicitly be used for having the probe reply to the last received message: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-probe-reply +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-probe-reply Forwarding Messages Received by Probes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -435,7 +435,7 @@ Forwarding Messages Received by Probes The probe can also forward a received message (i.e. after its ``expectMsg*`` reception), retaining the original sender: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-probe-forward +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-probe-forward Auto-Pilot ^^^^^^^^^^ @@ -447,7 +447,7 @@ keep a test running and verify traces later you can also install an This code can be used to forward messages, e.g. in a chain ``A --> Probe --> B``, as long as a certain protocol is obeyed. -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-auto-pilot +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-auto-pilot The :meth:`run` method must return the auto-pilot for the next message, wrapped in an :class:`Option`; setting it to :obj:`None` terminates the auto-pilot. @@ -461,7 +461,7 @@ described :ref:`above ` is local to each probe. Hence, probe do not react to each other's deadlines or to the deadline set in an enclosing :class:`JavaTestKit` instance: -.. includecode:: code/docs/testkit/TestKitDocTest.java#test-within-probe +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#test-within-probe Here, the ``expectMsgEquals`` call will use the default timeout. @@ -483,7 +483,7 @@ Conversely, a parent's binding to its child can be lessened as follows: For example, the structure of the code you want to test may follow this pattern: -.. includecode:: code/docs/testkit/ParentChildTest.java#test-example +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-example Introduce child to its parent ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -491,7 +491,7 @@ Introduce child to its parent The first option is to avoid use of the :meth:`context.parent` function and create a child with a custom parent by passing an explicit reference to its parent instead. -.. includecode:: code/docs/testkit/ParentChildTest.java#test-dependentchild +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-dependentchild Create the child using JavaTestKit ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -500,7 +500,7 @@ The ``JavaTestKit`` class can in fact create actors that will run with the test This will cause any messages the child actor sends to `getContext().getParent()` to end up in the test probe. -.. includecode:: code/docs/testkit/ParentChildTest.java#test-TestProbe-parent +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-TestProbe-parent Using a fabricated parent ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -509,8 +509,8 @@ If you prefer to avoid modifying the child constructor you can create a fabricated parent in your test. This, however, does not enable you to test the parent actor in isolation. -.. includecode:: code/docs/testkit/ParentChildTest.java#test-fabricated-parent-creator -.. includecode:: code/docs/testkit/ParentChildTest.java#test-fabricated-parent +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-fabricated-parent-creator +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-fabricated-parent Externalize child making from the parent ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -518,16 +518,16 @@ Externalize child making from the parent Alternatively, you can tell the parent how to create its child. There are two ways to do this: by giving it a :class:`Props` object or by giving it a function which takes care of creating the child actor: -.. includecode:: code/docs/testkit/ParentChildTest.java#test-dependentparent -.. includecode:: code/docs/testkit/ParentChildTest.java#test-dependentparent-generic +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-dependentparent +.. includecode:: code/jdocs/testkit/ParentChildTest.java#test-dependentparent-generic Creating the :class:`Actor` is straightforward and the function may look like this in your test code: -.. includecode:: code/docs/testkit/ParentChildTest.java#child-maker-test +.. includecode:: code/jdocs/testkit/ParentChildTest.java#child-maker-test And like this in your application code: -.. includecode:: code/docs/testkit/ParentChildTest.java#child-maker-prod +.. includecode:: code/jdocs/testkit/ParentChildTest.java#child-maker-prod Which of these methods is the best depends on what is most important to test. The @@ -551,7 +551,7 @@ How to use it Just set the dispatcher as you normally would: -.. includecode:: code/docs/testkit/TestKitDocTest.java#calling-thread-dispatcher +.. includecode:: code/jdocs/testkit/TestKitDocTest.java#calling-thread-dispatcher How it works ------------ diff --git a/akka-docs/rst/java/typed-actors.rst b/akka-docs/rst/java/typed-actors.rst index c7c5433299..7f8561b86d 100644 --- a/akka-docs/rst/java/typed-actors.rst +++ b/akka-docs/rst/java/typed-actors.rst @@ -9,7 +9,7 @@ a private instance of the implementation. The advantage of Typed Actors vs. Actors is that with TypedActors you have a static contract, and don't need to define your own messages, the downside is that it places some limitations on what you can do and what you can't, i.e. you can't use become/unbecome. -Typed Actors are implemented using `JDK Proxies `_ which provide a pretty easy-worked API to intercept method calls. +Typed Actors are implemented using `JDK Proxies `_ which provide a pretty easy-worked API to intercept method calls. .. note:: @@ -27,7 +27,7 @@ blog post `_. A bit more background: TypedActors can easily be abused as RPC, and that is an abstraction which is `well-known -`_ +`_ to be leaky. Hence TypedActors are not what we think of first when we talk about making highly scalable concurrent software easier to write correctly. They have their niche, use them sparingly. @@ -38,7 +38,7 @@ The tools of the trade Before we create our first Typed Actor we should first go through the tools that we have at our disposal, it's located in ``akka.actor.TypedActor``. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-extension-tools .. warning:: @@ -55,42 +55,42 @@ To create a Typed Actor you need to have one or more interfaces, and one impleme The following imports are assumed: -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: imports Our example interface: -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-iface :exclude: typed-actor-iface-methods Our example implementation of that interface: -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-impl :exclude: typed-actor-impl-methods The most trivial way of creating a Typed Actor instance of our ``Squarer``: -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-create1 First type is the type of the proxy, the second type is the type of the implementation. If you need to call a specific constructor you do it like this: -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-create2 Since you supply a ``Props``, you can specify which dispatcher to use, what the default timeout should be used and more. Now, our ``Squarer`` doesn't have any methods, so we'd better add those. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-iface Alright, now we've got some methods we can call, but we need to implement those in ``SquarerImpl``. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-impl Excellent, now we have an interface and an implementation of that interface, @@ -120,7 +120,7 @@ we *strongly* recommend that parameters passed are immutable. One-way message send ^^^^^^^^^^^^^^^^^^^^ -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-call-oneway As simple as that! The method will be executed on another thread; asynchronously. @@ -128,13 +128,13 @@ As simple as that! The method will be executed on another thread; asynchronously Request-reply message send ^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-call-option This will block for as long as the timeout that was set in the ``Props`` of the Typed Actor, if needed. It will return ``None`` if a timeout occurs. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-call-strict This will block for as long as the timeout that was set in the ``Props`` of the Typed Actor, @@ -148,7 +148,7 @@ interface method. Request-reply-with-future message send ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-call-future This call is asynchronous, and the Future returned can be used for asynchronous composition. @@ -158,12 +158,12 @@ Stopping Typed Actors Since Akka's Typed Actors are backed by Akka Actors they must be stopped when they aren't needed anymore. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-stop This asynchronously stops the Typed Actor associated with the specified proxy ASAP. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-poisonpill This asynchronously stops the Typed Actor associated with the specified proxy @@ -175,7 +175,7 @@ Typed Actor Hierarchies Since you can obtain a contextual Typed Actor Extension by passing in an ``ActorContext`` you can create child Typed Actors by invoking ``typedActorOf(..)`` on that. -.. includecode:: code/docs/actor/TypedActorDocTest.java +.. includecode:: code/jdocs/actor/TypedActorDocTest.java :include: typed-actor-hierarchy You can also create a child Typed Actor in regular Akka Actors by giving the ``AbstractActor.ActorContext`` @@ -220,7 +220,7 @@ Lookup & Remoting Since ``TypedActors`` are backed by ``Akka Actors``, you can use ``typedActorOf`` to proxy ``ActorRefs`` potentially residing on remote nodes. -.. includecode:: code/docs/actor/TypedActorDocTest.java#typed-actor-remote +.. includecode:: code/jdocs/actor/TypedActorDocTest.java#typed-actor-remote Typed Router pattern -------------------- @@ -231,11 +231,11 @@ which can implement a specific routing logic, such as ``smallest-mailbox`` or `` Routers are not provided directly for typed actors, but it is really easy to leverage an untyped router and use a typed proxy in front of it. To showcase this let's create typed actors that assign themselves some random ``id``, so we know that in fact, the router has sent the message to different actors: -.. includecode:: code/docs/actor/TypedActorDocTest.java#typed-router-types +.. includecode:: code/jdocs/actor/TypedActorDocTest.java#typed-router-types In order to round robin among a few instances of such actors, you can simply create a plain untyped router, and then facade it with a ``TypedActor`` like shown in the example below. This works because typed actors of course communicate using the same mechanisms as normal actors, and methods calls on them get transformed into message sends of ``MethodCall`` messages. -.. includecode:: code/docs/actor/TypedActorDocTest.java#typed-router +.. includecode:: code/jdocs/actor/TypedActorDocTest.java#typed-router diff --git a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala index fbb45b7ff2..5f0344bcb8 100644 --- a/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/actor/ActorDocSpec.scala @@ -3,6 +3,8 @@ */ package docs.actor +import jdocs.actor.ImmutableMessage + import language.postfixOps //#imports1 @@ -15,7 +17,6 @@ import akka.event.Logging import scala.concurrent.Future import akka.actor.{ ActorRef, ActorSystem, PoisonPill, Terminated, ActorLogging } import org.scalatest.{ BeforeAndAfterAll, WordSpec } -import org.scalatest.Matchers import akka.testkit._ import akka.util._ import scala.concurrent.duration._ diff --git a/akka-docs/rst/scala/code/docs/ddata/DistributedDataDocSpec.scala b/akka-docs/rst/scala/code/docs/ddata/DistributedDataDocSpec.scala index c5e563bd70..c87a1ce531 100644 --- a/akka-docs/rst/scala/code/docs/ddata/DistributedDataDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/ddata/DistributedDataDocSpec.scala @@ -4,16 +4,14 @@ package docs.ddata import scala.concurrent.duration._ -import java.util.concurrent.ThreadLocalRandom import akka.actor.Actor -import akka.actor.ActorLogging import akka.cluster.Cluster import akka.cluster.ddata._ import akka.testkit.AkkaSpec -import akka.testkit.ImplicitSender import akka.testkit.TestProbe import akka.actor.ActorRef import akka.serialization.SerializationExtension +import jdocs.ddata object DistributedDataDocSpec { @@ -36,10 +34,10 @@ object DistributedDataDocSpec { #//#japi-serializer-config akka.actor { serializers { - twophaseset = "docs.ddata.japi.protobuf.TwoPhaseSetSerializer" + twophaseset = "jdocs.ddata.protobuf.TwoPhaseSetSerializer" } serialization-bindings { - "docs.ddata.japi.TwoPhaseSet" = twophaseset + "jdocs.ddata.TwoPhaseSet" = twophaseset } } #//#japi-serializer-config @@ -401,7 +399,7 @@ class DistributedDataDocSpec extends AkkaSpec(DistributedDataDocSpec.config) { "test japi.TwoPhaseSetSerializer" in { import scala.collection.JavaConverters._ - val s1 = japi.TwoPhaseSet.create().add("a").add("b").add("c").remove("b") + val s1 = ddata.TwoPhaseSet.create().add("a").add("b").add("c").remove("b") s1.getElements.asScala should be(Set("a", "c")) val serializer = SerializationExtension(system).findSerializerFor(s1) val blob = serializer.toBinary(s1) diff --git a/akka-docs/rst/scala/code/docs/dispatcher/DispatcherDocSpec.scala b/akka-docs/rst/scala/code/docs/dispatcher/DispatcherDocSpec.scala index 522aceec2d..0e71951987 100644 --- a/akka-docs/rst/scala/code/docs/dispatcher/DispatcherDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/dispatcher/DispatcherDocSpec.scala @@ -18,7 +18,7 @@ object DispatcherDocSpec { val javaConfig = """ //#prio-dispatcher-config-java prio-dispatcher { - mailbox-type = "docs.dispatcher.DispatcherDocTest$MyPrioMailbox" + mailbox-type = "jdocs.dispatcher.DispatcherDocTest$MyPrioMailbox" //Other dispatcher configuration goes here } //#prio-dispatcher-config-java @@ -33,16 +33,16 @@ object DispatcherDocSpec { //#custom-mailbox-config-java custom-dispatcher { mailbox-requirement = - "docs.dispatcher.MyUnboundedJMessageQueueSemantics" + "jdocs.dispatcher.MyUnboundedMessageQueueSemantics" } akka.actor.mailbox.requirements { - "docs.dispatcher.MyUnboundedJMessageQueueSemantics" = + "jdocs.dispatcher.MyUnboundedMessageQueueSemantics" = custom-dispatcher-mailbox } custom-dispatcher-mailbox { - mailbox-type = "docs.dispatcher.MyUnboundedJMailbox" + mailbox-type = "jdocs.dispatcher.MyUnboundedMailbox" } //#custom-mailbox-config-java """ diff --git a/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala b/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala index 5a03629050..e8c11587c9 100644 --- a/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/io/UdpDocSpec.scala @@ -160,7 +160,7 @@ class ScalaUdpDocSpec extends UdpDocSpec { } class JavaUdpDocSpec extends UdpDocSpec { - import UdpDocTest._ + import jdocs.io.UdpDocTest._ override def listenerProps(next: ActorRef) = Props(new Listener(next)) override def simpleSenderProps(remote: InetSocketAddress) = Props(new SimpleSender(remote)) diff --git a/akka-docs/rst/scala/code/docs/routing/CustomRouterDocSpec.scala b/akka-docs/rst/scala/code/docs/routing/CustomRouterDocSpec.scala index dac4c4da24..72e19ad250 100644 --- a/akka-docs/rst/scala/code/docs/routing/CustomRouterDocSpec.scala +++ b/akka-docs/rst/scala/code/docs/routing/CustomRouterDocSpec.scala @@ -19,7 +19,7 @@ object CustomRouterDocSpec { #//#config akka.actor.deployment { /redundancy2 { - router = "docs.routing.RedundancyGroup" + router = "jdocs.routing.RedundancyGroup" routees.paths = ["/user/s1", "/user/s2", "/user/s3"] nbr-copies = 5 } @@ -31,7 +31,7 @@ akka.actor.deployment { #//#jconfig akka.actor.deployment { /redundancy2 { - router = "docs.jrouting.RedundancyGroup" + router = "jdocs.routing.RedundancyGroup" routees.paths = ["/user/s1", "/user/s2", "/user/s3"] nbr-copies = 5 }