+act,sam,doc #3940 Added receive setter for Java Lambda actors

* Added a setter for Java lambda actors to "hide" the not so nice looking type signature of the "receive" method.
* Updated docs to reflect the changes.
* Converted samples to use the new setter.
This commit is contained in:
Björn Antonsson 2014-03-20 12:05:32 +01:00
parent 30ae25a90c
commit 723c931d16
23 changed files with 683 additions and 570 deletions

View file

@ -73,9 +73,8 @@ public class FaultHandlingDocSample {
context().setReceiveTimeout(Duration.create("15 seconds"));
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return LoggingReceive.create(ReceiveBuilder.
public Listener() {
receive(LoggingReceive.create(ReceiveBuilder.
match(Progress.class, progress -> {
log().info("Current progress: {} %", progress.percent);
if (progress.percent >= 100.0) {
@ -87,7 +86,8 @@ public class FaultHandlingDocSample {
// No progress within 15 seconds, ServiceUnavailable
log().error("Shutting down due to unavailable service");
context().system().shutdown();
}).build(), context());
}).build(), context()
));
}
}
@ -137,9 +137,8 @@ public class FaultHandlingDocSample {
return strategy;
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return LoggingReceive.create(ReceiveBuilder.
public Worker() {
receive(LoggingReceive.create(ReceiveBuilder.
matchEquals(Start, x -> progressListener == null, x -> {
progressListener = sender();
context().system().scheduler().schedule(
@ -160,7 +159,8 @@ public class FaultHandlingDocSample {
}
}, context().dispatcher()), context().dispatcher())
.to(progressListener);
}).build(), context());
}).build(), context())
);
}
}
@ -266,9 +266,8 @@ public class FaultHandlingDocSample {
storage.tell(new Get(key), self());
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return LoggingReceive.create(ReceiveBuilder.
public CounterService() {
receive(LoggingReceive.create(ReceiveBuilder.
match(Entry.class, entry -> entry.key.equals(key) && counter == null, entry -> {
// Reply from Storage of the initial value, now we can create the Counter
final long value = entry.value;
@ -301,7 +300,8 @@ public class FaultHandlingDocSample {
matchEquals(Reconnect, o -> {
// Re-establish storage after the scheduled delay
initStorage();
}).build(), context());
}).build(), context())
);
}
void forwardOrPlaceInBacklog(Object msg) {
@ -348,11 +348,8 @@ public class FaultHandlingDocSample {
public Counter(String key, long initialValue) {
this.key = key;
this.count = initialValue;
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return LoggingReceive.create(ReceiveBuilder.
receive(LoggingReceive.create(ReceiveBuilder.
match(UseStorage.class, useStorage -> {
storage = useStorage.storage;
storeCount();
@ -363,7 +360,8 @@ public class FaultHandlingDocSample {
}).
matchEquals(GetCurrentCount, gcc -> {
sender().tell(new CurrentCount(key, count), self());
}).build(), context());
}).build(), context())
);
}
void storeCount() {
@ -435,9 +433,8 @@ public class FaultHandlingDocSample {
final DummyDB db = DummyDB.instance;
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return LoggingReceive.create(ReceiveBuilder.
public Storage() {
receive(LoggingReceive.create(ReceiveBuilder.
match(Store.class, store -> {
db.save(store.entry.key, store.entry.value);
}).
@ -445,7 +442,8 @@ public class FaultHandlingDocSample {
Long value = db.load(get.key);
sender().tell(new Entry(get.key, value == null ?
Long.valueOf(0L) : value), self());
}).build(), context());
}).build(), context())
);
}
}