ActorContext.getParent for Java API #22413

This commit is contained in:
Johan Andrén 2017-03-16 09:30:00 +01:00 committed by GitHub
parent 5ff44194a3
commit 2eb226ed32
213 changed files with 1319 additions and 1523 deletions

View file

@ -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;
}
}
}

View file

@ -1,7 +1,7 @@
/*
* Copyright (C) 2016-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs
package jdocs
import org.scalatest.junit.JUnitSuite

View file

@ -2,14 +2,15 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
import akka.actor.*;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import docs.AbstractJavaTest;
import static docs.actorlambda.Messages.Swap.Swap;
import static docs.actorlambda.Messages.*;
import jdocs.AbstractJavaTest;
import static jdocs.actor.Messages.Swap.Swap;
import static jdocs.actor.Messages.*;
import static akka.japi.Util.immutableSeq;
import akka.actor.CoordinatedShutdown;
import akka.util.Timeout;
@ -41,7 +42,7 @@ import akka.actor.Identify;
//#import-ask
import static akka.pattern.PatternsCS.ask;
import static akka.pattern.PatternsCS.pipe;
import akka.util.Timeout;
import java.util.concurrent.CompletableFuture;
//#import-ask
//#import-gracefulStop
@ -85,7 +86,7 @@ public class ActorDocTest extends AbstractJavaTest {
@Override
public Receive createReceive() {
return receiveBuilder()
.matchAny(x -> sender().tell(x, self()))
.matchAny(x -> getSender().tell(x, getSelf()))
.build();
}
//#plus-some-behavior
@ -206,7 +207,7 @@ public class ActorDocTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(Integer.class, i -> {
sender().tell(i + magicNumber, self());
getSender().tell(i + magicNumber, getSelf());
})
.build();
}
@ -311,7 +312,7 @@ public class ActorDocTest extends AbstractJavaTest {
final String message = "stopped";
//#tell
// dont forget to think about who is the sender (2nd argument)
target.tell(message, self());
target.tell(message, getSelf());
//#tell
final Object result = "";
//#forward
@ -353,9 +354,9 @@ public class ActorDocTest extends AbstractJavaTest {
//#reply-exception
try {
String result = operation();
sender().tell(result, self());
getSender().tell(result, getSelf());
} catch (Exception e) {
sender().tell(new akka.actor.Status.Failure(e), self());
getSender().tell(new akka.actor.Status.Failure(e), getSelf());
throw e;
}
//#reply-exception
@ -383,10 +384,10 @@ public class ActorDocTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.matchEquals("job", s -> {
worker.tell("crunch", self());
worker.tell("crunch", getSelf());
})
.matchEquals(SHUTDOWN, x -> {
worker.tell(PoisonPill.getInstance(), self());
worker.tell(PoisonPill.getInstance(), getSelf());
getContext().become(shuttingDown());
})
.build();
@ -394,8 +395,8 @@ public class ActorDocTest extends AbstractJavaTest {
private AbstractActor.Receive shuttingDown() {
return receiveBuilder()
.matchEquals("job", s ->
sender().tell("service unavailable, shutting down", self())
.matchEquals("job", s ->
getSender().tell("service unavailable, shutting down", getSelf())
)
.match(Terminated.class, t -> t.actor().equals(worker), t ->
getContext().stop(self())
@ -530,7 +531,7 @@ public class ActorDocTest extends AbstractJavaTest {
//#receive-timeout
public class ReceiveTimeoutActor extends AbstractActor {
//#receive-timeout
ActorRef target = getContext().system().deadLetters();
ActorRef target = getContext().getSystem().deadLetters();
//#receive-timeout
public ReceiveTimeoutActor() {
// To set an initial delay
@ -544,15 +545,15 @@ public class ActorDocTest extends AbstractJavaTest {
// To set in a response to a message
getContext().setReceiveTimeout(Duration.create(1, TimeUnit.SECONDS));
//#receive-timeout
target = sender();
target.tell("Hello world", self());
target = getSender();
target.tell("Hello world", getSelf());
//#receive-timeout
})
.match(ReceiveTimeout.class, r -> {
// To turn it off
getContext().setReceiveTimeout(Duration.Undefined());
//#receive-timeout
target.tell("timeout", self());
target.tell("timeout", getSelf());
//#receive-timeout
})
.build();
@ -582,7 +583,7 @@ public class ActorDocTest extends AbstractJavaTest {
angry =
receiveBuilder()
.matchEquals("foo", s -> {
sender().tell("I am already angry?", self());
getSender().tell("I am already angry?", getSelf());
})
.matchEquals("bar", s -> {
getContext().become(happy);
@ -591,7 +592,7 @@ public class ActorDocTest extends AbstractJavaTest {
happy = receiveBuilder()
.matchEquals("bar", s -> {
sender().tell("I am already happy :-)", self());
getSender().tell("I am already happy :-)", getSelf());
})
.matchEquals("foo", s -> {
getContext().become(angry);
@ -675,10 +676,10 @@ public class ActorDocTest extends AbstractJavaTest {
return receiveBuilder()
.matchEquals("kill", s -> {
getContext().stop(child);
lastSender = sender();
lastSender = getSender();
})
.match(Terminated.class, t -> t.actor().equals(child), t -> {
lastSender.tell("finished", self());
lastSender.tell("finished", getSelf());
})
.build();
}
@ -704,7 +705,7 @@ public class ActorDocTest extends AbstractJavaTest {
public Follower(){
ActorSelection selection = getContext().actorSelection("/user/another");
selection.tell(new Identify(identifyId), self());
selection.tell(new Identify(identifyId), getSelf());
}
@Override

View file

@ -2,7 +2,7 @@
* Copyright (C) 2016-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actor;
package jdocs.actor;
//#bytebufserializer-with-manifest
import akka.serialization.ByteBufferSerializer;

View file

@ -1,9 +1,9 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -35,7 +35,7 @@ public class DependencyInjectionDocTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(String.class, msg -> {
sender().tell(s, self());
getSender().tell(s, getSelf());
})
.build();
}

View file

@ -1,14 +1,14 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
import akka.actor.*;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import java.util.Optional;
import static akka.pattern.Patterns.ask;
@ -73,7 +73,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(Props.class, props -> {
sender().tell(getContext().actorOf(props), self());
getSender().tell(getContext().actorOf(props), getSelf());
})
.build();
}
@ -104,7 +104,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(Props.class, props -> {
sender().tell(getContext().actorOf(props), self());
getSender().tell(getContext().actorOf(props), getSelf());
})
.build();
}
@ -127,7 +127,7 @@ public class FaultHandlingTest extends AbstractJavaTest {
return receiveBuilder()
.match(Exception.class, exception -> { throw exception; })
.match(Integer.class, i -> state = i)
.matchEquals("get", s -> sender().tell(state, self()))
.matchEquals("get", s -> getSender().tell(state, getSelf()))
.build();
}
}

View file

@ -2,20 +2,19 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
//#imports
import akka.actor.AbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import akka.japi.pf.ReceiveBuilder;
import akka.japi.pf.UnitPFBuilder;
//#imports
//#actor
public class GraduallyBuiltActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
@Override
public Receive createReceive() {
@ -25,7 +24,7 @@ public class GraduallyBuiltActor extends AbstractActor {
log.info("Received String message: {}", s);
//#actor
//#reply
sender().tell(s, self());
getSender().tell(s, getSelf());
//#reply
//#actor
});

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actor;
package jdocs.actor;
import java.util.ArrayList;
import java.util.Collections;

View file

@ -2,12 +2,12 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actor;
package jdocs.actor;
import java.util.concurrent.TimeUnit;
import akka.testkit.AkkaJUnitActorSystemResource;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.ClassRule;
import org.junit.Test;

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
@ -9,7 +9,7 @@ import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.japi.pf.FI;
import akka.testkit.JavaTestKit;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -75,7 +75,7 @@ public class InitializationDocTest extends AbstractJavaTest {
initializeMe = "Up and running";
getContext().become(receiveBuilder()
.matchEquals("U OK?", m2 -> {
sender().tell(initializeMe, self());
getSender().tell(initializeMe, getSelf());
})
.build());
})
@ -98,7 +98,7 @@ public class InitializationDocTest extends AbstractJavaTest {
return receiveBuilder()
.matchUnchecked(GenericMessage.class, (GenericMessage<String> msg) -> {
GenericMessage<String> message = msg;
sender().tell(message.value.toUpperCase(), self());
getSender().tell(message.value.toUpperCase(), getSelf());
})
.build();
}
@ -111,7 +111,7 @@ public class InitializationDocTest extends AbstractJavaTest {
return receiveBuilder()
.matchUnchecked(GenericMessage.class, typedPredicate, (GenericMessage<String> msg) -> {
sender().tell(msg.value.toUpperCase(), self());
getSender().tell(msg.value.toUpperCase(), getSelf());
})
.build();
}

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actor;
package jdocs.actor;
import java.util.ArrayList;
import java.util.Collections;

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
//#imports
import akka.actor.AbstractActor;
@ -13,7 +13,7 @@ import akka.event.LoggingAdapter;
//#my-actor
public class MyActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
@Override
public Receive createReceive() {
@ -22,7 +22,7 @@ public class MyActor extends AbstractActor {
log.info("Received String message: {}", s);
//#my-actor
//#reply
sender().tell(s, self());
getSender().tell(s, getSelf());
//#reply
//#my-actor
})

View file

@ -2,13 +2,13 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
//#my-bounded-untyped-actor
import akka.dispatch.BoundedMessageQueueSemantics;
import akka.dispatch.RequiresMessageQueue;
public class MyBoundedActor extends MyActor
public class MyBoundedActor extends MyActor
implements RequiresMessageQueue<BoundedMessageQueueSemantics> {
}
//#my-bounded-untyped-actor

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
//#my-stopping-actor
import akka.actor.ActorRef;
@ -20,7 +20,7 @@ public class MyStoppingActor extends AbstractActor {
getContext().stop(child)
)
.matchEquals("done", m ->
getContext().stop(self())
getContext().stop(getSelf())
)
.build();
}

View file

@ -2,17 +2,16 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
//#sample-actor
import akka.actor.AbstractActor;
import akka.japi.pf.ReceiveBuilder;
public class SampleActor extends AbstractActor {
private Receive guarded = receiveBuilder()
.match(String.class, s -> s.contains("guard"), s -> {
sender().tell("contains(guard): " + s, self());
getSender().tell("contains(guard): " + s, getSelf());
getContext().unbecome();
})
.build();
@ -21,13 +20,13 @@ public class SampleActor extends AbstractActor {
public Receive createReceive() {
return receiveBuilder()
.match(Double.class, d -> {
sender().tell(d.isNaN() ? 0 : d, self());
getSender().tell(d.isNaN() ? 0 : d, getSelf());
})
.match(Integer.class, i -> {
sender().tell(i * 10, self());
getSender().tell(i * 10, getSelf());
})
.match(String.class, s -> s.startsWith("guard"), s -> {
sender().tell("startsWith(guard): " + s.toUpperCase(), self());
getSender().tell("startsWith(guard): " + s.toUpperCase(), getSelf());
getContext().become(guarded, false);
})
.build();

View file

@ -2,13 +2,13 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda;
package jdocs.actor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.testkit.JavaTestKit;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

View file

@ -1,11 +1,11 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actor;
package jdocs.actor;
//#imports1
import akka.actor.Props;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import scala.concurrent.duration.Duration;
import java.util.concurrent.TimeUnit;
//#imports1
@ -14,7 +14,6 @@ import java.util.concurrent.TimeUnit;
import akka.actor.Cancellable;
//#imports2
import docs.actorlambda.MyActor;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actor;
package jdocs.actor;
//#imports
@ -10,7 +10,7 @@ import akka.actor.*;
import akka.japi.*;
import akka.dispatch.Futures;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import scala.concurrent.Await;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda.fsm;
package jdocs.actor.fsm;
//#simple-imports
import akka.actor.AbstractFSM;
@ -14,11 +14,11 @@ import java.util.List;
import scala.concurrent.duration.Duration;
//#simple-imports
import static docs.actorlambda.fsm.Buncher.Data;
import static docs.actorlambda.fsm.Buncher.State.*;
import static docs.actorlambda.fsm.Buncher.State;
import static docs.actorlambda.fsm.Buncher.Uninitialized.*;
import static docs.actorlambda.fsm.Events.*;
import static jdocs.actor.fsm.Buncher.Data;
import static jdocs.actor.fsm.Buncher.State.*;
import static jdocs.actor.fsm.Buncher.State;
import static jdocs.actor.fsm.Buncher.Uninitialized.*;
import static jdocs.actor.fsm.Events.*;
//#simple-fsm
public class Buncher extends AbstractFSM<State, Data> {

View file

@ -2,23 +2,22 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda.fsm;
package jdocs.actor.fsm;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import akka.testkit.JavaTestKit;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import java.util.LinkedList;
import docs.actorlambda.fsm.*;
import static docs.actorlambda.fsm.Events.Batch;
import static docs.actorlambda.fsm.Events.Queue;
import static docs.actorlambda.fsm.Events.SetTarget;
import static docs.actorlambda.fsm.Events.Flush.Flush;
import static jdocs.actor.fsm.Events.Batch;
import static jdocs.actor.fsm.Events.Queue;
import static jdocs.actor.fsm.Events.SetTarget;
import static jdocs.actor.fsm.Events.Flush.Flush;
//#test-code
public class BuncherTest extends AbstractJavaTest {

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda.fsm;
package jdocs.actor.fsm;
import akka.actor.ActorRef;
import java.util.List;

View file

@ -2,12 +2,11 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda.fsm;
package jdocs.actor.fsm;
import akka.actor.*;
import akka.testkit.JavaTestKit;
import docs.AbstractJavaTest;
import org.hamcrest.CoreMatchers;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -15,8 +14,8 @@ import scala.concurrent.duration.Duration;
import static org.junit.Assert.*;
import static docs.actorlambda.fsm.FSMDocTest.StateType.*;
import static docs.actorlambda.fsm.FSMDocTest.Messages.*;
import static jdocs.actor.fsm.FSMDocTest.StateType.*;
import static jdocs.actor.fsm.FSMDocTest.Messages.*;
import static java.util.concurrent.TimeUnit.*;
public class FSMDocTest extends AbstractJavaTest {

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.actorlambda.japi;
package jdocs.actor.japi;
//#all
//#imports
@ -14,7 +14,6 @@ import akka.actor.*;
import akka.dispatch.Mapper;
import akka.event.LoggingReceive;
import akka.japi.pf.DeciderBuilder;
import akka.japi.pf.ReceiveBuilder;
import akka.util.Timeout;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
@ -28,10 +27,10 @@ import static akka.actor.SupervisorStrategy.escalate;
import static akka.pattern.Patterns.ask;
import static akka.pattern.Patterns.pipe;
import static docs.actorlambda.japi.FaultHandlingDocSample.WorkerApi.*;
import static docs.actorlambda.japi.FaultHandlingDocSample.CounterServiceApi.*;
import static docs.actorlambda.japi.FaultHandlingDocSample.CounterApi.*;
import static docs.actorlambda.japi.FaultHandlingDocSample.StorageApi.*;
import static jdocs.actor.japi.FaultHandlingDocSample.WorkerApi.*;
import static jdocs.actor.japi.FaultHandlingDocSample.CounterServiceApi.*;
import static jdocs.actor.japi.FaultHandlingDocSample.CounterApi.*;
import static jdocs.actor.japi.FaultHandlingDocSample.StorageApi.*;
//#imports
@ -77,13 +76,13 @@ public class FaultHandlingDocSample {
log().info("Current progress: {} %", progress.percent);
if (progress.percent >= 100.0) {
log().info("That's all, shutting down");
getContext().system().terminate();
getContext().getSystem().terminate();
}
}).
matchEquals(ReceiveTimeout.getInstance(), x -> {
// No progress within 15 seconds, ServiceUnavailable
log().error("Shutting down due to unavailable service");
getContext().system().terminate();
getContext().getSystem().terminate();
}).build(), getContext());
}
}
@ -138,16 +137,16 @@ public class FaultHandlingDocSample {
public Receive createReceive() {
return LoggingReceive.create(receiveBuilder().
matchEquals(Start, x -> progressListener == null, x -> {
progressListener = sender();
getContext().system().scheduler().schedule(
Duration.Zero(), Duration.create(1, "second"), self(), Do,
progressListener = getSender();
getContext().getSystem().scheduler().schedule(
Duration.Zero(), Duration.create(1, "second"), getSelf(), Do,
getContext().dispatcher(), null
);
}).
matchEquals(Do, x -> {
counterService.tell(new Increment(1), self());
counterService.tell(new Increment(1), self());
counterService.tell(new Increment(1), self());
counterService.tell(new Increment(1), getSelf());
counterService.tell(new Increment(1), getSelf());
counterService.tell(new Increment(1), getSelf());
// Send current progress to the initial sender
pipe(ask(counterService, GetCurrentCount, askTimeout)
.mapTo(classTag(CurrentCount.class))
@ -223,7 +222,7 @@ public class FaultHandlingDocSample {
}
}
final String key = self().path().name();
final String key = getSelf().path().name();
ActorRef storage;
ActorRef counter;
final List<SenderMsgPair> backlog = new ArrayList<>();
@ -258,9 +257,9 @@ public class FaultHandlingDocSample {
Props.create(Storage.class), "storage"));
// Tell the counter, if any, to use the new storage
if (counter != null)
counter.tell(new UseStorage(storage), self());
counter.tell(new UseStorage(storage), getSelf());
// We need the initial value to be able to operate
storage.tell(new Get(key), self());
storage.tell(new Get(key), getSelf());
}
@Override
@ -271,7 +270,7 @@ public class FaultHandlingDocSample {
final long value = entry.value;
counter = getContext().actorOf(Props.create(Counter.class, key, value));
// Tell the counter to use current storage
counter.tell(new UseStorage(storage), self());
counter.tell(new UseStorage(storage), getSelf());
// and send the buffered backlog to the counter
for (SenderMsgPair each : backlog) {
counter.tell(each.msg, each.sender);
@ -289,10 +288,10 @@ public class FaultHandlingDocSample {
// We receive Terminated because we watch the child, see initStorage.
storage = null;
// Tell the counter that there is no storage for the moment
counter.tell(new UseStorage(null), self());
counter.tell(new UseStorage(null), getSelf());
// Try to re-establish storage after while
getContext().system().scheduler().scheduleOnce(
Duration.create(10, "seconds"), self(), Reconnect,
getContext().getSystem().scheduler().scheduleOnce(
Duration.create(10, "seconds"), getSelf(), Reconnect,
getContext().dispatcher(), null);
}).
matchEquals(Reconnect, o -> {
@ -309,7 +308,7 @@ public class FaultHandlingDocSample {
if (backlog.size() >= MAX_BACKLOG)
throw new ServiceUnavailable("CounterService not available," +
" lack of initial value");
backlog.add(new SenderMsgPair(sender(), msg));
backlog.add(new SenderMsgPair(getSender(), msg));
} else {
counter.forward(msg, getContext());
}
@ -359,7 +358,7 @@ public class FaultHandlingDocSample {
storeCount();
}).
matchEquals(GetCurrentCount, gcc -> {
sender().tell(new CurrentCount(key, count), self());
getSender().tell(new CurrentCount(key, count), getSelf());
}).build(), getContext());
}
@ -367,7 +366,7 @@ public class FaultHandlingDocSample {
// Delegate dangerous work, to protect our valuable state.
// We can continue without storage.
if (storage != null) {
storage.tell(new Store(new Entry(key, count)), self());
storage.tell(new Store(new Entry(key, count)), getSelf());
}
}
}
@ -440,8 +439,8 @@ public class FaultHandlingDocSample {
}).
match(Get.class, get -> {
Long value = db.load(get.key);
sender().tell(new Entry(get.key, value == null ?
Long.valueOf(0L) : value), self());
getSender().tell(new Entry(get.key, value == null ?
Long.valueOf(0L) : value), getSelf());
}).build(), getContext());
}
}

View file

@ -1,11 +1,10 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.agent;
package jdocs.agent;
import static org.junit.Assert.*;
import docs.AbstractJavaTest;
import org.junit.Test;
import scala.concurrent.Await;
@ -25,7 +24,7 @@ import scala.concurrent.duration.Duration;
import scala.concurrent.Future;
//#import-future
public class AgentDocTest extends docs.AbstractJavaTest {
public class AgentDocTest extends jdocs.AbstractJavaTest {
private static ExecutionContext ec = ExecutionContexts.global();

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#CamelActivation
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
@ -7,9 +7,8 @@ package docs.camel;
import akka.camel.CamelExtension;
import akka.camel.javaapi.UntypedConsumerActor;
import akka.testkit.JavaTestKit;
import akka.testkit.TestKit;
import akka.util.Timeout;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import scala.concurrent.Future;
import scala.concurrent.duration.Duration;
import static java.util.concurrent.TimeUnit.SECONDS;

View file

@ -1,10 +1,10 @@
package docs.camel;
package jdocs.camel;
import akka.actor.ActorSystem;
import akka.camel.Camel;
import akka.camel.CamelExtension;
import akka.testkit.JavaTestKit;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.junit.Test;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Consumer1
import akka.camel.CamelMessage;
import akka.camel.javaapi.UntypedConsumerActor;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Consumer2
import akka.camel.CamelMessage;
import akka.camel.javaapi.UntypedConsumerActor;
@ -12,7 +12,7 @@ public class Consumer2 extends UntypedConsumerActor {
if (message instanceof CamelMessage) {
CamelMessage camelMessage = (CamelMessage) message;
String body = camelMessage.getBodyAs(String.class, getCamelContext());
sender().tell(String.format("Received message: %s",body), self());
getSender().tell(String.format("Received message: %s",body), getSelf());
} else
unhandled(message);
}

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Consumer3
import akka.actor.Status;
import akka.camel.Ack;
@ -18,12 +18,12 @@ public class Consumer3 extends UntypedConsumerActor{
public void onReceive(Object message) {
if (message instanceof CamelMessage) {
sender().tell(Ack.getInstance(), self());
getSender().tell(Ack.getInstance(), getSelf());
// on success
// ..
Exception someException = new Exception("e1");
// on failure
sender().tell(new Status.Failure(someException), self());
getSender().tell(new Status.Failure(someException), getSelf());
} else
unhandled(message);
}

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Consumer4
import akka.camel.CamelMessage;
import akka.camel.javaapi.UntypedConsumerActor;
@ -24,7 +24,7 @@ public class Consumer4 extends UntypedConsumerActor {
if (message instanceof CamelMessage) {
CamelMessage camelMessage = (CamelMessage) message;
String body = camelMessage.getBodyAs(String.class, getCamelContext());
sender().tell(String.format("Hello %s",body), self());
getSender().tell(String.format("Hello %s",body), getSelf());
} else
unhandled(message);
}

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#CustomRoute
import akka.actor.ActorRef;
import akka.camel.internal.component.CamelPath;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#ErrorThrowingConsumer
import akka.actor.Status;
import akka.camel.CamelMessage;
@ -47,7 +47,7 @@ public class ErrorThrowingConsumer extends UntypedConsumerActor{
@Override
public void preRestart(Throwable reason, Option<Object> message) {
sender().tell(new Status.Failure(reason), self());
getSender().tell(new Status.Failure(reason), getSelf());
}
}
//#ErrorThrowingConsumer

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Producer1
import akka.camel.javaapi.UntypedProducerActor;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#RouteResponse
import akka.actor.ActorRef;
import akka.camel.javaapi.UntypedProducerActor;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#ProducerTemplate
import akka.actor.UntypedAbstractActor;
import akka.camel.Camel;
@ -7,7 +7,7 @@ import org.apache.camel.ProducerTemplate;
public class MyActor extends UntypedAbstractActor {
public void onReceive(Object message) {
Camel camel = CamelExtension.get(getContext().system());
Camel camel = CamelExtension.get(getContext().getSystem());
ProducerTemplate template = camel.template();
template.sendBody("direct:news", message);
}

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Consumer-mina
import akka.camel.CamelMessage;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
import akka.actor.*;
import akka.testkit.JavaTestKit;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Oneway
import akka.camel.javaapi.UntypedProducerActor;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Producer
import akka.camel.javaapi.UntypedProducerActor;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#Producer1
import akka.camel.javaapi.UntypedProducerActor;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
import java.util.HashMap;
import java.util.Map;

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#RequestProducerTemplate
import akka.actor.AbstractActor;
import akka.camel.Camel;
@ -10,9 +10,9 @@ public class RequestBodyActor extends AbstractActor {
public Receive createReceive() {
return receiveBuilder()
.matchAny(message -> {
Camel camel = CamelExtension.get(getContext().system());
Camel camel = CamelExtension.get(getContext().getSystem());
ProducerTemplate template = camel.template();
sender().tell(template.requestBody("direct:news", message), self());
getSender().tell(template.requestBody("direct:news", message), getSelf());
})
.build();
}

View file

@ -1,16 +1,15 @@
package docs.camel;
package jdocs.camel;
//#CustomRoute
import akka.actor.UntypedAbstractActor;
import akka.camel.CamelMessage;
import akka.dispatch.Mapper;
import akka.japi.Function;
public class Responder extends UntypedAbstractActor{
public void onReceive(Object message) {
if (message instanceof CamelMessage) {
CamelMessage camelMessage = (CamelMessage) message;
sender().tell(createResponse(camelMessage), self());
getSender().tell(createResponse(camelMessage), getSelf());
} else
unhandled(message);
}

View file

@ -1,4 +1,4 @@
package docs.camel;
package jdocs.camel;
//#RouteResponse
import akka.actor.UntypedAbstractActor;
import akka.camel.CamelMessage;

View file

@ -1,9 +1,8 @@
package docs.camel;
package jdocs.camel;
//#TransformOutgoingMessage
import akka.camel.CamelMessage;
import akka.camel.javaapi.UntypedProducerActor;
import akka.dispatch.Mapper;
import akka.japi.Function;
public class Transformer extends UntypedProducerActor{
private String uri;

View file

@ -1,10 +1,10 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.cluster;
package jdocs.cluster;
import com.typesafe.config.ConfigFactory;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.math.BigInteger;
import java.util.concurrent.CompletableFuture;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.util.Arrays;
import java.util.Collections;
@ -26,7 +26,7 @@ public class FactorialFrontend extends AbstractActor {
final int upToN;
final boolean repeat;
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
ActorRef backend = getContext().actorOf(FromConfig.getInstance().props(),
"factorialBackendRouter");
@ -64,7 +64,7 @@ public class FactorialFrontend extends AbstractActor {
void sendJobs() {
log.info("Starting batch of factorials up to [{}]", upToN);
for (int n = 1; n <= upToN; n++) {
backend.tell(n, self());
backend.tell(n, getSelf());
}
}

View file

@ -1,7 +1,6 @@
package docs.cluster;
package jdocs.cluster;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import scala.concurrent.Await;
import scala.concurrent.duration.Duration;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.math.BigInteger;
import java.io.Serializable;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
//#metrics-listener
import akka.actor.AbstractActor;
@ -14,11 +14,11 @@ import akka.event.Logging;
import akka.event.LoggingAdapter;
public class MetricsListener extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
Cluster cluster = Cluster.get(getContext().system());
Cluster cluster = Cluster.get(getContext().getSystem());
ClusterMetricsExtension extension = ClusterMetricsExtension.get(getContext().system());
ClusterMetricsExtension extension = ClusterMetricsExtension.get(getContext().getSystem());
// Subscribe unto ClusterMetricsEvent events.

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import akka.actor.AbstractActor;
import akka.cluster.Cluster;
@ -11,8 +11,8 @@ import akka.event.Logging;
import akka.event.LoggingAdapter;
public class SimpleClusterListener extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
Cluster cluster = Cluster.get(getContext().system());
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
Cluster cluster = Cluster.get(getContext().getSystem());
//subscribe to cluster changes
@Override

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import akka.actor.AbstractActor;
import akka.cluster.Cluster;
@ -11,8 +11,8 @@ import akka.event.Logging;
import akka.event.LoggingAdapter;
public class SimpleClusterListener2 extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
Cluster cluster = Cluster.get(getContext().system());
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
Cluster cluster = Cluster.get(getContext().getSystem());
//subscribe to cluster changes
@Override

View file

@ -1,11 +1,11 @@
package docs.cluster;
package jdocs.cluster;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import docs.cluster.StatsMessages.JobFailed;
import docs.cluster.StatsMessages.StatsResult;
import jdocs.cluster.StatsMessages.JobFailed;
import jdocs.cluster.StatsMessages.StatsResult;
import scala.concurrent.duration.Duration;
import akka.actor.ActorRef;
import akka.actor.ReceiveTimeout;
@ -39,14 +39,14 @@ public class StatsAggregator extends AbstractActor {
sum += c;
}
double meanWordLength = ((double) sum) / results.size();
replyTo.tell(new StatsResult(meanWordLength), self());
getContext().stop(self());
replyTo.tell(new StatsResult(meanWordLength), getSelf());
getContext().stop(getSelf());
}
})
.match(ReceiveTimeout.class, x -> {
replyTo.tell(new JobFailed("Service unavailable, try again later"),
self());
getContext().stop(self());
getSelf());
getContext().stop(getSelf());
})
.build();
}

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.io.Serializable;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.util.ArrayList;
import java.util.HashSet;
@ -6,9 +6,9 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import docs.cluster.StatsMessages.JobFailed;
import docs.cluster.StatsMessages.StatsJob;
import docs.cluster.StatsMessages.StatsResult;
import jdocs.cluster.StatsMessages.JobFailed;
import jdocs.cluster.StatsMessages.StatsJob;
import jdocs.cluster.StatsMessages.StatsResult;
import java.util.concurrent.ThreadLocalRandom;
import scala.concurrent.duration.Duration;
import scala.concurrent.duration.FiniteDuration;
@ -32,15 +32,15 @@ public class StatsSampleClient extends AbstractActor {
final Cancellable tickTask;
final Set<Address> nodes = new HashSet<Address>();
Cluster cluster = Cluster.get(getContext().system());
Cluster cluster = Cluster.get(getContext().getSystem());
public StatsSampleClient(String servicePath) {
this.servicePath = servicePath;
FiniteDuration interval = Duration.create(2, TimeUnit.SECONDS);
tickTask = getContext()
.system()
.getSystem()
.scheduler()
.schedule(interval, interval, self(), "tick",
.schedule(interval, interval, getSelf(), "tick",
getContext().dispatcher(), null);
}
@ -67,7 +67,7 @@ public class StatsSampleClient extends AbstractActor {
nodesList.size()));
ActorSelection service = getContext().actorSelection(address + servicePath);
service.tell(new StatsJob("this is the text that will be analyzed"),
self());
getSelf());
})
.match(StatsResult.class, System.out::println)
.match(JobFailed.class, System.out::println)

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import com.typesafe.config.ConfigFactory;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import akka.cluster.routing.ClusterRouterGroup;
import akka.cluster.routing.ClusterRouterGroupSettings;
@ -6,7 +6,7 @@ import akka.cluster.routing.ClusterRouterPool;
import akka.cluster.routing.ClusterRouterPoolSettings;
import akka.routing.ConsistentHashingGroup;
import akka.routing.ConsistentHashingPool;
import docs.cluster.StatsMessages.StatsJob;
import jdocs.cluster.StatsMessages.StatsJob;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.actor.AbstractActor;
@ -30,7 +30,7 @@ public class StatsService extends AbstractActor {
return receiveBuilder()
.match(StatsJob.class, job -> !job.getText().isEmpty(), job -> {
String[] words = job.getText().split(" ");
ActorRef replyTo = sender();
ActorRef replyTo = getSender();
// create actor that collects replies from workers
ActorRef aggregator = getContext().actorOf(

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.util.HashMap;
import java.util.Map;
@ -19,7 +19,7 @@ public class StatsWorker extends AbstractActor {
length = word.length();
cache.put(word, length);
}
sender().tell(length, self());
getSender().tell(length, getSelf());
})
.build();
}

View file

@ -1,8 +1,8 @@
package docs.cluster;
package jdocs.cluster;
import static docs.cluster.TransformationMessages.BACKEND_REGISTRATION;
import docs.cluster.TransformationMessages.TransformationJob;
import docs.cluster.TransformationMessages.TransformationResult;
import static jdocs.cluster.TransformationMessages.BACKEND_REGISTRATION;
import jdocs.cluster.TransformationMessages.TransformationJob;
import jdocs.cluster.TransformationMessages.TransformationResult;
import akka.actor.AbstractActor;
import akka.cluster.Cluster;
import akka.cluster.ClusterEvent.CurrentClusterState;
@ -13,7 +13,7 @@ import akka.cluster.MemberStatus;
//#backend
public class TransformationBackend extends AbstractActor {
Cluster cluster = Cluster.get(getContext().system());
Cluster cluster = Cluster.get(getContext().getSystem());
//subscribe to cluster changes, MemberUp
@Override
@ -31,8 +31,8 @@ public class TransformationBackend extends AbstractActor {
public Receive createReceive() {
return receiveBuilder()
.match(TransformationJob.class, job -> {
sender().tell(new TransformationResult(job.getText().toUpperCase()),
self());
getSender().tell(new TransformationResult(job.getText().toUpperCase()),
getSelf());
})
.match(CurrentClusterState.class, state -> {
for (Member member : state.getMembers()) {
@ -50,7 +50,7 @@ public class TransformationBackend extends AbstractActor {
void register(Member member) {
if (member.hasRole("frontend"))
getContext().actorSelection(member.address() + "/user/frontend").tell(
BACKEND_REGISTRATION, self());
BACKEND_REGISTRATION, getSelf());
}
}
//#backend

View file

@ -1,12 +1,12 @@
package docs.cluster;
package jdocs.cluster;
import static docs.cluster.TransformationMessages.BACKEND_REGISTRATION;
import static jdocs.cluster.TransformationMessages.BACKEND_REGISTRATION;
import java.util.ArrayList;
import java.util.List;
import docs.cluster.TransformationMessages.JobFailed;
import docs.cluster.TransformationMessages.TransformationJob;
import jdocs.cluster.TransformationMessages.JobFailed;
import jdocs.cluster.TransformationMessages.TransformationJob;
import akka.actor.ActorRef;
import akka.actor.Terminated;
import akka.actor.AbstractActor;
@ -21,9 +21,9 @@ public class TransformationFrontend extends AbstractActor {
public Receive createReceive() {
return receiveBuilder()
.match(TransformationJob.class, job -> backends.isEmpty(), job -> {
sender().tell(
getSender().tell(
new JobFailed("Service unavailable, try again later", job),
sender());
getSender());
})
.match(TransformationJob.class, job -> {
jobCounter++;

View file

@ -1,4 +1,4 @@
package docs.cluster;
package jdocs.cluster;
import java.io.Serializable;

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.ddata;
package jdocs.ddata;
//#data-bot
import static java.util.concurrent.TimeUnit.SECONDS;
@ -24,21 +24,20 @@ import akka.cluster.ddata.Replicator.Update;
import akka.cluster.ddata.Replicator.UpdateResponse;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import akka.japi.pf.ReceiveBuilder;
public class DataBot extends AbstractActor {
private static final String TICK = "tick";
private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
private final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
private final Cluster node = Cluster.get(getContext().system());
DistributedData.get(getContext().getSystem()).replicator();
private final Cluster node = Cluster.get(getContext().getSystem());
private final Cancellable tickTask = getContext().system().scheduler().schedule(
Duration.create(5, SECONDS), Duration.create(5, SECONDS), self(), TICK,
getContext().dispatcher(), self());
private final Cancellable tickTask = getContext().getSystem().scheduler().schedule(
Duration.create(5, SECONDS), Duration.create(5, SECONDS), getSelf(), TICK,
getContext().dispatcher(), getSelf());
private final Key<ORSet<String>> dataKey = ORSetKey.create("key");
@ -63,7 +62,7 @@ public class DataBot extends AbstractActor {
ORSet.create(),
Replicator.writeLocal(),
curr -> curr.add(node, s));
replicator.tell(update, self());
replicator.tell(update, getSelf());
} else {
// remove
log.info("Removing: {}", s);
@ -72,7 +71,7 @@ public class DataBot extends AbstractActor {
ORSet.create(),
Replicator.writeLocal(),
curr -> curr.remove(node, s));
replicator.tell(update, self());
replicator.tell(update, getSelf());
}
}
@ -89,7 +88,7 @@ public class DataBot extends AbstractActor {
@Override
public void preStart() {
Subscribe<ORSet<String>> subscribe = new Subscribe<>(dataKey, self());
Subscribe<ORSet<String>> subscribe = new Subscribe<>(dataKey, getSelf());
replicator.tell(subscribe, ActorRef.noSender());
}

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.ddata;
package jdocs.ddata;
import java.util.HashSet;
import java.util.Arrays;
@ -11,17 +11,16 @@ import java.util.Optional;
import akka.actor.*;
import com.typesafe.config.ConfigFactory;
import docs.AbstractJavaTest;
import docs.ddata.DistributedDataDocSpec;
import jdocs.AbstractJavaTest;
import scala.concurrent.duration.Duration;
import scala.runtime.BoxedUnit;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import scala.PartialFunction;
import org.junit.Test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import scala.concurrent.duration.FiniteDuration;
import java.util.concurrent.ThreadLocalRandom;
import akka.cluster.Cluster;
import akka.cluster.ddata.*;
@ -29,11 +28,7 @@ import akka.japi.pf.ReceiveBuilder;
import static akka.cluster.ddata.Replicator.*;
import akka.testkit.AkkaSpec;
import akka.testkit.ImplicitSender;
import akka.testkit.JavaTestKit;
import akka.testkit.TestProbe;
import akka.serialization.SerializationExtension;
@SuppressWarnings({"unchecked", "unused"})
public class DistributedDataDocTest extends AbstractJavaTest {
@ -56,9 +51,9 @@ public class DistributedDataDocTest extends AbstractJavaTest {
static
//#update
class DemonstrateUpdate extends AbstractActor {
final Cluster node = Cluster.get(getContext().system());
final Cluster node = Cluster.get(getContext().getSystem());
final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
DistributedData.get(getContext().getSystem()).replicator();
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
final Key<GSet<String>> set1Key = GSetKey.create("set1");
@ -71,20 +66,20 @@ public class DistributedDataDocTest extends AbstractJavaTest {
b.matchEquals("demonstrate update", msg -> {
replicator.tell(new Replicator.Update<PNCounter>(counter1Key, PNCounter.create(),
Replicator.writeLocal(), curr -> curr.increment(node, 1)), self());
Replicator.writeLocal(), curr -> curr.increment(node, 1)), getSelf());
final WriteConsistency writeTo3 = new WriteTo(3, Duration.create(1, SECONDS));
replicator.tell(new Replicator.Update<GSet<String>>(set1Key, GSet.create(),
writeTo3, curr -> curr.add("hello")), self());
writeTo3, curr -> curr.add("hello")), getSelf());
final WriteConsistency writeMajority =
new WriteMajority(Duration.create(5, SECONDS));
replicator.tell(new Replicator.Update<ORSet<String>>(set2Key, ORSet.create(),
writeMajority, curr -> curr.add(node, "hello")), self());
writeMajority, curr -> curr.add(node, "hello")), getSelf());
final WriteConsistency writeAll = new WriteAll(Duration.create(5, SECONDS));
replicator.tell(new Replicator.Update<Flag>(activeFlagKey, Flag.create(),
writeAll, curr -> curr.switchOn()), self());
writeAll, curr -> curr.switchOn()), getSelf());
});
//#update
@ -112,9 +107,9 @@ public class DistributedDataDocTest extends AbstractJavaTest {
static
//#update-request-context
class DemonstrateUpdateWithRequestContext extends AbstractActor {
final Cluster node = Cluster.get(getContext().system());
final Cluster node = Cluster.get(getContext().getSystem());
final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
DistributedData.get(getContext().getSystem()).replicator();
final WriteConsistency writeTwo = new WriteTo(2, Duration.create(3, SECONDS));
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
@ -127,17 +122,17 @@ public class DistributedDataDocTest extends AbstractJavaTest {
Optional<Object> reqContext = Optional.of(sender());
Replicator.Update<PNCounter> upd = new Replicator.Update<PNCounter>(counter1Key,
PNCounter.create(), writeTwo, reqContext, curr -> curr.increment(node, 1));
replicator.tell(upd, self());
replicator.tell(upd, getSelf());
})
.match(UpdateSuccess.class, a -> a.key().equals(counter1Key), a -> {
ActorRef replyTo = (ActorRef) a.getRequest().get();
replyTo.tell("ack", self());
replyTo.tell("ack", getSelf());
})
.match(UpdateTimeout.class, a -> a.key().equals(counter1Key), a -> {
ActorRef replyTo = (ActorRef) a.getRequest().get();
replyTo.tell("nack", self());
replyTo.tell("nack", getSelf());
})
.build();
@ -149,7 +144,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
//#get
class DemonstrateGet extends AbstractActor {
final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
DistributedData.get(getContext().getSystem()).replicator();
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
final Key<GSet<String>> set1Key = GSetKey.create("set1");
@ -163,19 +158,19 @@ public class DistributedDataDocTest extends AbstractJavaTest {
b.matchEquals("demonstrate get", msg -> {
replicator.tell(new Replicator.Get<PNCounter>(counter1Key,
Replicator.readLocal()), self());
Replicator.readLocal()), getSelf());
final ReadConsistency readFrom3 = new ReadFrom(3, Duration.create(1, SECONDS));
replicator.tell(new Replicator.Get<GSet<String>>(set1Key,
readFrom3), self());
readFrom3), getSelf());
final ReadConsistency readMajority = new ReadMajority(Duration.create(5, SECONDS));
replicator.tell(new Replicator.Get<ORSet<String>>(set2Key,
readMajority), self());
readMajority), getSelf());
final ReadConsistency readAll = new ReadAll(Duration.create(5, SECONDS));
replicator.tell(new Replicator.Get<Flag>(activeFlagKey,
readAll), self());
readAll), getSelf());
});
//#get
@ -213,7 +208,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
//#get-request-context
class DemonstrateGetWithRequestContext extends AbstractActor {
final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
DistributedData.get(getContext().getSystem()).replicator();
final ReadConsistency readTwo = new ReadFrom(2, Duration.create(3, SECONDS));
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
@ -225,24 +220,24 @@ public class DistributedDataDocTest extends AbstractJavaTest {
// incoming request to retrieve current value of the counter
Optional<Object> reqContext = Optional.of(sender());
replicator.tell(new Replicator.Get<PNCounter>(counter1Key,
readTwo), self());
readTwo), getSelf());
})
.match(GetSuccess.class, a -> a.key().equals(counter1Key), a -> {
ActorRef replyTo = (ActorRef) a.getRequest().get();
GetSuccess<PNCounter> g = a;
long value = g.dataValue().getValue().longValue();
replyTo.tell(value, self());
replyTo.tell(value, getSelf());
})
.match(GetFailure.class, a -> a.key().equals(counter1Key), a -> {
ActorRef replyTo = (ActorRef) a.getRequest().get();
replyTo.tell(-1L, self());
replyTo.tell(-1L, getSelf());
})
.match(NotFound.class, a -> a.key().equals(counter1Key), a -> {
ActorRef replyTo = (ActorRef) a.getRequest().get();
replyTo.tell(0L, self());
replyTo.tell(0L, getSelf());
})
.build();
@ -254,7 +249,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
//#subscribe
class DemonstrateSubscribe extends AbstractActor {
final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
DistributedData.get(getContext().getSystem()).replicator();
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
BigInteger currentValue = BigInteger.valueOf(0);
@ -268,7 +263,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
})
.match(String.class, a -> a.equals("get-count"), a -> {
// incoming request to retrieve current value of the counter
sender().tell(currentValue, sender());
getSender().tell(currentValue, getSender());
})
.build();
}
@ -276,7 +271,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
@Override
public void preStart() {
// subscribe to changes of the Counter1Key value
replicator.tell(new Subscribe<PNCounter>(counter1Key, self()), ActorRef.noSender());
replicator.tell(new Subscribe<PNCounter>(counter1Key, getSelf()), ActorRef.noSender());
}
}
@ -286,7 +281,7 @@ public class DistributedDataDocTest extends AbstractJavaTest {
//#delete
class DemonstrateDelete extends AbstractActor {
final ActorRef replicator =
DistributedData.get(getContext().system()).replicator();
DistributedData.get(getContext().getSystem()).replicator();
final Key<PNCounter> counter1Key = PNCounterKey.create("counter1");
final Key<ORSet<String>> set2Key = ORSetKey.create("set2");
@ -297,12 +292,12 @@ public class DistributedDataDocTest extends AbstractJavaTest {
.matchEquals("demonstrate delete", msg -> {
replicator.tell(new Delete<PNCounter>(counter1Key,
Replicator.writeLocal()), self());
Replicator.writeLocal()), getSelf());
final WriteConsistency writeMajority =
new WriteMajority(Duration.create(5, SECONDS));
replicator.tell(new Delete<PNCounter>(counter1Key,
writeMajority), self());
writeMajority), getSelf());
})
.build();
}

View file

@ -1,13 +1,12 @@
package docs.ddata;
package jdocs.ddata;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import scala.PartialFunction;
import scala.concurrent.duration.Duration;
import scala.runtime.BoxedUnit;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
@ -30,7 +29,6 @@ import akka.cluster.ddata.Replicator.UpdateSuccess;
import akka.cluster.ddata.Replicator.UpdateTimeout;
import akka.cluster.ddata.Replicator.WriteConsistency;
import akka.cluster.ddata.Replicator.WriteMajority;
import akka.japi.pf.ReceiveBuilder;
@SuppressWarnings("unchecked")
public class ShoppingCart extends AbstractActor {
@ -125,8 +123,8 @@ public class ShoppingCart extends AbstractActor {
return Props.create(ShoppingCart.class, userId);
}
private final ActorRef replicator = DistributedData.get(context().system()).replicator();
private final Cluster node = Cluster.get(context().system());
private final ActorRef replicator = DistributedData.get(getContext().getSystem()).replicator();
private final Cluster node = Cluster.get(getContext().getSystem());
@SuppressWarnings("unused")
private final String userId;
@ -159,9 +157,9 @@ public class ShoppingCart extends AbstractActor {
}
private void receiveGetCart() {
Optional<Object> ctx = Optional.of(sender());
Optional<Object> ctx = Optional.of(getSender());
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, readMajority, ctx),
self());
getSelf());
}
private boolean isResponseToGetCart(GetResponse<?> response) {
@ -172,19 +170,19 @@ public class ShoppingCart extends AbstractActor {
private void receiveGetSuccess(GetSuccess<LWWMap<String, LineItem>> g) {
Set<LineItem> items = new HashSet<>(g.dataValue().getEntries().values());
ActorRef replyTo = (ActorRef) g.getRequest().get();
replyTo.tell(new Cart(items), self());
replyTo.tell(new Cart(items), getSelf());
}
private void receiveNotFound(NotFound<LWWMap<String, LineItem>> n) {
ActorRef replyTo = (ActorRef) n.getRequest().get();
replyTo.tell(new Cart(new HashSet<>()), self());
replyTo.tell(new Cart(new HashSet<>()), getSelf());
}
private void receiveGetFailure(GetFailure<LWWMap<String, LineItem>> f) {
// ReadMajority failure, try again with local read
Optional<Object> ctx = Optional.of(sender());
Optional<Object> ctx = Optional.of(getSender());
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, Replicator.readLocal(),
ctx), self());
ctx), getSelf());
}
//#get-cart
@ -198,7 +196,7 @@ public class ShoppingCart extends AbstractActor {
private void receiveAddItem(AddItem add) {
Update<LWWMap<String, LineItem>> update = new Update<>(dataKey, LWWMap.create(), writeMajority,
cart -> updateCart(cart, add.item));
replicator.tell(update, self());
replicator.tell(update, getSelf());
}
//#add-item
@ -230,8 +228,8 @@ public class ShoppingCart extends AbstractActor {
// Try to fetch latest from a majority of nodes first, since ORMap
// remove must have seen the item to be able to remove it.
Optional<Object> ctx = Optional.of(rm);
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, readMajority, ctx),
self());
replicator.tell(new Replicator.Get<LWWMap<String, LineItem>>(dataKey, readMajority, ctx),
getSelf());
}
private void receiveRemoveItemGetSuccess(GetSuccess<LWWMap<String, LineItem>> g) {
@ -249,7 +247,7 @@ public class ShoppingCart extends AbstractActor {
private void removeItem(String productId) {
Update<LWWMap<String, LineItem>> update = new Update<>(dataKey, LWWMap.create(), writeMajority,
cart -> cart.remove(node, productId));
replicator.tell(update, self());
replicator.tell(update, getSelf());
}
private boolean isResponseToRemoveItem(GetResponse<?> response) {

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.ddata.japi;
package jdocs.ddata;
import java.util.HashSet;

View file

@ -1,10 +1,10 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.ddata.japi.protobuf;
package jdocs.ddata.protobuf;
//#serializer
import docs.ddata.japi.TwoPhaseSet;
import jdocs.ddata.TwoPhaseSet;
import docs.ddata.protobuf.msg.TwoPhaseSetMessages;
import docs.ddata.protobuf.msg.TwoPhaseSetMessages.TwoPhaseSet.Builder;
import java.util.ArrayList;

View file

@ -1,14 +1,12 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.ddata.japi.protobuf;
package jdocs.ddata.protobuf;
//#serializer
import docs.ddata.japi.TwoPhaseSet;
import jdocs.ddata.TwoPhaseSet;
import docs.ddata.protobuf.msg.TwoPhaseSetMessages;
import docs.ddata.protobuf.msg.TwoPhaseSetMessages.TwoPhaseSet2.Builder;
import java.util.ArrayList;
import java.util.Collections;
import akka.actor.ExtendedActorSystem;
import akka.cluster.ddata.GSet;

View file

@ -1,9 +1,9 @@
/**
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.ddata.japi.protobuf;
package jdocs.ddata.protobuf;
import docs.ddata.japi.TwoPhaseSet;
import jdocs.ddata.TwoPhaseSet;
import akka.actor.ExtendedActorSystem;

View file

@ -1,15 +1,16 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.dispatcher;
package jdocs.dispatcher;
import akka.dispatch.ControlMessage;
import akka.dispatch.RequiresMessageQueue;
import akka.testkit.AkkaSpec;
import com.typesafe.config.ConfigFactory;
import docs.AbstractJavaTest;
import docs.actorlambda.MyBoundedActor;
import docs.actorlambda.MyActor;
import docs.dispatcher.DispatcherDocSpec;
import jdocs.AbstractJavaTest;
import jdocs.actor.MyBoundedActor;
import jdocs.actor.MyActor;
import org.junit.ClassRule;
import org.junit.Test;
import scala.concurrent.ExecutionContext;
@ -17,7 +18,6 @@ import scala.concurrent.ExecutionContext;
//#imports
import akka.actor.*;
//#imports
import akka.actor.AbstractActor.Receive;
//#imports-prio
import akka.event.Logging;
import akka.event.LoggingAdapter;
@ -127,12 +127,12 @@ public class DispatcherDocTest extends AbstractJavaTest {
//#prio-dispatcher
class Demo extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
{
for (Object msg : new Object[] { "lowpriority", "lowpriority",
"highpriority", "pigdog", "pigdog2", "pigdog3", "highpriority",
PoisonPill.getInstance() }) {
self().tell(msg, self());
getSelf().tell(msg, getSelf());
}
}
@ -170,11 +170,11 @@ public class DispatcherDocTest extends AbstractJavaTest {
//#control-aware-dispatcher
class Demo extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
{
for (Object msg : new Object[] { "foo", "bar", new MyControlMessage(),
PoisonPill.getInstance() }) {
self().tell(msg, self());
getSelf().tell(msg, getSelf());
}
}
@ -239,7 +239,7 @@ public class DispatcherDocTest extends AbstractJavaTest {
static
//#require-mailbox-on-actor
public class MySpecialActor extends AbstractActor implements
RequiresMessageQueue<MyUnboundedJMessageQueueSemantics> {
RequiresMessageQueue<MyUnboundedMessageQueueSemantics> {
//#require-mailbox-on-actor
@Override
public Receive createReceive() {

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.dispatcher;
package jdocs.dispatcher;
//#mailbox-implementation-example
import akka.actor.ActorRef;
@ -15,12 +15,12 @@ import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.Queue;
import scala.Option;
public class MyUnboundedJMailbox implements MailboxType,
ProducesMessageQueue<MyUnboundedJMailbox.MyMessageQueue> {
public class MyUnboundedMailbox implements MailboxType,
ProducesMessageQueue<MyUnboundedMailbox.MyMessageQueue> {
// This is the MessageQueue implementation
public static class MyMessageQueue implements MessageQueue,
MyUnboundedJMessageQueueSemantics {
MyUnboundedMessageQueueSemantics {
private final Queue<Envelope> queue =
new ConcurrentLinkedQueue<Envelope>();
@ -39,7 +39,7 @@ public class MyUnboundedJMailbox implements MailboxType,
}
// This constructor signature must exist, it will be called by Akka
public MyUnboundedJMailbox(ActorSystem.Settings settings, Config config) {
public MyUnboundedMailbox(ActorSystem.Settings settings, Config config) {
// put your initialization code here
}

View file

@ -2,10 +2,10 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.dispatcher;
package jdocs.dispatcher;
//#mailbox-implementation-example
// Marker interface used for mailbox requirements mapping
public interface MyUnboundedJMessageQueueSemantics {
public interface MyUnboundedMessageQueueSemantics {
}
//#mailbox-implementation-example

View file

@ -1,36 +1,30 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.event;
package jdocs.event;
import akka.event.japi.EventBus;
import java.util.concurrent.TimeUnit;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.ClassRule;
import org.junit.Test;
import akka.actor.ActorSystem;
import akka.actor.ActorRef;
import akka.event.japi.*;
import akka.testkit.AkkaJUnitActorSystemResource;
import akka.testkit.JavaTestKit;
import akka.event.japi.EventBus;
import akka.util.Subclassification;
import org.junit.ClassRule;
import org.junit.Test;
import scala.concurrent.duration.FiniteDuration;
//#lookup-bus
import akka.event.japi.LookupEventBus;
import java.util.concurrent.TimeUnit;
//#lookup-bus
//#subchannel-bus
import akka.event.japi.SubchannelEventBus;
import akka.util.Subclassification;
//#subchannel-bus

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.event;
package jdocs.event;
//#imports
import akka.actor.*;
@ -19,13 +19,12 @@ import akka.event.Logging.Debug;
//#imports-listener
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.Test;
import akka.testkit.JavaTestKit;
import java.util.Optional;
//#imports-mdc
import akka.event.Logging;
import akka.event.DiagnosticLoggingAdapter;
import java.util.HashMap;
import java.util.Map;
@ -85,10 +84,10 @@ public class LoggingDocTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(Jazz.class, msg ->
System.out.printf("%s is listening to: %s%n", self().path().name(), msg)
System.out.printf("%s is listening to: %s%n", getSelf().path().name(), msg)
)
.match(Electronic.class, msg ->
System.out.printf("%s is listening to: %s%n", self().path().name(), msg)
System.out.printf("%s is listening to: %s%n", getSelf().path().name(), msg)
)
.build();
}
@ -152,7 +151,7 @@ public class LoggingDocTest extends AbstractJavaTest {
//#my-actor
class MyActor extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
@Override
public void preStart() {
@ -211,7 +210,7 @@ public class LoggingDocTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(InitializeLogger.class, msg -> {
sender().tell(Logging.loggerInitialized(), self());
getSender().tell(Logging.loggerInitialized(), getSelf());
})
.match(Error.class, msg -> {
// ...

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.extension;
package jdocs.extension;
//#imports
import akka.actor.*;
@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;
//#imports
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.Test;
public class ExtensionDocTest extends AbstractJavaTest {
@ -64,7 +64,7 @@ public class ExtensionDocTest extends AbstractJavaTest {
.matchAny(msg -> {
// typically you would use static import of the
// CountExtension.CountExtensionProvider field
CountExtension.CountExtensionProvider.get(getContext().system()).increment();
CountExtension.CountExtensionProvider.get(getContext().getSystem()).increment();
})
.build();
}

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.extension;
package jdocs.extension;
//#imports
import akka.actor.Extension;
@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit;
//#imports
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import akka.actor.AbstractActor;
import org.junit.Test;
@ -63,7 +63,7 @@ public class SettingsExtensionDocTest extends AbstractJavaTest {
public class MyActor extends AbstractActor {
// typically you would use static import of the Settings.SettingsProvider field
final SettingsImpl settings =
Settings.SettingsProvider.get(getContext().system());
Settings.SettingsProvider.get(getContext().getSystem());
Connection connection =
connect(settings.DB_URI, settings.CIRCUIT_BREAKER_TIMEOUT);

View file

@ -1,11 +1,11 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.future;
package jdocs.future;
//#imports1
import akka.dispatch.*;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import scala.concurrent.ExecutionContext;
import scala.concurrent.Future;
import scala.concurrent.Await;
@ -39,8 +39,6 @@ import static akka.dispatch.Futures.reduce;
//#imports6
//#imports7
import scala.concurrent.ExecutionContext;
import scala.concurrent.ExecutionContext$;
//#imports7
//#imports8
@ -661,13 +659,13 @@ public class FutureDocTest extends AbstractJavaTest {
public Receive createReceive() {
return receiveBuilder()
.match(String.class, msg -> {
sender().tell(msg.toUpperCase(), self());
getSender().tell(msg.toUpperCase(), getSelf());
})
.match(Integer.class, i -> {
if (i < 0) {
sender().tell(new Failure(new ArithmeticException("Negative values not supported")), self());
getSender().tell(new Failure(new ArithmeticException("Negative values not supported")), getSelf());
} else {
sender().tell(i, self());
getSender().tell(i, getSelf());
}
})
.build();

View file

@ -2,10 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io;
import org.junit.BeforeClass;
import org.junit.Test;
package jdocs.io;
import akka.actor.ActorSystem;
import akka.actor.AbstractActor;
@ -16,7 +13,6 @@ import java.util.List;
import akka.actor.ActorRef;
import akka.io.Inet;
import akka.io.Tcp;
import akka.io.TcpExt;
import akka.io.TcpMessage;
import akka.io.TcpSO;
import akka.util.ByteString;
@ -26,7 +22,7 @@ public class IODocTest {
static public class Demo extends AbstractActor {
ActorRef connectionActor = null;
ActorRef listener = self();
ActorRef listener = getSelf();
@Override
public Receive createReceive() {
@ -38,20 +34,20 @@ public class IODocTest {
//#connect
final InetSocketAddress remoteAddr = new InetSocketAddress("127.0.0.1",
12345);
tcp.tell(TcpMessage.connect(remoteAddr), self());
tcp.tell(TcpMessage.connect(remoteAddr), getSelf());
//#connect
//#connect-with-options
final InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
1234);
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
options.add(TcpSO.keepAlive(true));
tcp.tell(TcpMessage.connect(remoteAddr, localAddr, options, null, false), self());
tcp.tell(TcpMessage.connect(remoteAddr, localAddr, options, null, false), getSelf());
//#connect-with-options
})
//#connected
.match(Tcp.Connected.class, conn -> {
connectionActor = sender();
connectionActor.tell(TcpMessage.register(listener), self());
connectionActor = getSender();
connectionActor.tell(TcpMessage.register(listener), getSelf());
})
//#connected
//#received
@ -70,14 +66,14 @@ public class IODocTest {
})
//#received
.matchEquals("bind", msg -> {
final ActorRef handler = self();
final ActorRef handler = getSelf();
//#bind
final ActorRef tcp = Tcp.get(system).manager();
final InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
1234);
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
options.add(TcpSO.reuseAddress(true));
tcp.tell(TcpMessage.bind(handler, localAddr, 10, options, false), self());
tcp.tell(TcpMessage.bind(handler, localAddr, 10, options, false), getSelf());
//#bind
})
.build();

View file

@ -1,4 +1,4 @@
package docs.io;
package jdocs.io;
import akka.actor.ActorRef;
import akka.actor.Props;
@ -26,15 +26,15 @@ public class JavaReadBackPressure {
public Receive createReceive() {
return receiveBuilder()
.match(Tcp.Bound.class, x -> {
listener = sender();
listener = getSender();
// Accept connections one by one
listener.tell(TcpMessage.resumeAccepting(1), self());
listener.tell(TcpMessage.resumeAccepting(1), getSelf());
})
.match(Tcp.Connected.class, x -> {
ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, sender()));
sender().tell(TcpMessage.register(handler), self());
ActorRef handler = getContext().actorOf(Props.create(PullEcho.class, getSender()));
getSender().tell(TcpMessage.register(handler), getSelf());
// Resume accepting connections
listener.tell(TcpMessage.resumeAccepting(1), self());
listener.tell(TcpMessage.resumeAccepting(1), getSelf());
})
.build();
}
@ -43,11 +43,11 @@ public class JavaReadBackPressure {
@Override
public void preStart() throws Exception {
//#pull-mode-bind
tcp = Tcp.get(getContext().system()).manager();
tcp = Tcp.get(getContext().getSystem()).manager();
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
tcp.tell(
TcpMessage.bind(self(), new InetSocketAddress("localhost", 0), 100, options, true),
self()
getSelf()
);
//#pull-mode-bind
}
@ -57,7 +57,7 @@ public class JavaReadBackPressure {
final List<Inet.SocketOption> options = new ArrayList<Inet.SocketOption>();
tcp.tell(
TcpMessage.connect(new InetSocketAddress("localhost", 3000), null, options, null, true),
self()
getSelf()
);
//#pull-mode-connect
}
@ -76,7 +76,7 @@ public class JavaReadBackPressure {
//#pull-reading-echo
@Override
public void preStart() throws Exception {
connection.tell(TcpMessage.resumeReading(), self());
connection.tell(TcpMessage.resumeReading(), getSelf());
}
@Override
@ -84,10 +84,10 @@ public class JavaReadBackPressure {
return receiveBuilder()
.match(Tcp.Received.class, message -> {
ByteString data = message.data();
connection.tell(TcpMessage.write(data, new Ack()), self());
connection.tell(TcpMessage.write(data, new Ack()), getSelf());
})
.match(Ack.class, message -> {
connection.tell(TcpMessage.resumeReading(), self());
connection.tell(TcpMessage.resumeReading(), getSelf());
})
.build();
}

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io;
package jdocs.io;
//#imports
import akka.actor.ActorRef;
@ -58,7 +58,7 @@ public class JavaUdpMulticast {
//#multicast-group
public static class Listener extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
ActorRef sink;
@ -70,10 +70,10 @@ public class JavaUdpMulticast {
options.add(new Inet6ProtocolFamily());
options.add(new MulticastGroup(group, iface));
final ActorRef mgr = Udp.get(getContext().system()).getManager();
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
// listen for datagrams on this address
InetSocketAddress endpoint = new InetSocketAddress(port);
mgr.tell(UdpMessage.bind(self(), endpoint, options), self());
mgr.tell(UdpMessage.bind(self(), endpoint, options), getSelf());
//#bind
}
@ -82,19 +82,19 @@ public class JavaUdpMulticast {
return receiveBuilder()
.match(Udp.Bound.class, bound -> {
log.info("Bound to {}", bound.localAddress());
sink.tell(bound, self());
sink.tell(bound, getSelf());
})
.match(Udp.Received.class, received -> {
final String txt = received.data().decodeString("utf-8");
log.info("Received '{}' from {}", txt, received.sender());
sink.tell(txt, self());
sink.tell(txt, getSelf());
})
.build();
}
}
public static class Sender extends AbstractActor {
LoggingAdapter log = Logging.getLogger(getContext().system(), this);
LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
String iface;
String group;
@ -110,8 +110,8 @@ public class JavaUdpMulticast {
List<Inet.SocketOption> options = new ArrayList<>();
options.add(new Inet6ProtocolFamily());
final ActorRef mgr = Udp.get(getContext().system()).getManager();
mgr.tell(UdpMessage.simpleSender(options), self());
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
mgr.tell(UdpMessage.simpleSender(options), getSelf());
}
@Override
@ -120,7 +120,7 @@ public class JavaUdpMulticast {
.match(Udp.SimpleSenderReady.class, x -> {
InetSocketAddress remote = new InetSocketAddress(group + "%" + iface, port);
log.info("Sending message to " + remote);
sender().tell(UdpMessage.send(ByteString.fromString(message), remote), self());
getSender().tell(UdpMessage.send(ByteString.fromString(message), remote), getSelf());
})
.build();
}

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io;
package jdocs.io;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
@ -11,7 +11,7 @@ import akka.io.Udp;
import akka.testkit.JavaTestKit;
import akka.testkit.SocketUtil;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io;
package jdocs.io;
import akka.japi.pf.ReceiveBuilder;
import org.junit.Test;
@ -25,8 +25,8 @@ public class UdpConnectedDocTest {
static public class Demo extends AbstractActor {
ActorRef connectionActor = null;
ActorRef handler = self();
ActorSystem system = getContext().system();
ActorRef handler = getSelf();
ActorSystem system = getContext().getSystem();
@Override
public Receive createReceive() {
@ -38,7 +38,7 @@ public class UdpConnectedDocTest {
//#connect
final InetSocketAddress remoteAddr =
new InetSocketAddress("127.0.0.1", 12345);
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr), self());
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr), getSelf());
//#connect
//#connect-with-options
final InetSocketAddress localAddr =
@ -46,12 +46,12 @@ public class UdpConnectedDocTest {
final List<Inet.SocketOption> options =
new ArrayList<Inet.SocketOption>();
options.add(UdpSO.broadcast(true));
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr, localAddr, options), self());
udp.tell(UdpConnectedMessage.connect(handler, remoteAddr, localAddr, options), getSelf());
//#connect-with-options
});
//#connected
builder.match(UdpConnected.Connected.class, conn -> {
connectionActor = sender(); // Save the worker ref for later use
connectionActor = getSender(); // Save the worker ref for later use
});
//#connected
//#received
@ -71,7 +71,7 @@ public class UdpConnectedDocTest {
builder.matchEquals("send", x -> {
ByteString data = ByteString.empty();
//#send
connectionActor.tell(UdpConnectedMessage.send(data), self());
connectionActor.tell(UdpConnectedMessage.send(data), getSelf());
//#send
});
return builder.build();

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io;
package jdocs.io;
//#imports
import akka.actor.ActorRef;
@ -12,7 +12,6 @@ import akka.io.Udp;
import akka.io.UdpConnected;
import akka.io.UdpConnectedMessage;
import akka.io.UdpMessage;
import akka.japi.Procedure;
import akka.util.ByteString;
import java.net.InetSocketAddress;
@ -28,8 +27,8 @@ public class UdpDocTest {
this.remote = remote;
// request creation of a SimpleSender
final ActorRef mgr = Udp.get(getContext().system()).getManager();
mgr.tell(UdpMessage.simpleSender(), self());
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
mgr.tell(UdpMessage.simpleSender(), getSelf());
}
@Override
@ -38,7 +37,7 @@ public class UdpDocTest {
.match(Udp.SimpleSenderReady.class, message -> {
getContext().become(ready(sender()));
//#sender
sender().tell(UdpMessage.send(ByteString.fromString("hello"), remote), self());
getSender().tell(UdpMessage.send(ByteString.fromString("hello"), remote), getSelf());
//#sender
})
.build();
@ -47,10 +46,10 @@ public class UdpDocTest {
private Receive ready(final ActorRef send) {
return receiveBuilder()
.match(String.class, message -> {
send.tell(UdpMessage.send(ByteString.fromString(message), remote), self());
send.tell(UdpMessage.send(ByteString.fromString(message), remote), getSelf());
//#sender
if (message.equals("world")) {
send.tell(PoisonPill.getInstance(), self());
send.tell(PoisonPill.getInstance(), getSelf());
}
//#sender
})
@ -67,10 +66,10 @@ public class UdpDocTest {
this.nextActor = nextActor;
// request creation of a bound listen socket
final ActorRef mgr = Udp.get(getContext().system()).getManager();
final ActorRef mgr = Udp.get(getContext().getSystem()).getManager();
mgr.tell(
UdpMessage.bind(self(), new InetSocketAddress("localhost", 0)),
self());
getSelf());
}
@Override
@ -78,9 +77,9 @@ public class UdpDocTest {
return receiveBuilder()
.match(Udp.Bound.class, bound -> {
//#listener
nextActor.tell(bound.localAddress(), sender());
nextActor.tell(bound.localAddress(), getSender());
//#listener
getContext().become(ready(sender()));
getContext().become(ready(getSender()));
})
.build();
}
@ -89,19 +88,19 @@ public class UdpDocTest {
return receiveBuilder()
.match(Udp.Received.class, r -> {
// echo server example: send back the data
socket.tell(UdpMessage.send(r.data(), r.sender()), self());
socket.tell(UdpMessage.send(r.data(), r.sender()), getSelf());
// or do some processing and forward it on
final Object processed = // parse data etc., e.g. using PipelineStage
// #listener
r.data().utf8String();
//#listener
nextActor.tell(processed, self());
nextActor.tell(processed, getSelf());
})
.matchEquals(UdpMessage.unbind(), message -> {
socket.tell(message, self());
socket.tell(message, getSelf());
})
.match(Udp.Unbound.class, message -> {
getContext().stop(self());
getContext().stop(getSelf());
})
.build();
}
@ -116,8 +115,8 @@ public class UdpDocTest {
this.remote = remote;
// create a restricted a.k.a. connected socket
final ActorRef mgr = UdpConnected.get(getContext().system()).getManager();
mgr.tell(UdpConnectedMessage.connect(self(), remote), self());
final ActorRef mgr = UdpConnected.get(getContext().getSystem()).getManager();
mgr.tell(UdpConnectedMessage.connect(self(), remote), getSelf());
}
@Override
@ -126,9 +125,9 @@ public class UdpDocTest {
.match(UdpConnected.Connected.class, message -> {
getContext().become(ready(sender()));
//#connected
sender()
getSender()
.tell(UdpConnectedMessage.send(ByteString.fromString("hello")),
self());
getSelf());
//#connected
})
.build();
@ -142,17 +141,17 @@ public class UdpDocTest {
if (r.data().utf8String().equals("hello")) {
connection.tell(
UdpConnectedMessage.send(ByteString.fromString("world")),
self());
getSelf());
}
// #connected
})
.match(String.class, str -> {
connection
.tell(UdpConnectedMessage.send(ByteString.fromString(str)),
self());
getSelf());
})
.matchEquals(UdpConnectedMessage.disconnect(), message -> {
connection.tell(message, self());
connection.tell(message, getSelf());
})
.match(UdpConnected.Disconnected.class, x -> {
getContext().stop(self());

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io.japi;
package jdocs.io.japi;
import java.net.InetSocketAddress;
import java.util.LinkedList;
@ -25,7 +25,7 @@ import akka.util.ByteString;
public class EchoHandler extends AbstractActor {
final LoggingAdapter log = Logging
.getLogger(getContext().system(), self());
.getLogger(getContext().getSystem(), getSelf());
final ActorRef connection;
final InetSocketAddress remote;
@ -72,7 +72,7 @@ public class EchoHandler extends AbstractActor {
return receiveBuilder()
.match(Received.class, msg -> {
final ByteString data = msg.data();
connection.tell(TcpMessage.write(data, new Ack(currentOffset())), self());
connection.tell(TcpMessage.write(data, new Ack(currentOffset())), getSelf());
buffer(data);
})
@ -81,7 +81,7 @@ public class EchoHandler extends AbstractActor {
})
.match(CommandFailed.class, msg -> {
final Write w = (Write) msg.cmd();
connection.tell(TcpMessage.resumeWriting(), self());
connection.tell(TcpMessage.resumeWriting(), getSelf());
getContext().become(buffering((Ack) w.ack()));
})
.match(ConnectionClosed.class, msg -> {
@ -159,7 +159,7 @@ public class EchoHandler extends AbstractActor {
return receiveBuilder()
.match(CommandFailed.class, msg -> {
// the command can only have been a Write
connection.tell(TcpMessage.resumeWriting(), self());
connection.tell(TcpMessage.resumeWriting(), getSelf());
getContext().become(closeResend(), false);
})
.match(Integer.class, msg -> {
@ -201,7 +201,7 @@ public class EchoHandler extends AbstractActor {
} else if (stored > HIGH_WATERMARK) {
log.debug("suspending reading at {}", currentOffset());
connection.tell(TcpMessage.suspendReading(), self());
connection.tell(TcpMessage.suspendReading(), getSelf());
suspended = true;
}
}
@ -217,7 +217,7 @@ public class EchoHandler extends AbstractActor {
if (suspended && stored < LOW_WATERMARK) {
log.debug("resuming reading");
connection.tell(TcpMessage.resumeReading(), self());
connection.tell(TcpMessage.resumeReading(), getSelf());
suspended = false;
}
}
@ -230,12 +230,12 @@ public class EchoHandler extends AbstractActor {
protected void writeAll() {
int i = 0;
for (ByteString data : storage) {
connection.tell(TcpMessage.write(data, new Ack(storageOffset + i++)), self());
connection.tell(TcpMessage.write(data, new Ack(storageOffset + i++)), getSelf());
}
}
protected void writeFirst() {
connection.tell(TcpMessage.write(storage.peek(), new Ack(storageOffset)), self());
connection.tell(TcpMessage.write(storage.peek(), new Ack(storageOffset)), getSelf());
}
//#storage-omitted

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io.japi;
package jdocs.io.japi;
import java.net.InetSocketAddress;
@ -15,14 +15,13 @@ import akka.event.LoggingAdapter;
import akka.io.Tcp;
import akka.io.Tcp.Bind;
import akka.io.Tcp.Bound;
import akka.io.Tcp.CommandFailed;
import akka.io.Tcp.Connected;
import akka.io.TcpMessage;
public class EchoManager extends AbstractActor {
final LoggingAdapter log = Logging
.getLogger(getContext().system(), self());
.getLogger(getContext().getSystem(), getSelf());
final Class<?> handlerClass;
@ -38,11 +37,11 @@ public class EchoManager extends AbstractActor {
@Override
public void preStart() throws Exception {
//#manager
final ActorRef tcpManager = Tcp.get(getContext().system()).manager();
final ActorRef tcpManager = Tcp.get(getContext().getSystem()).manager();
//#manager
tcpManager.tell(
TcpMessage.bind(self(), new InetSocketAddress("localhost", 0), 100),
self());
getSelf());
}
@Override
@ -67,13 +66,13 @@ public class EchoManager extends AbstractActor {
})
.match(Connected.class, conn -> {
log.info("received connection from [{}]", conn.remoteAddress());
final ActorRef connection = sender();
final ActorRef connection = getSender();
final ActorRef handler = getContext().actorOf(
Props.create(handlerClass, connection, conn.remoteAddress()));
//#echo-manager
connection.tell(TcpMessage.register(handler,
true, // <-- keepOpenOnPeerClosed flag
true), self());
true), getSelf());
//#echo-manager
})
.build();

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io.japi;
package jdocs.io.japi;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

View file

@ -2,11 +2,11 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io.japi;
package jdocs.io.japi;
import akka.testkit.AkkaJUnitActorSystemResource;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.ClassRule;
import org.junit.Test;
@ -23,7 +23,6 @@ import akka.io.Tcp.Connected;
import akka.io.Tcp.ConnectionClosed;
import akka.io.Tcp.Received;
import akka.io.TcpMessage;
import akka.japi.Procedure;
import akka.util.ByteString;
//#imports
@ -48,16 +47,16 @@ public class IODocTest extends AbstractJavaTest {
@Override
public void preStart() throws Exception {
final ActorRef tcp = Tcp.get(getContext().system()).manager();
final ActorRef tcp = Tcp.get(getContext().getSystem()).manager();
tcp.tell(TcpMessage.bind(self(),
new InetSocketAddress("localhost", 0), 100), self());
new InetSocketAddress("localhost", 0), 100), getSelf());
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Bound.class, msg -> {
manager.tell(msg, self());
manager.tell(msg, getSelf());
})
.match(CommandFailed.class, msg -> {
@ -65,10 +64,10 @@ public class IODocTest extends AbstractJavaTest {
})
.match(Connected.class, conn -> {
manager.tell(conn, self());
manager.tell(conn, getSelf());
final ActorRef handler = getContext().actorOf(
Props.create(SimplisticHandler.class));
sender().tell(TcpMessage.register(handler), self());
getSender().tell(TcpMessage.register(handler), getSelf());
})
.build();
}
@ -85,7 +84,7 @@ public class IODocTest extends AbstractJavaTest {
.match(Received.class, msg -> {
final ByteString data = msg.data();
System.out.println(data);
sender().tell(TcpMessage.write(data), self());
getSender().tell(TcpMessage.write(data), getSelf());
})
.match(ConnectionClosed.class, msg -> {
getContext().stop(self());
@ -110,21 +109,21 @@ public class IODocTest extends AbstractJavaTest {
this.remote = remote;
this.listener = listener;
final ActorRef tcp = Tcp.get(getContext().system()).manager();
tcp.tell(TcpMessage.connect(remote), self());
final ActorRef tcp = Tcp.get(getContext().getSystem()).manager();
tcp.tell(TcpMessage.connect(remote), getSelf());
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(CommandFailed.class, msg -> {
listener.tell("failed", self());
listener.tell("failed", getSelf());
getContext().stop(self());
})
.match(Connected.class, msg -> {
listener.tell(msg, self());
sender().tell(TcpMessage.register(self()), self());
listener.tell(msg, getSelf());
getSender().tell(TcpMessage.register(self()), getSelf());
getContext().become(connected(sender()));
})
.build();
@ -133,16 +132,16 @@ public class IODocTest extends AbstractJavaTest {
private Receive connected(final ActorRef connection) {
return receiveBuilder()
.match(ByteString.class, msg -> {
connection.tell(TcpMessage.write((ByteString) msg), self());
connection.tell(TcpMessage.write((ByteString) msg), getSelf());
})
.match(CommandFailed.class, msg -> {
// OS kernel socket buffer was full
})
.match(Received.class, msg -> {
listener.tell(msg.data(), self());
listener.tell(msg.data(), getSelf());
})
.matchEquals("close", msg -> {
connection.tell(TcpMessage.close(), self());
connection.tell(TcpMessage.close(), getSelf());
})
.match(ConnectionClosed.class, msg -> {
getContext().stop(self());

View file

@ -2,7 +2,7 @@
* Copyright (C) 2013-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io.japi;
package jdocs.io.japi;
//#message
public class Message {

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.io.japi;
package jdocs.io.japi;
import java.net.InetSocketAddress;
import java.util.LinkedList;
@ -16,14 +16,13 @@ import akka.io.Tcp.ConnectionClosed;
import akka.io.Tcp.Event;
import akka.io.Tcp.Received;
import akka.io.TcpMessage;
import akka.japi.Procedure;
import akka.util.ByteString;
//#simple-echo-handler
public class SimpleEchoHandler extends AbstractActor {
final LoggingAdapter log = Logging
.getLogger(getContext().system(), self());
.getLogger(getContext().getSystem(), getSelf());
final ActorRef connection;
final InetSocketAddress remote;
@ -46,7 +45,7 @@ public class SimpleEchoHandler extends AbstractActor {
.match(Received.class, msg -> {
final ByteString data = msg.data();
buffer(data);
connection.tell(TcpMessage.write(data, ACK), self());
connection.tell(TcpMessage.write(data, ACK), getSelf());
// now switch behavior to waiting for acknowledgement
getContext().become(buffering(), false);
@ -103,7 +102,7 @@ public class SimpleEchoHandler extends AbstractActor {
} else if (stored > highWatermark) {
log.debug("suspending reading");
connection.tell(TcpMessage.suspendReading(), self());
connection.tell(TcpMessage.suspendReading(), getSelf());
suspended = true;
}
}
@ -115,7 +114,7 @@ public class SimpleEchoHandler extends AbstractActor {
if (suspended && stored < lowWatermark) {
log.debug("resuming reading");
connection.tell(TcpMessage.resumeReading(), self());
connection.tell(TcpMessage.resumeReading(), getSelf());
suspended = false;
}
@ -126,7 +125,7 @@ public class SimpleEchoHandler extends AbstractActor {
getContext().unbecome();
}
} else {
connection.tell(TcpMessage.write(storage.peek(), ACK), self());
connection.tell(TcpMessage.write(storage.peek(), ACK), getSelf());
}
}
//#simple-helpers

View file

@ -1,4 +1,4 @@
package docs.io.japi;
package jdocs.io.japi;
import java.util.concurrent.CountDownLatch;

View file

@ -1,7 +1,7 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.pattern;
package jdocs.pattern;
import akka.actor.*;
import akka.pattern.Backoff;

View file

@ -2,13 +2,13 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.pattern;
package jdocs.pattern;
import akka.actor.*;
import akka.testkit.*;
import akka.testkit.TestEvent.Mute;
import akka.testkit.TestEvent.UnMute;
import docs.AbstractJavaTest;
import jdocs.AbstractJavaTest;
import org.junit.*;
import scala.concurrent.duration.Duration;
import scala.concurrent.duration.FiniteDuration;
@ -27,10 +27,10 @@ public class SchedulerPatternTest extends AbstractJavaTest {
//#schedule-constructor
public class ScheduleInConstructor extends AbstractActor {
private final Cancellable tick = getContext().system().scheduler().schedule(
private final Cancellable tick = getContext().getSystem().scheduler().schedule(
Duration.create(500, TimeUnit.MILLISECONDS),
Duration.create(1, TimeUnit.SECONDS),
self(), "tick", getContext().dispatcher(), null);
getSelf(), "tick", getContext().dispatcher(), null);
//#schedule-constructor
// this variable and constructor is declared here to not show up in the docs
final ActorRef target;
@ -50,7 +50,7 @@ public class SchedulerPatternTest extends AbstractJavaTest {
.matchEquals("tick", message -> {
// do something useful here
//#schedule-constructor
target.tell(message, self());
target.tell(message, getSelf());
//#schedule-constructor
})
.matchEquals("restart", message -> {
@ -74,9 +74,9 @@ public class SchedulerPatternTest extends AbstractJavaTest {
@Override
public void preStart() {
getContext().system().scheduler().scheduleOnce(
getContext().getSystem().scheduler().scheduleOnce(
Duration.create(500, TimeUnit.MILLISECONDS),
self(), "tick", getContext().dispatcher(), null);
getSelf(), "tick", getContext().dispatcher(), null);
}
// override postRestart so we don't call preStart and schedule a new message
@ -89,12 +89,12 @@ public class SchedulerPatternTest extends AbstractJavaTest {
return receiveBuilder()
.matchEquals("tick", message -> {
// send another periodic tick after the specified delay
getContext().system().scheduler().scheduleOnce(
getContext().getSystem().scheduler().scheduleOnce(
Duration.create(1, TimeUnit.SECONDS),
self(), "tick", getContext().dispatcher(), null);
getSelf(), "tick", getContext().dispatcher(), null);
// do something useful here
//#schedule-receive
target.tell(message, self());
target.tell(message, getSelf());
//#schedule-receive
})
.matchEquals("restart", message -> {

View file

@ -1,4 +1,4 @@
package docs.pattern;
package jdocs.pattern;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeoutException;
@ -59,7 +59,7 @@ public class SupervisedAsk {
@Override
public SupervisorStrategy supervisorStrategy() {
return new OneForOneStrategy(0, Duration.Zero(), cause -> {
caller.tell(new Status.Failure(cause), self());
caller.tell(new Status.Failure(cause), getSelf());
return SupervisorStrategy.stop();
});
}
@ -69,25 +69,25 @@ public class SupervisedAsk {
return receiveBuilder()
.match(AskParam.class, message -> {
askParam = message;
caller = sender();
caller = getSender();
targetActor = getContext().actorOf(askParam.props);
getContext().watch(targetActor);
targetActor.forward(askParam.message, getContext());
Scheduler scheduler = getContext().system().scheduler();
Scheduler scheduler = getContext().getSystem().scheduler();
timeoutMessage = scheduler.scheduleOnce(askParam.timeout.duration(),
self(), new AskTimeout(), getContext().dispatcher(), null);
getSelf(), new AskTimeout(), getContext().dispatcher(), null);
})
.match(Terminated.class, message -> {
Throwable ex = new ActorKilledException("Target actor terminated.");
caller.tell(new Status.Failure(ex), self());
caller.tell(new Status.Failure(ex), getSelf());
timeoutMessage.cancel();
getContext().stop(self());
getContext().stop(getSelf());
})
.match(AskTimeout.class, message -> {
Throwable ex = new TimeoutException("Target actor timed out after "
+ askParam.timeout.toString());
caller.tell(new Status.Failure(ex), self());
getContext().stop(self());
caller.tell(new Status.Failure(ex), getSelf());
getContext().stop(getSelf());
})
.build();
}

View file

@ -1,4 +1,4 @@
package docs.pattern;
package jdocs.pattern;
import akka.actor.ActorRef;
import akka.actor.ActorRefFactory;

View file

@ -1,18 +1,14 @@
/**
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.persistence;
package jdocs.persistence;
import akka.actor.*;
import akka.japi.Procedure;
import akka.japi.pf.ReceiveBuilder;
import akka.pattern.BackoffSupervisor;
import akka.persistence.*;
import akka.persistence.journal.EventAdapter;
import akka.persistence.journal.EventSeq;
import scala.concurrent.duration.Duration;
import scala.PartialFunction;
import scala.runtime.BoxedUnit;
import java.io.Serializable;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
@ -222,7 +218,7 @@ public class LambdaPersistenceDocTest {
return receiveBuilder()
.match(Msg.class, msg -> {
// ...
sender().tell(new Confirm(msg.deliveryId), self());
getSender().tell(new Confirm(msg.deliveryId), getSelf());
})
.build();
}
@ -331,13 +327,13 @@ public class LambdaPersistenceDocTest {
}
private void handleCommand(String c) {
sender().tell(c, self());
getSender().tell(c, getSelf());
persistAsync(String.format("evt-%s-1", c), e -> {
sender().tell(e, self());
getSender().tell(e, getSelf());
});
persistAsync(String.format("evt-%s-2", c), e -> {
sender().tell(e, self());
getSender().tell(e, getSelf());
});
}
@ -382,14 +378,14 @@ public class LambdaPersistenceDocTest {
private void handleCommand(String c) {
persistAsync(String.format("evt-%s-1", c), e -> {
sender().tell(e, self());
getSender().tell(e, getSelf());
});
persistAsync(String.format("evt-%s-2", c), e -> {
sender().tell(e, self());
getSender().tell(e, getSelf());
});
deferAsync(String.format("evt-%s-3", c), e -> {
sender().tell(e, self());
getSender().tell(e, getSelf());
});
}
@ -440,17 +436,17 @@ public class LambdaPersistenceDocTest {
//#nested-persist-persist
@Override public Receive createReceiveRecover() {
final Procedure<String> replyToSender = event -> sender().tell(event, self());
final Procedure<String> replyToSender = event -> getSender().tell(event, getSelf());
return receiveBuilder()
.match(String.class, msg -> {
persist(String.format("%s-outer-1", msg), event -> {
sender().tell(event, self());
getSender().tell(event, getSelf());
persist(String.format("%s-inner-1", event), replyToSender);
});
persist(String.format("%s-outer-2", msg), event -> {
sender().tell(event, self());
getSender().tell(event, getSelf());
persist(String.format("%s-inner-2", event), replyToSender);
});
})
@ -495,17 +491,17 @@ public class LambdaPersistenceDocTest {
//#nested-persistAsync-persistAsync
@Override
public Receive createReceive() {
final Procedure<String> replyToSender = event -> sender().tell(event, self());
final Procedure<String> replyToSender = event -> getSender().tell(event, getSelf());
return receiveBuilder()
.match(String.class, msg -> {
persistAsync(String.format("%s-outer-1", msg ), event -> {
sender().tell(event, self());
getSender().tell(event, getSelf());
persistAsync(String.format("%s-inner-1", event), replyToSender);
});
persistAsync(String.format("%s-outer-2", msg ), event -> {
sender().tell(event, self());
getSender().tell(event, getSelf());
persistAsync(String.format("%s-inner-1", event), replyToSender);
});
})
@ -515,8 +511,8 @@ public class LambdaPersistenceDocTest {
void usage(ActorRef persistentActor) {
//#nested-persistAsync-persistAsync-caller
persistentActor.tell("a", self());
persistentActor.tell("b", self());
persistentActor.tell("a", getSelf());
persistentActor.tell("b", getSelf());
// order of received messages:
// a
@ -554,7 +550,7 @@ public class LambdaPersistenceDocTest {
public Receive createReceive() {
return receiveBuilder()
.match(Shutdown.class, shutdown -> {
getContext().stop(self());
getContext().stop(getSelf());
})
.match(String.class, msg -> {
System.out.println(msg);

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.persistence;
package jdocs.persistence;
//#plugin-imports
import akka.dispatch.Futures;
@ -44,7 +44,7 @@ public class LambdaPersistencePluginDocTest {
public void preStart() throws Exception {
String path = "akka.tcp://example@127.0.0.1:2552/user/store";
ActorSelection selection = getContext().actorSelection(path);
selection.tell(new Identify(1), self());
selection.tell(new Identify(1), getSelf());
}
@Override
@ -54,7 +54,7 @@ public class LambdaPersistencePluginDocTest {
if (ai.correlationId().equals(1)) {
Optional<ActorRef> store = ai.getActorRef();
if (store.isPresent()) {
SharedLeveldbJournal.setStore(store.get(), getContext().system());
SharedLeveldbJournal.setStore(store.get(), getContext().getSystem());
} else {
throw new RuntimeException("Couldn't identify store");
}

View file

@ -2,7 +2,7 @@
* Copyright (C) 2015-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.persistence;
package jdocs.persistence;
import akka.persistence.journal.EventAdapter;
import akka.persistence.journal.EventSeq;

View file

@ -2,7 +2,7 @@
* Copyright (C) 2009-2017 Lightbend Inc. <http://www.lightbend.com>
*/
package docs.persistence;
package jdocs.persistence;
import akka.persistence.UntypedPersistentActor;

Some files were not shown because too many files have changed in this diff Show more