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