parent
67a9e62254
commit
0953e7aee3
41 changed files with 156 additions and 368 deletions
|
|
@ -10,18 +10,19 @@ import static akka.actor.SupervisorStrategy.Directive;
|
||||||
* Used for building a partial function for {@link akka.actor.Actor#supervisorStrategy() Actor.supervisorStrategy()}.
|
* Used for building a partial function for {@link akka.actor.Actor#supervisorStrategy() Actor.supervisorStrategy()}.
|
||||||
* *
|
* *
|
||||||
* Inside an actor you can use it like this with Java 8 to define your supervisorStrategy.
|
* Inside an actor you can use it like this with Java 8 to define your supervisorStrategy.
|
||||||
* <p/>
|
* <p>
|
||||||
* Example:
|
* Example:
|
||||||
|
* </p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* @Override
|
* @Override
|
||||||
* private static SupervisorStrategy strategy =
|
* private static SupervisorStrategy strategy =
|
||||||
* new OneForOneStrategy(10, Duration.create("1 minute"), DeciderBuilder.
|
* new OneForOneStrategy(10, Duration.create("1 minute"), DeciderBuilder.
|
||||||
* match(ArithmeticException.class, e -> resume()).
|
* match(ArithmeticException.class, e -> resume()).
|
||||||
* match(NullPointerException.class, e -> restart()).
|
* match(NullPointerException.class, e -> restart()).
|
||||||
* match(IllegalArgumentException.class, e -> stop()).
|
* match(IllegalArgumentException.class, e -> stop()).
|
||||||
* matchAny(o -> escalate()).build());
|
* matchAny(o -> escalate()).build());
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public SupervisorStrategy supervisorStrategy() {
|
* public SupervisorStrategy supervisorStrategy() {
|
||||||
* return strategy;
|
* return strategy;
|
||||||
* }
|
* }
|
||||||
|
|
|
||||||
|
|
@ -90,10 +90,11 @@ public class Match<I, R> extends AbstractMatch<I, R> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function to make the Java code more readable.
|
* Convenience function to make the Java code more readable.
|
||||||
* <p>
|
* <p></p>
|
||||||
|
*
|
||||||
* <pre><code>
|
* <pre><code>
|
||||||
* Matcher<X, Y> matcher = Matcher.create(...);
|
* Matcher<X, Y> matcher = Matcher.create(...);
|
||||||
* <p>
|
*
|
||||||
* Y someY = matcher.match(obj);
|
* Y someY = matcher.match(obj);
|
||||||
* </code></pre>
|
* </code></pre>
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,20 @@ package akka.japi.pf;
|
||||||
* There is both a match on type only, and a match on type and predicate.
|
* There is both a match on type only, and a match on type and predicate.
|
||||||
*
|
*
|
||||||
* Inside an actor you can use it like this with Java 8 to define your receive method.
|
* Inside an actor you can use it like this with Java 8 to define your receive method.
|
||||||
* <p/>
|
* <p>
|
||||||
* Example:
|
* Example:
|
||||||
|
* </p>
|
||||||
* <pre>
|
* <pre>
|
||||||
* @Override
|
* @Override
|
||||||
* public Actor() {
|
* public Actor() {
|
||||||
* receive(ReceiveBuilder.
|
* receive(ReceiveBuilder.
|
||||||
* match(Double.class, d -> {
|
* match(Double.class, d -> {
|
||||||
* sender().tell(d.isNaN() ? 0 : d, self());
|
* sender().tell(d.isNaN() ? 0 : d, self());
|
||||||
* }).
|
* }).
|
||||||
* match(Integer.class, i -> {
|
* match(Integer.class, i -> {
|
||||||
* sender().tell(i * 10, self());
|
* sender().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());
|
* sender().tell(s.toUpperCase(), self());
|
||||||
* }).build()
|
* }).build()
|
||||||
* );
|
* );
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ public class UnitMatch<I> extends AbstractMatch<I, BoxedUnit> {
|
||||||
* <p>
|
* <p>
|
||||||
* <pre><code>
|
* <pre><code>
|
||||||
* UnitMatcher<X> matcher = UnitMatcher.create(...);
|
* UnitMatcher<X> matcher = UnitMatcher.create(...);
|
||||||
* <p>
|
*
|
||||||
* matcher.match(obj);
|
* matcher.match(obj);
|
||||||
* </code></pre>
|
* </code></pre>
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ before or after using them to construct an actor system:
|
||||||
|
|
||||||
.. parsed-literal::
|
.. parsed-literal::
|
||||||
|
|
||||||
Welcome to Scala version @scalaVersion@ (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_27).
|
Welcome to Scala version @scalaVersion@ (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0).
|
||||||
Type in expressions to have them evaluated.
|
Type in expressions to have them evaluated.
|
||||||
Type :help for more information.
|
Type :help for more information.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,11 @@ Getting Started
|
||||||
Prerequisites
|
Prerequisites
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
Akka requires that you have `Java 1.6 <http://www.oracle.com/technetwork/java/javase/downloads/index.html>`_ or
|
Akka requires that you have `Java 8 <http://www.oracle.com/technetwork/java/javase/downloads/index.html>`_ or
|
||||||
later installed on you machine.
|
later installed on you machine.
|
||||||
|
|
||||||
|
`Typesafe <http://www.typesafe.com>`_ provides versions of Akka that are compatible with Java 6, 7 and 8.
|
||||||
|
|
||||||
Getting Started Guides and Template Projects
|
Getting Started Guides and Template Projects
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
|
|
@ -33,8 +35,7 @@ Akka is very modular and consists of several JARs containing different features.
|
||||||
|
|
||||||
- ``akka-cluster`` – Cluster membership management, elastic routers.
|
- ``akka-cluster`` – Cluster membership management, elastic routers.
|
||||||
|
|
||||||
- ``akka-osgi`` – base bundle for using Akka in OSGi containers, containing the
|
- ``akka-osgi`` – utilities for using Akka in OSGi containers
|
||||||
``akka-actor`` classes
|
|
||||||
|
|
||||||
- ``akka-osgi-aries`` – Aries blueprint for provisioning actor systems
|
- ``akka-osgi-aries`` – Aries blueprint for provisioning actor systems
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor;
|
package docs.actorlambda;
|
||||||
|
|
||||||
import akka.actor.*;
|
import akka.actor.*;
|
||||||
import akka.japi.pf.ReceiveBuilder;
|
import akka.japi.pf.ReceiveBuilder;
|
||||||
|
|
@ -13,8 +13,8 @@ import com.typesafe.config.Config;
|
||||||
import com.typesafe.config.ConfigFactory;
|
import com.typesafe.config.ConfigFactory;
|
||||||
import scala.PartialFunction;
|
import scala.PartialFunction;
|
||||||
import scala.runtime.BoxedUnit;
|
import scala.runtime.BoxedUnit;
|
||||||
import static docs.actor.Messages.Swap.Swap;
|
import static docs.actorlambda.Messages.Swap.Swap;
|
||||||
import static docs.actor.Messages.*;
|
import static docs.actorlambda.Messages.*;
|
||||||
import static akka.japi.Util.immutableSeq;
|
import static akka.japi.Util.immutableSeq;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
package docs.actor;
|
package docs.actorlambda;
|
||||||
|
|
||||||
//#testkit
|
//#testkit
|
||||||
import akka.actor.*;
|
import akka.actor.*;
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
package docs.actor;
|
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
package docs.actorlambda;
|
||||||
|
|
||||||
import akka.actor.AbstractActor;
|
import akka.actor.AbstractActor;
|
||||||
import akka.actor.ActorRef;
|
import akka.actor.ActorRef;
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor;
|
package docs.actorlambda;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor;
|
package docs.actorlambda;
|
||||||
|
|
||||||
//#imports
|
//#imports
|
||||||
import akka.actor.AbstractActor;
|
import akka.actor.AbstractActor;
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor;
|
package docs.actorlambda;
|
||||||
|
|
||||||
//#sample-actor
|
//#sample-actor
|
||||||
import akka.actor.AbstractActor;
|
import akka.actor.AbstractActor;
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor;
|
package docs.actorlambda;
|
||||||
|
|
||||||
import akka.actor.ActorRef;
|
import akka.actor.ActorRef;
|
||||||
import akka.actor.ActorSystem;
|
import akka.actor.ActorSystem;
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor.fsm;
|
package docs.actorlambda.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.actor.fsm.Buncher.Data;
|
import static docs.actorlambda.fsm.Buncher.Data;
|
||||||
import static docs.actor.fsm.Buncher.State.*;
|
import static docs.actorlambda.fsm.Buncher.State.*;
|
||||||
import static docs.actor.fsm.Buncher.State;
|
import static docs.actorlambda.fsm.Buncher.State;
|
||||||
import static docs.actor.fsm.Buncher.Uninitialized.*;
|
import static docs.actorlambda.fsm.Buncher.Uninitialized.*;
|
||||||
import static docs.actor.fsm.Events.*;
|
import static docs.actorlambda.fsm.Events.*;
|
||||||
|
|
||||||
//#simple-fsm
|
//#simple-fsm
|
||||||
public class Buncher extends AbstractFSM<State, Data> {
|
public class Buncher extends AbstractFSM<State, Data> {
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor.fsm;
|
package docs.actorlambda.fsm;
|
||||||
|
|
||||||
import akka.actor.ActorRef;
|
import akka.actor.ActorRef;
|
||||||
import akka.actor.ActorSystem;
|
import akka.actor.ActorSystem;
|
||||||
|
|
@ -13,11 +13,11 @@ import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import docs.actor.fsm.*;
|
import docs.actorlambda.fsm.*;
|
||||||
import static docs.actor.fsm.Events.Batch;
|
import static docs.actorlambda.fsm.Events.Batch;
|
||||||
import static docs.actor.fsm.Events.Queue;
|
import static docs.actorlambda.fsm.Events.Queue;
|
||||||
import static docs.actor.fsm.Events.SetTarget;
|
import static docs.actorlambda.fsm.Events.SetTarget;
|
||||||
import static docs.actor.fsm.Events.Flush.Flush;
|
import static docs.actorlambda.fsm.Events.Flush.Flush;
|
||||||
|
|
||||||
//#test-code
|
//#test-code
|
||||||
public class BuncherTest {
|
public class BuncherTest {
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor.fsm;
|
package docs.actorlambda.fsm;
|
||||||
|
|
||||||
import akka.actor.ActorRef;
|
import akka.actor.ActorRef;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package docs.actor.fsm;
|
package docs.actorlambda.fsm;
|
||||||
|
|
||||||
import akka.actor.*;
|
import akka.actor.*;
|
||||||
import akka.testkit.JavaTestKit;
|
import akka.testkit.JavaTestKit;
|
||||||
|
|
@ -14,8 +14,8 @@ import scala.concurrent.duration.Duration;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import static docs.actor.fsm.FSMDocTest.StateType.*;
|
import static docs.actorlambda.fsm.FSMDocTest.StateType.*;
|
||||||
import static docs.actor.fsm.FSMDocTest.Messages.*;
|
import static docs.actorlambda.fsm.FSMDocTest.Messages.*;
|
||||||
import static java.util.concurrent.TimeUnit.*;
|
import static java.util.concurrent.TimeUnit.*;
|
||||||
|
|
||||||
public class FSMDocTest {
|
public class FSMDocTest {
|
||||||
|
|
@ -173,7 +173,7 @@ public class FSMDocTest {
|
||||||
expectMsgEquals(Active);
|
expectMsgEquals(Active);
|
||||||
expectMsgEquals(Data.Foo);
|
expectMsgEquals(Data.Foo);
|
||||||
String msg = expectMsgClass(String.class);
|
String msg = expectMsgClass(String.class);
|
||||||
assertThat(msg, CoreMatchers.startsWith("LogEntry(SomeState,Foo,Actor[akka://FSMDocTest/system/"));
|
assertTrue(msg.startsWith("LogEntry(SomeState,Foo,Actor[akka://FSMDocTest/system/"));
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||||
*/
|
*/
|
||||||
package docs.actor.japi;
|
package docs.actorlambda.japi;
|
||||||
|
|
||||||
//#all
|
//#all
|
||||||
//#imports
|
//#imports
|
||||||
|
|
@ -28,10 +28,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.actor.japi.FaultHandlingDocSample.WorkerApi.*;
|
import static docs.actorlambda.japi.FaultHandlingDocSample.WorkerApi.*;
|
||||||
import static docs.actor.japi.FaultHandlingDocSample.CounterServiceApi.*;
|
import static docs.actorlambda.japi.FaultHandlingDocSample.CounterServiceApi.*;
|
||||||
import static docs.actor.japi.FaultHandlingDocSample.CounterApi.*;
|
import static docs.actorlambda.japi.FaultHandlingDocSample.CounterApi.*;
|
||||||
import static docs.actor.japi.FaultHandlingDocSample.StorageApi.*;
|
import static docs.actorlambda.japi.FaultHandlingDocSample.StorageApi.*;
|
||||||
|
|
||||||
//#imports
|
//#imports
|
||||||
|
|
||||||
|
|
@ -95,12 +95,12 @@ To select a Protocol Family you must extend ``akka.io.Inet.DatagramChannelCreato
|
||||||
class which implements ``akka.io.Inet.SocketOption``. Provide custom logic
|
class which implements ``akka.io.Inet.SocketOption``. Provide custom logic
|
||||||
for opening a datagram channel by overriding :meth:`create` method.
|
for opening a datagram channel by overriding :meth:`create` method.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-udp-multicast/src/main/java/docs/io/JavaUdpMulticast.java#inet6-protocol-family
|
.. includecode:: code/docs/io/JavaUdpMulticast.java#inet6-protocol-family
|
||||||
|
|
||||||
Another socket option will be needed to join a multicast group.
|
Another socket option will be needed to join a multicast group.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-udp-multicast/src/main/java/docs/io/JavaUdpMulticast.java#multicast-group
|
.. includecode:: code/docs/io/JavaUdpMulticast.java#multicast-group
|
||||||
|
|
||||||
Socket options must be provided to :meth:`UdpMessage.bind` command.
|
Socket options must be provided to :meth:`UdpMessage.bind` command.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-udp-multicast/src/main/java/docs/io/JavaUdpMulticast.java#bind
|
.. includecode:: code/docs/io/JavaUdpMulticast.java#bind
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ function there is a builder named ``ReceiveBuilder`` that you can use.
|
||||||
|
|
||||||
Here is an example:
|
Here is an example:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/MyActor.java
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -80,8 +80,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#import-props
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-props
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#creating-props
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -96,7 +96,7 @@ found.
|
||||||
Dangerous Variants
|
Dangerous Variants
|
||||||
^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#creating-props-deprecated
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -128,14 +128,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#props-factory
|
.. includecode:: code/docs/actorlambda/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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#messages-in-companion
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#messages-in-companion
|
||||||
|
|
||||||
Creating Actors with Props
|
Creating Actors with Props
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
@ -144,14 +144,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#import-actorRef
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-actorRef
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#system-actorOf
|
.. includecode:: code/docs/actorlambda/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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#context-actorOf
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -321,7 +321,7 @@ termination (see `Stopping Actors`_). This service is provided by the
|
||||||
|
|
||||||
Registering a monitor is easy:
|
Registering a monitor is easy:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#watch
|
.. includecode:: code/docs/actorlambda/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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#preStart
|
.. includecode:: code/docs/actorlambda/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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#selection-local
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#selection-local
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|
@ -453,7 +453,7 @@ 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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#selection-wildcard
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#import-identify
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#import-identify
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#identify
|
.. includecode:: code/docs/actorlambda/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 ``Future``
|
the ``resolveOne`` method of the :class:`ActorSelection`. It returns a ``Future``
|
||||||
|
|
@ -480,7 +480,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#selection-remote
|
.. includecode:: code/docs/actorlambda/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`.
|
||||||
|
|
||||||
|
|
@ -537,7 +537,7 @@ 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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#tell
|
.. includecode:: code/docs/actorlambda/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:`sender()` method while processing this
|
||||||
|
|
@ -577,7 +577,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#reply-exception
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -608,7 +608,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#forward
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#forward
|
||||||
|
|
||||||
Receive messages
|
Receive messages
|
||||||
================
|
================
|
||||||
|
|
@ -616,13 +616,13 @@ Receive messages
|
||||||
An Actor either has to set its initial receive behavior in the constructor by
|
An Actor either has to set its initial receive behavior in the constructor by
|
||||||
calling the :meth:`receive` method in the :class:`AbstractActor`:
|
calling the :meth:`receive` method in the :class:`AbstractActor`:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java
|
||||||
:include: receive-constructor
|
:include: receive-constructor
|
||||||
:exclude: and-some-behavior
|
:exclude: and-some-behavior
|
||||||
|
|
||||||
or by implementing the :meth:`receive` method in the :class:`Actor` interface:
|
or by implementing the :meth:`receive` method in the :class:`Actor` interface:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#receive
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#receive
|
||||||
|
|
||||||
Both the argument to the :class:`AbstractActor` :meth:`receive` method and the return
|
Both the argument to the :class:`AbstractActor` :meth:`receive` method and the return
|
||||||
type of the :class:`Actor` :meth:`receive` method is a ``PartialFunction<Object, BoxedUnit>``
|
type of the :class:`Actor` :meth:`receive` method is a ``PartialFunction<Object, BoxedUnit>``
|
||||||
|
|
@ -634,7 +634,7 @@ function there is a builder named ``ReceiveBuilder`` that you can use.
|
||||||
|
|
||||||
Here is an example:
|
Here is an example:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/MyActor.java
|
.. includecode:: code/docs/actorlambda/MyActor.java
|
||||||
:include: imports,my-actor
|
:include: imports,my-actor
|
||||||
|
|
||||||
.. _LambdaActor.Reply:
|
.. _LambdaActor.Reply:
|
||||||
|
|
@ -649,7 +649,7 @@ 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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/MyActor.java#reply
|
.. includecode:: code/docs/actorlambda/MyActor.java#reply
|
||||||
|
|
||||||
|
|
||||||
Receive timeout
|
Receive timeout
|
||||||
|
|
@ -667,7 +667,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#receive-timeout
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#receive-timeout
|
||||||
|
|
||||||
.. _stopping-actors-lambda:
|
.. _stopping-actors-lambda:
|
||||||
|
|
||||||
|
|
@ -704,7 +704,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#postStop
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#postStop
|
||||||
:exclude: clean-up-some-resources
|
:exclude: clean-up-some-resources
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
@ -735,7 +735,7 @@ termination of several actors:
|
||||||
|
|
||||||
.. includecode:: code/docs/actor/UntypedActorDocTest.java#gracefulStop
|
.. includecode:: code/docs/actor/UntypedActorDocTest.java#gracefulStop
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#gracefulStop-actor
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -775,7 +775,7 @@ popped.
|
||||||
|
|
||||||
To hotswap the Actor behavior using ``become``:
|
To hotswap the Actor behavior using ``become``:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#hot-swap-actor
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -791,7 +791,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#swapper
|
.. includecode:: code/docs/actorlambda/ActorDocTest.java#swapper
|
||||||
|
|
||||||
|
|
||||||
Stash
|
Stash
|
||||||
|
|
@ -816,7 +816,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/ActorDocTest.java#stash
|
.. includecode:: code/docs/actorlambda/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
|
||||||
|
|
@ -949,7 +949,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:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/InitializationDocTest.java#messageInit
|
.. includecode:: code/docs/actorlambda/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.
|
||||||
|
|
|
||||||
|
|
@ -49,5 +49,5 @@ Step Description
|
||||||
Full Source Code of the Fault Tolerance Sample
|
Full Source Code of the Fault Tolerance Sample
|
||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/japi/FaultHandlingDocSample.java#all
|
.. includecode:: code/docs/actorlambda/japi/FaultHandlingDocSample.java#all
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ in more depth.
|
||||||
|
|
||||||
For the sake of demonstration let us consider the following strategy:
|
For the sake of demonstration let us consider the following strategy:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: strategy
|
:include: strategy
|
||||||
|
|
||||||
I have chosen a few well-known exception types in order to demonstrate the
|
I have chosen a few well-known exception types in order to demonstrate the
|
||||||
|
|
@ -109,49 +109,49 @@ Test Application
|
||||||
The following section shows the effects of the different directives in practice,
|
The following section shows the effects of the different directives in practice,
|
||||||
wherefor a test setup is needed. First off, we need a suitable supervisor:
|
wherefor a test setup is needed. First off, we need a suitable supervisor:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: supervisor
|
:include: supervisor
|
||||||
|
|
||||||
This supervisor will be used to create a child, with which we can experiment:
|
This supervisor will be used to create a child, with which we can experiment:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: child
|
:include: child
|
||||||
|
|
||||||
The test is easier by using the utilities described in :ref:`akka-testkit`,
|
The test is easier by using the utilities described in :ref:`akka-testkit`,
|
||||||
where ``TestProbe`` provides an actor ref useful for receiving and inspecting replies.
|
where ``TestProbe`` provides an actor ref useful for receiving and inspecting replies.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: testkit
|
:include: testkit
|
||||||
|
|
||||||
Let us create actors:
|
Let us create actors:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: create
|
:include: create
|
||||||
|
|
||||||
The first test shall demonstrate the ``Resume`` directive, so we try it out by
|
The first test shall demonstrate the ``Resume`` directive, so we try it out by
|
||||||
setting some non-initial state in the actor and have it fail:
|
setting some non-initial state in the actor and have it fail:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: resume
|
:include: resume
|
||||||
|
|
||||||
As you can see the value 42 survives the fault handling directive. Now, if we
|
As you can see the value 42 survives the fault handling directive. Now, if we
|
||||||
change the failure to a more serious ``NullPointerException``, that will no
|
change the failure to a more serious ``NullPointerException``, that will no
|
||||||
longer be the case:
|
longer be the case:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: restart
|
:include: restart
|
||||||
|
|
||||||
And finally in case of the fatal ``IllegalArgumentException`` the child will be
|
And finally in case of the fatal ``IllegalArgumentException`` the child will be
|
||||||
terminated by the supervisor:
|
terminated by the supervisor:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: stop
|
:include: stop
|
||||||
|
|
||||||
Up to now the supervisor was completely unaffected by the child’s failure,
|
Up to now the supervisor was completely unaffected by the child’s failure,
|
||||||
because the directives set did handle it. In case of an ``Exception``, this is not
|
because the directives set did handle it. In case of an ``Exception``, this is not
|
||||||
true anymore and the supervisor escalates the failure.
|
true anymore and the supervisor escalates the failure.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: escalate-kill
|
:include: escalate-kill
|
||||||
|
|
||||||
The supervisor itself is supervised by the top-level actor provided by the
|
The supervisor itself is supervised by the top-level actor provided by the
|
||||||
|
|
@ -164,12 +164,12 @@ child not to survive this failure.
|
||||||
In case this is not desired (which depends on the use case), we need to use a
|
In case this is not desired (which depends on the use case), we need to use a
|
||||||
different supervisor which overrides this behavior.
|
different supervisor which overrides this behavior.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: supervisor2
|
:include: supervisor2
|
||||||
|
|
||||||
With this parent, the child survives the escalated restart, as demonstrated in
|
With this parent, the child survives the escalated restart, as demonstrated in
|
||||||
the last test:
|
the last test:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/FaultHandlingTest.java
|
.. includecode:: code/docs/actorlambda/FaultHandlingTest.java
|
||||||
:include: escalate-restart
|
:include: escalate-restart
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,11 @@ send them on after the burst ended or a flush request is received.
|
||||||
|
|
||||||
First, consider all of the below to use these import statements:
|
First, consider all of the below to use these import statements:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java#simple-imports
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java#simple-imports
|
||||||
|
|
||||||
The contract of our “Buncher” actor is that it accepts or produces the following messages:
|
The contract of our “Buncher” actor is that it accepts or produces the following messages:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Events.java
|
.. includecode:: code/docs/actorlambda/fsm/Events.java
|
||||||
:include: simple-events
|
:include: simple-events
|
||||||
:exclude: boilerplate
|
:exclude: boilerplate
|
||||||
|
|
||||||
|
|
@ -53,7 +53,7 @@ The contract of our “Buncher” actor is that it accepts or produces the follo
|
||||||
The actor can be in two states: no message queued (aka ``Idle``) or some
|
The actor can be in two states: no message queued (aka ``Idle``) or some
|
||||||
message queued (aka ``Active``). The states and the state data is defined like this:
|
message queued (aka ``Active``). The states and the state data is defined like this:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java
|
||||||
:include: simple-state
|
:include: simple-state
|
||||||
:exclude: boilerplate
|
:exclude: boilerplate
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ reference to send the batches to and the actual queue of messages.
|
||||||
|
|
||||||
Now let’s take a look at the skeleton for our FSM actor:
|
Now let’s take a look at the skeleton for our FSM actor:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java
|
||||||
:include: simple-fsm
|
:include: simple-fsm
|
||||||
:exclude: transition-elided,unhandled-elided
|
:exclude: transition-elided,unhandled-elided
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ shall work identically in both states, we make use of the fact that any event
|
||||||
which is not handled by the ``when()`` block is passed to the
|
which is not handled by the ``when()`` block is passed to the
|
||||||
``whenUnhandled()`` block:
|
``whenUnhandled()`` block:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java#unhandled-elided
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java#unhandled-elided
|
||||||
|
|
||||||
The first case handled here is adding ``Queue()`` requests to the internal
|
The first case handled here is adding ``Queue()`` requests to the internal
|
||||||
queue and going to the ``Active`` state (this does the obvious thing of staying
|
queue and going to the ``Active`` state (this does the obvious thing of staying
|
||||||
|
|
@ -107,7 +107,7 @@ target, for which we use the ``onTransition`` mechanism: you can declare
|
||||||
multiple such blocks and all of them will be tried for matching behavior in
|
multiple such blocks and all of them will be tried for matching behavior in
|
||||||
case a state transition occurs (i.e. only when the state actually changes).
|
case a state transition occurs (i.e. only when the state actually changes).
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java#transition-elided
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java#transition-elided
|
||||||
|
|
||||||
The transition callback is a partial function which takes as input a pair of
|
The transition callback is a partial function which takes as input a pair of
|
||||||
states—the current and the next state. During the state change, the old state
|
states—the current and the next state. During the state change, the old state
|
||||||
|
|
@ -117,7 +117,7 @@ available as ``nextStateData``.
|
||||||
To verify that this buncher actually works, it is quite easy to write a test
|
To verify that this buncher actually works, it is quite easy to write a test
|
||||||
using the :ref:`akka-testkit`, here using JUnit as an example:
|
using the :ref:`akka-testkit`, here using JUnit as an example:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/BuncherTest.java
|
.. includecode:: code/docs/actorlambda/fsm/BuncherTest.java
|
||||||
:include: test-code
|
:include: test-code
|
||||||
|
|
||||||
Reference
|
Reference
|
||||||
|
|
@ -129,7 +129,7 @@ The AbstractFSM Class
|
||||||
The :class:`AbstractFSM` abstract class is the base class used to implement an FSM. It implements
|
The :class:`AbstractFSM` abstract class is the base class used to implement an FSM. It implements
|
||||||
Actor since an Actor is created to drive the FSM.
|
Actor since an Actor is created to drive the FSM.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java
|
||||||
:include: simple-fsm
|
:include: simple-fsm
|
||||||
:exclude: fsm-body
|
:exclude: fsm-body
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ The :meth:`stateFunction` argument is a :class:`PartialFunction[Event, State]`,
|
||||||
which is conveniently given using the state function builder syntax as
|
which is conveniently given using the state function builder syntax as
|
||||||
demonstrated below:
|
demonstrated below:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/Buncher.java
|
.. includecode:: code/docs/actorlambda/fsm/Buncher.java
|
||||||
:include: when-syntax
|
:include: when-syntax
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
|
|
@ -193,7 +193,7 @@ It is recommended practice to declare the states as an enum and then verify that
|
||||||
``when`` clause for each of the states. If you want to leave the handling of a state
|
``when`` clause for each of the states. If you want to leave the handling of a state
|
||||||
“unhandled” (more below), it still needs to be declared like this:
|
“unhandled” (more below), it still needs to be declared like this:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java#NullFunction
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java#NullFunction
|
||||||
|
|
||||||
Defining the Initial State
|
Defining the Initial State
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
@ -213,7 +213,7 @@ If a state doesn't handle a received event a warning is logged. If you want to
|
||||||
do something else in this case you can specify that with
|
do something else in this case you can specify that with
|
||||||
:func:`whenUnhandled(stateFunction)`:
|
:func:`whenUnhandled(stateFunction)`:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: unhandled-syntax
|
:include: unhandled-syntax
|
||||||
|
|
||||||
Within this handler the state of the FSM may be queried using the
|
Within this handler the state of the FSM may be queried using the
|
||||||
|
|
@ -257,7 +257,7 @@ of the modifiers described in the following:
|
||||||
|
|
||||||
All modifiers can be chained to achieve a nice and concise description:
|
All modifiers can be chained to achieve a nice and concise description:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: modifier-syntax
|
:include: modifier-syntax
|
||||||
|
|
||||||
The parentheses are not actually needed in all cases, but they visually
|
The parentheses are not actually needed in all cases, but they visually
|
||||||
|
|
@ -294,14 +294,14 @@ The handler is a partial function which takes a pair of states as input; no
|
||||||
resulting state is needed as it is not possible to modify the transition in
|
resulting state is needed as it is not possible to modify the transition in
|
||||||
progress.
|
progress.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: transition-syntax
|
:include: transition-syntax
|
||||||
|
|
||||||
It is also possible to pass a function object accepting two states to
|
It is also possible to pass a function object accepting two states to
|
||||||
:func:`onTransition`, in case your transition handling logic is implemented as
|
:func:`onTransition`, in case your transition handling logic is implemented as
|
||||||
a method:
|
a method:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: alt-transition-syntax
|
:include: alt-transition-syntax
|
||||||
|
|
||||||
The handlers registered with this method are stacked, so you can intersperse
|
The handlers registered with this method are stacked, so you can intersperse
|
||||||
|
|
@ -377,14 +377,14 @@ state data which is available during termination handling.
|
||||||
the same way as a state transition (but note that the ``return`` statement
|
the same way as a state transition (but note that the ``return`` statement
|
||||||
may not be used within a :meth:`when` block).
|
may not be used within a :meth:`when` block).
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: stop-syntax
|
:include: stop-syntax
|
||||||
|
|
||||||
You can use :func:`onTermination(handler)` to specify custom code that is
|
You can use :func:`onTermination(handler)` to specify custom code that is
|
||||||
executed when the FSM is stopped. The handler is a partial function which takes
|
executed when the FSM is stopped. The handler is a partial function which takes
|
||||||
a :class:`StopEvent(reason, stateName, stateData)` as argument:
|
a :class:`StopEvent(reason, stateName, stateData)` as argument:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: termination-syntax
|
:include: termination-syntax
|
||||||
|
|
||||||
As for the :func:`whenUnhandled` case, this handler is not stacked, so each
|
As for the :func:`whenUnhandled` case, this handler is not stacked, so each
|
||||||
|
|
@ -418,7 +418,7 @@ Event Tracing
|
||||||
The setting ``akka.actor.debug.fsm`` in :ref:`configuration` enables logging of an
|
The setting ``akka.actor.debug.fsm`` in :ref:`configuration` enables logging of an
|
||||||
event trace by :class:`LoggingFSM` instances:
|
event trace by :class:`LoggingFSM` instances:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: logging-fsm
|
:include: logging-fsm
|
||||||
:exclude: body-elided
|
:exclude: body-elided
|
||||||
|
|
||||||
|
|
@ -439,7 +439,7 @@ The :class:`AbstractLoggingFSM` class adds one more feature to the FSM: a rollin
|
||||||
log which may be used during debugging (for tracing how the FSM entered a
|
log which may be used during debugging (for tracing how the FSM entered a
|
||||||
certain failure state) or for other creative uses:
|
certain failure state) or for other creative uses:
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-java-lambda/src/test/java/docs/actor/fsm/FSMDocTest.java
|
.. includecode:: code/docs/actorlambda/fsm/FSMDocTest.java
|
||||||
:include: logging-fsm
|
:include: logging-fsm
|
||||||
|
|
||||||
The :meth:`logDepth` defaults to zero, which turns off the event log.
|
The :meth:`logDepth` defaults to zero, which turns off the event log.
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
|
|
||||||
package docs.io
|
package docs.io
|
||||||
|
|
||||||
import java.net.{InetAddress, InetSocketAddress, NetworkInterface, StandardProtocolFamily}
|
import java.net.{ InetAddress, InetSocketAddress, NetworkInterface, StandardProtocolFamily }
|
||||||
import java.net.DatagramSocket
|
import java.net.DatagramSocket
|
||||||
import java.nio.channels.DatagramChannel
|
import java.nio.channels.DatagramChannel
|
||||||
|
|
||||||
import akka.actor.{Actor, ActorLogging, ActorRef}
|
import akka.actor.{ Actor, ActorLogging, ActorRef }
|
||||||
import akka.io.Inet.{DatagramChannelCreator, SocketOption, SocketOptionV2}
|
import akka.io.Inet.{ DatagramChannelCreator, SocketOption, SocketOptionV2 }
|
||||||
import akka.io.{IO, Udp}
|
import akka.io.{ IO, Udp }
|
||||||
import akka.util.ByteString
|
import akka.util.ByteString
|
||||||
|
|
||||||
//#inet6-protocol-family
|
//#inet6-protocol-family
|
||||||
|
|
@ -4,14 +4,14 @@
|
||||||
|
|
||||||
package docs.io
|
package docs.io
|
||||||
|
|
||||||
import java.net.{Inet6Address, InetSocketAddress, NetworkInterface, StandardProtocolFamily}
|
import java.net.{ Inet6Address, InetSocketAddress, NetworkInterface, StandardProtocolFamily }
|
||||||
import java.nio.channels.DatagramChannel
|
import java.nio.channels.DatagramChannel
|
||||||
import scala.util.Random
|
import scala.util.Random
|
||||||
|
|
||||||
import akka.actor.{ActorSystem, Props}
|
import akka.actor.{ ActorSystem, Props }
|
||||||
import akka.io.Udp
|
import akka.io.Udp
|
||||||
import akka.testkit.TestKit
|
import akka.testkit.TestKit
|
||||||
import org.scalatest.{BeforeAndAfter, WordSpecLike}
|
import org.scalatest.{ BeforeAndAfter, WordSpecLike }
|
||||||
|
|
||||||
import scala.collection.JavaConversions.enumerationAsScalaIterator
|
import scala.collection.JavaConversions.enumerationAsScalaIterator
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ class ScalaUdpMulticastSpec extends TestKit(ActorSystem("ScalaUdpMulticastSpec")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def afterAll = {
|
def afterAll(): Unit = {
|
||||||
TestKit.shutdownActorSystem(system)
|
TestKit.shutdownActorSystem(system)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,12 +95,12 @@ To select a Protocol Family you must extend ``akka.io.Inet.DatagramChannelCreato
|
||||||
class which extends ``akka.io.Inet.SocketOption``. Provide custom logic
|
class which extends ``akka.io.Inet.SocketOption``. Provide custom logic
|
||||||
for opening a datagram channel by overriding :meth:`create` method.
|
for opening a datagram channel by overriding :meth:`create` method.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-udp-multicast/src/main/scala/ScalaUdpMulticast.scala#inet6-protocol-family
|
.. includecode:: code/docs/io/ScalaUdpMulticast.scala#inet6-protocol-family
|
||||||
|
|
||||||
Another socket option will be needed to join a multicast group.
|
Another socket option will be needed to join a multicast group.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-udp-multicast/src/main/scala/ScalaUdpMulticast.scala#multicast-group
|
.. includecode:: code/docs/io/ScalaUdpMulticast.scala#multicast-group
|
||||||
|
|
||||||
Socket options must be provided to :class:`UdpMessage.Bind` message.
|
Socket options must be provided to :class:`UdpMessage.Bind` message.
|
||||||
|
|
||||||
.. includecode:: ../../../akka-samples/akka-docs-udp-multicast/src/main/scala/ScalaUdpMulticast.scala#bind
|
.. includecode:: code/docs/io/ScalaUdpMulticast.scala#bind
|
||||||
|
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
name := "akka-docs-java-lambda"
|
|
||||||
|
|
||||||
version := "2.4-SNAPSHOT"
|
|
||||||
|
|
||||||
scalaVersion := "2.11.5"
|
|
||||||
|
|
||||||
compileOrder := CompileOrder.ScalaThenJava
|
|
||||||
|
|
||||||
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
|
|
||||||
|
|
||||||
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
|
|
||||||
|
|
||||||
libraryDependencies ++= Seq(
|
|
||||||
"com.typesafe.akka" %% "akka-actor" % "2.4-SNAPSHOT",
|
|
||||||
"com.typesafe.akka" %% "akka-testkit" % "2.4-SNAPSHOT" % "test",
|
|
||||||
"junit" % "junit" % "4.11" % "test",
|
|
||||||
"com.novocode" % "junit-interface" % "0.10" % "test")
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
|
|
||||||
http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<groupId>sample</groupId>
|
|
||||||
<artifactId>akka-docs-java-lambda</artifactId>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
<version>2.4-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.typesafe.akka</groupId>
|
|
||||||
<artifactId>akka-actor_2.11</artifactId>
|
|
||||||
<version>2.4-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.typesafe.akka</groupId>
|
|
||||||
<artifactId>akka-testkit_2.11</artifactId>
|
|
||||||
<version>2.4-SNAPSHOT</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>4.11</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
<fork>true</fork>
|
|
||||||
<compilerArgs>
|
|
||||||
<arg>-Xlint</arg>
|
|
||||||
</compilerArgs>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
sbt.version=0.13.7
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
name := "akka-docs-udp-multicast"
|
|
||||||
|
|
||||||
version := "2.4-SNAPSHOT"
|
|
||||||
|
|
||||||
scalaVersion := "2.11.5"
|
|
||||||
|
|
||||||
compileOrder := CompileOrder.ScalaThenJava
|
|
||||||
|
|
||||||
javacOptions ++= Seq("-source", "1.7", "-target", "1.7", "-Xlint")
|
|
||||||
|
|
||||||
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
|
|
||||||
|
|
||||||
libraryDependencies ++= Seq(
|
|
||||||
"com.typesafe.akka" %% "akka-actor" % "2.4-SNAPSHOT",
|
|
||||||
"com.typesafe.akka" %% "akka-testkit" % "2.4-SNAPSHOT",
|
|
||||||
"org.scalatest" %% "scalatest" % "2.2.1" % "test",
|
|
||||||
"junit" % "junit" % "4.11" % "test",
|
|
||||||
"com.novocode" % "junit-interface" % "0.10" % "test"
|
|
||||||
)
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
sbt.version=0.13.7
|
|
||||||
|
|
@ -10,9 +10,9 @@ val project = Project(
|
||||||
name := "akka-sample-cluster-java",
|
name := "akka-sample-cluster-java",
|
||||||
version := "2.4-SNAPSHOT",
|
version := "2.4-SNAPSHOT",
|
||||||
scalaVersion := "2.11.5",
|
scalaVersion := "2.11.5",
|
||||||
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.8", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
||||||
javacOptions in Compile ++= Seq("-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-Xlint:deprecation"),
|
javacOptions in Compile ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint:unchecked", "-Xlint:deprecation"),
|
||||||
javacOptions in doc in Compile := Seq("-source", "1.6"), // javadoc does not support -target and -Xlint flags
|
javacOptions in doc in Compile := Seq("-source", "1.8", "-Xdoclint:none"),
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
|
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
|
||||||
"com.typesafe.akka" %% "akka-remote" % akkaVersion,
|
"com.typesafe.akka" %% "akka-remote" % akkaVersion,
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@ val project = Project(
|
||||||
name := "akka-sample-cluster-scala",
|
name := "akka-sample-cluster-scala",
|
||||||
version := "2.4-SNAPSHOT",
|
version := "2.4-SNAPSHOT",
|
||||||
scalaVersion := "2.11.5",
|
scalaVersion := "2.11.5",
|
||||||
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.8", "-deprecation", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
||||||
javacOptions in Compile ++= Seq("-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-Xlint:deprecation"),
|
javacOptions in Compile ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint:unchecked", "-Xlint:deprecation"),
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
|
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
|
||||||
"com.typesafe.akka" %% "akka-remote" % akkaVersion,
|
"com.typesafe.akka" %% "akka-remote" % akkaVersion,
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ name := "akka-docs-java-lambda"
|
||||||
|
|
||||||
version := "2.4-SNAPSHOT"
|
version := "2.4-SNAPSHOT"
|
||||||
|
|
||||||
scalaVersion := "2.11.5"
|
scalaVersion := "2.11.6"
|
||||||
|
|
||||||
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
|
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8", "-Xlint")
|
||||||
|
|
||||||
|
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.8")
|
||||||
|
|
||||||
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
|
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ version := "1.0"
|
||||||
|
|
||||||
scalaVersion := "2.11.5"
|
scalaVersion := "2.11.5"
|
||||||
|
|
||||||
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
|
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8", "-Xlint")
|
||||||
|
|
||||||
|
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-Xdoclint:none")
|
||||||
|
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"com.typesafe.akka" %% "akka-persistence-experimental" % "2.4-SNAPSHOT"
|
"com.typesafe.akka" %% "akka-persistence-experimental" % "2.4-SNAPSHOT"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ version := "1.0"
|
||||||
|
|
||||||
scalaVersion := "2.11.5"
|
scalaVersion := "2.11.5"
|
||||||
|
|
||||||
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
|
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8", "-Xlint")
|
||||||
|
|
||||||
|
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-Xdoclint:none")
|
||||||
|
|
||||||
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
|
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ public class JavaTestKit {
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* <code>
|
* <code>
|
||||||
* final String out = new ExpectMsg<String>("match hint") {
|
* final String out = new ExpectMsg<String>("match hint") {
|
||||||
* protected String match(Object in) {
|
* protected String match(Object in) {
|
||||||
* if (in instanceof Integer)
|
* if (in instanceof Integer)
|
||||||
* return "match";
|
* return "match";
|
||||||
|
|
|
||||||
|
|
@ -203,9 +203,10 @@ object AkkaBuild extends Build {
|
||||||
settings = parentSettings ++ ActivatorDist.settings,
|
settings = parentSettings ++ ActivatorDist.settings,
|
||||||
// FIXME osgiDiningHakkersSampleMavenTest temporarily removed from aggregate due to #16703
|
// FIXME osgiDiningHakkersSampleMavenTest temporarily removed from aggregate due to #16703
|
||||||
aggregate = if (!CommandLineOptions.aggregateSamples) Nil else
|
aggregate = if (!CommandLineOptions.aggregateSamples) Nil else
|
||||||
Seq(sampleCamelJava, sampleCamelScala, sampleClusterJava, sampleClusterScala, sampleFsmScala,
|
Seq(sampleCamelJava, sampleCamelScala, sampleClusterJava, sampleClusterScala, sampleFsmScala, sampleFsmJavaLambda,
|
||||||
sampleMainJava, sampleMainScala, sampleMultiNodeScala,
|
sampleMainJava, sampleMainScala, sampleMainJavaLambda, sampleMultiNodeScala,
|
||||||
samplePersistenceJava, samplePersistenceScala, sampleRemoteJava, sampleRemoteScala)
|
samplePersistenceJava, samplePersistenceScala, samplePersistenceJavaLambda,
|
||||||
|
sampleRemoteJava, sampleRemoteScala, sampleSupervisionJavaLambda)
|
||||||
)
|
)
|
||||||
|
|
||||||
lazy val sampleCamelJava = Sample.project("akka-sample-camel-java")
|
lazy val sampleCamelJava = Sample.project("akka-sample-camel-java")
|
||||||
|
|
@ -215,18 +216,23 @@ object AkkaBuild extends Build {
|
||||||
lazy val sampleClusterScala = Sample.project("akka-sample-cluster-scala")
|
lazy val sampleClusterScala = Sample.project("akka-sample-cluster-scala")
|
||||||
|
|
||||||
lazy val sampleFsmScala = Sample.project("akka-sample-fsm-scala")
|
lazy val sampleFsmScala = Sample.project("akka-sample-fsm-scala")
|
||||||
|
lazy val sampleFsmJavaLambda = Sample.project("akka-sample-fsm-java-lambda")
|
||||||
|
|
||||||
lazy val sampleMainJava = Sample.project("akka-sample-main-java")
|
lazy val sampleMainJava = Sample.project("akka-sample-main-java")
|
||||||
lazy val sampleMainScala = Sample.project("akka-sample-main-scala")
|
lazy val sampleMainScala = Sample.project("akka-sample-main-scala")
|
||||||
|
lazy val sampleMainJavaLambda = Sample.project("akka-sample-main-java-lambda")
|
||||||
|
|
||||||
lazy val sampleMultiNodeScala = Sample.project("akka-sample-multi-node-scala")
|
lazy val sampleMultiNodeScala = Sample.project("akka-sample-multi-node-scala")
|
||||||
|
|
||||||
lazy val samplePersistenceJava = Sample.project("akka-sample-persistence-java")
|
lazy val samplePersistenceJava = Sample.project("akka-sample-persistence-java")
|
||||||
lazy val samplePersistenceScala = Sample.project("akka-sample-persistence-scala")
|
lazy val samplePersistenceScala = Sample.project("akka-sample-persistence-scala")
|
||||||
|
lazy val samplePersistenceJavaLambda = Sample.project("akka-sample-persistence-java-lambda")
|
||||||
|
|
||||||
lazy val sampleRemoteJava = Sample.project("akka-sample-remote-java")
|
lazy val sampleRemoteJava = Sample.project("akka-sample-remote-java")
|
||||||
lazy val sampleRemoteScala = Sample.project("akka-sample-remote-scala")
|
lazy val sampleRemoteScala = Sample.project("akka-sample-remote-scala")
|
||||||
|
|
||||||
|
lazy val sampleSupervisionJavaLambda = Sample.project("akka-sample-supervision-java-lambda")
|
||||||
|
|
||||||
lazy val osgiDiningHakkersSampleMavenTest = Project(id = "akka-sample-osgi-dining-hakkers-maven-test",
|
lazy val osgiDiningHakkersSampleMavenTest = Project(id = "akka-sample-osgi-dining-hakkers-maven-test",
|
||||||
base = file("akka-samples/akka-sample-osgi-dining-hakkers-maven-test"),
|
base = file("akka-samples/akka-sample-osgi-dining-hakkers-maven-test"),
|
||||||
settings = Seq(
|
settings = Seq(
|
||||||
|
|
@ -305,13 +311,13 @@ object AkkaBuild extends Build {
|
||||||
lazy val defaultSettings = baseSettings ++ resolverSettings ++ TestExtras.Filter.settings ++
|
lazy val defaultSettings = baseSettings ++ resolverSettings ++ TestExtras.Filter.settings ++
|
||||||
Protobuf.settings ++ Seq(
|
Protobuf.settings ++ Seq(
|
||||||
// compile options
|
// compile options
|
||||||
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.6", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
scalacOptions in Compile ++= Seq("-encoding", "UTF-8", "-target:jvm-1.8", "-feature", "-unchecked", "-Xlog-reflective-calls", "-Xlint"),
|
||||||
scalacOptions in Compile ++= (if (allWarnings) Seq("-deprecation") else Nil),
|
scalacOptions in Compile ++= (if (allWarnings) Seq("-deprecation") else Nil),
|
||||||
scalacOptions in Test := (scalacOptions in Test).value.filterNot(_ == "-Xlog-reflective-calls"),
|
scalacOptions in Test := (scalacOptions in Test).value.filterNot(_ == "-Xlog-reflective-calls"),
|
||||||
// -XDignore.symbol.file suppresses sun.misc.Unsafe warnings
|
// -XDignore.symbol.file suppresses sun.misc.Unsafe warnings
|
||||||
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.6", "-target", "1.6", "-Xlint:unchecked", "-XDignore.symbol.file"),
|
javacOptions in compile ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-target", "1.8", "-Xlint:unchecked", "-XDignore.symbol.file"),
|
||||||
javacOptions in compile ++= (if (allWarnings) Seq("-Xlint:deprecation") else Nil),
|
javacOptions in compile ++= (if (allWarnings) Seq("-Xlint:deprecation") else Nil),
|
||||||
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.6"),
|
javacOptions in doc ++= Seq("-encoding", "UTF-8", "-source", "1.8", "-Xdoclint:none"),
|
||||||
incOptions := incOptions.value.withNameHashing(true),
|
incOptions := incOptions.value.withNameHashing(true),
|
||||||
|
|
||||||
crossVersion := CrossVersion.binary,
|
crossVersion := CrossVersion.binary,
|
||||||
|
|
|
||||||
|
|
@ -1,136 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# defaults
|
|
||||||
declare -r default_java_home="/usr/local/share/java/jdk6"
|
|
||||||
declare -r default_java8_home="/usr/local/share/java/jdk8"
|
|
||||||
declare -r default_sbt_jar="/usr/share/sbt-launcher-packaging/bin/sbt-launch.jar"
|
|
||||||
declare -r default_ivy_home="~/.ivy2"
|
|
||||||
|
|
||||||
# get the source location for this script; handles symlinks
|
|
||||||
function get_script_path {
|
|
||||||
local source="${BASH_SOURCE[0]}"
|
|
||||||
while [ -h "${source}" ] ; do
|
|
||||||
source="$(readlink "${source}")";
|
|
||||||
done
|
|
||||||
echo ${source}
|
|
||||||
}
|
|
||||||
|
|
||||||
# path, name, and dir for this script
|
|
||||||
declare -r script_path=$(get_script_path)
|
|
||||||
declare -r script_name=$(basename "${script_path}")
|
|
||||||
declare -r script_dir="$(cd -P "$(dirname "${script_path}")" && pwd)"
|
|
||||||
|
|
||||||
# print usage info
|
|
||||||
function usage {
|
|
||||||
cat <<EOM
|
|
||||||
Usage: ${script_name} [options] VERSION
|
|
||||||
-h | --help Print this usage message
|
|
||||||
--java_home PATH Set the path to the "standard" java version
|
|
||||||
--java8_home PATH Set the path to the java 8 version
|
|
||||||
|
|
||||||
This script assumes that the mvn command is in your path.
|
|
||||||
EOM
|
|
||||||
}
|
|
||||||
|
|
||||||
# echo a log message
|
|
||||||
function echolog {
|
|
||||||
echo "[${script_name}] $@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# echo an error message
|
|
||||||
function echoerr {
|
|
||||||
echo "[${script_name}] $@" 1>&2
|
|
||||||
}
|
|
||||||
|
|
||||||
# fail the script with an error message
|
|
||||||
function fail {
|
|
||||||
echoerr "$@"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
# try to run a command or otherwise fail with a message
|
|
||||||
function try {
|
|
||||||
"${@:1:$#-1}" || fail "${@:$#}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# try to run a command or otherwise fail
|
|
||||||
function check {
|
|
||||||
type -P "$@" &> /dev/null || fail "command not found: $@"
|
|
||||||
}
|
|
||||||
|
|
||||||
# run mvn clean test using the specified java home in the specified directory
|
|
||||||
function mvncleantest {
|
|
||||||
tmp="$script_dir/../../$2"
|
|
||||||
try cd "$tmp" "can't step into project directory: $tmp"
|
|
||||||
export JAVA_HOME="$1"
|
|
||||||
try mvn clean test "mvn execution in $2 failed"
|
|
||||||
}
|
|
||||||
|
|
||||||
# run sbt clean test using the specified java home in the specified directory
|
|
||||||
function sbtcleantest {
|
|
||||||
tmp="$script_dir/../../$2"
|
|
||||||
try cd "$tmp" "can't step into project directory: $tmp"
|
|
||||||
orig_path="$PATH"
|
|
||||||
export PATH="$1/bin:$PATH"
|
|
||||||
try java -jar $sbt_jar -Dsbt.ivy.home=$ivy_home clean test "sbt execution in $2 failed"
|
|
||||||
export PATH="$orig_path"
|
|
||||||
}
|
|
||||||
|
|
||||||
# initialize variables with defaults and override from environment
|
|
||||||
declare java_home="$default_java_home"
|
|
||||||
if [ $AKKA_BUILD_JAVA_HOME ]; then
|
|
||||||
java_home="$AKKA_BUILD_JAVA_HOME"
|
|
||||||
fi
|
|
||||||
|
|
||||||
declare java8_home="$default_java8_home"
|
|
||||||
if [ $AKKA_BUILD_JAVA8_HOME ]; then
|
|
||||||
java8_home="$AKKA_BUILD_JAVA8_HOME"
|
|
||||||
fi
|
|
||||||
|
|
||||||
declare sbt_jar="$default_sbt_jar"
|
|
||||||
if [ $AKKA_BUILD_SBT_JAR ]; then
|
|
||||||
sbt_jar="$AKKA_BUILD_SBT_JAR"
|
|
||||||
fi
|
|
||||||
|
|
||||||
declare ivy_home="$default_ivy_home"
|
|
||||||
if [ $AKKA_BUILD_IVY_HOME ]; then
|
|
||||||
ivy_home="$AKKA_BUILD_IVY_HOME"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# process options and set flags
|
|
||||||
while true; do
|
|
||||||
case "$1" in
|
|
||||||
-h | --help ) usage; exit 1 ;;
|
|
||||||
--java_home ) java_home=$2; shift 2 ;;
|
|
||||||
--java8_home ) java8_home=$2; shift 2 ;;
|
|
||||||
* ) break ;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
declare -r java_path="$java_home/bin/java"
|
|
||||||
declare -r java8_path="$java8_home/bin/java"
|
|
||||||
|
|
||||||
# check that java paths work
|
|
||||||
check "$java_path"
|
|
||||||
check "$java8_path"
|
|
||||||
|
|
||||||
# check for a mvn command
|
|
||||||
check mvn
|
|
||||||
|
|
||||||
# now do some work
|
|
||||||
mvncleantest "$java8_home" "akka-samples/akka-docs-java-lambda"
|
|
||||||
|
|
||||||
mvncleantest "$java8_home" "akka-samples/akka-sample-fsm-java-lambda"
|
|
||||||
|
|
||||||
mvncleantest "$java8_home" "akka-samples/akka-sample-persistence-java-lambda"
|
|
||||||
|
|
||||||
mvncleantest "$java8_home" "akka-samples/akka-sample-supervision-java-lambda"
|
|
||||||
|
|
||||||
sample_dir=akka-samples/akka-sample-main-java-lambda
|
|
||||||
tmp="$script_dir/../../$sample_dir"
|
|
||||||
try cd "$tmp" "can't step into project directory: $tmp"
|
|
||||||
export JAVA_HOME="$java8_home"
|
|
||||||
try mvn clean compile exec:java -Dexec.mainClass="akka.Main" -Dexec.args="sample.hello.HelloWorld" "mvn execution in $sample_dir failed"
|
|
||||||
try mvn exec:java -Dexec.mainClass="sample.hello.Main2" "mvn execution in $sample_dir failed"
|
|
||||||
|
|
||||||
sbtcleantest "$java8_home" "akka-samples/akka-docs-udp-multicast"
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue