Formatting java codes with sbt-java-formatter.
This commit is contained in:
parent
27500001ea
commit
998c5a9285
401 changed files with 19750 additions and 17450 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
package jdocs.ddata;
|
||||
|
||||
//#data-bot
|
||||
// #data-bot
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
|
|
@ -30,13 +30,20 @@ public class DataBot extends AbstractActor {
|
|||
|
||||
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
|
||||
|
||||
private final ActorRef replicator =
|
||||
DistributedData.get(getContext().getSystem()).replicator();
|
||||
private final ActorRef replicator = DistributedData.get(getContext().getSystem()).replicator();
|
||||
private final Cluster node = Cluster.get(getContext().getSystem());
|
||||
|
||||
private final Cancellable tickTask = getContext().getSystem().scheduler().schedule(
|
||||
Duration.ofSeconds(5), Duration.ofSeconds(5), getSelf(), TICK,
|
||||
getContext().getDispatcher(), getSelf());
|
||||
private final Cancellable tickTask =
|
||||
getContext()
|
||||
.getSystem()
|
||||
.scheduler()
|
||||
.schedule(
|
||||
Duration.ofSeconds(5),
|
||||
Duration.ofSeconds(5),
|
||||
getSelf(),
|
||||
TICK,
|
||||
getContext().getDispatcher(),
|
||||
getSelf());
|
||||
|
||||
private final Key<ORSet<String>> dataKey = ORSetKey.create("key");
|
||||
|
||||
|
|
@ -44,37 +51,33 @@ public class DataBot extends AbstractActor {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(String.class, a -> a.equals(TICK), a -> receiveTick())
|
||||
.match(Changed.class, c -> c.key().equals(dataKey), c -> receiveChanged((Changed<ORSet<String>>) c))
|
||||
.match(UpdateResponse.class, r -> receiveUpdateResponse())
|
||||
.build();
|
||||
.match(String.class, a -> a.equals(TICK), a -> receiveTick())
|
||||
.match(
|
||||
Changed.class,
|
||||
c -> c.key().equals(dataKey),
|
||||
c -> receiveChanged((Changed<ORSet<String>>) c))
|
||||
.match(UpdateResponse.class, r -> receiveUpdateResponse())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
private void receiveTick() {
|
||||
String s = String.valueOf((char) ThreadLocalRandom.current().nextInt(97, 123));
|
||||
if (ThreadLocalRandom.current().nextBoolean()) {
|
||||
// add
|
||||
log.info("Adding: {}", s);
|
||||
Update<ORSet<String>> update = new Update<>(
|
||||
dataKey,
|
||||
ORSet.create(),
|
||||
Replicator.writeLocal(),
|
||||
curr -> curr.add(node, s));
|
||||
replicator.tell(update, getSelf());
|
||||
Update<ORSet<String>> update =
|
||||
new Update<>(dataKey, ORSet.create(), Replicator.writeLocal(), curr -> curr.add(node, s));
|
||||
replicator.tell(update, getSelf());
|
||||
} else {
|
||||
// remove
|
||||
log.info("Removing: {}", s);
|
||||
Update<ORSet<String>> update = new Update<>(
|
||||
dataKey,
|
||||
ORSet.create(),
|
||||
Replicator.writeLocal(),
|
||||
curr -> curr.remove(node, s));
|
||||
Update<ORSet<String>> update =
|
||||
new Update<>(
|
||||
dataKey, ORSet.create(), Replicator.writeLocal(), curr -> curr.remove(node, s));
|
||||
replicator.tell(update, getSelf());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void receiveChanged(Changed<ORSet<String>> c) {
|
||||
ORSet<String> data = c.dataValue();
|
||||
log.info("Current elements: {}", data.getElements());
|
||||
|
|
@ -84,7 +87,6 @@ public class DataBot extends AbstractActor {
|
|||
// ignore
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void preStart() {
|
||||
Subscribe<ORSet<String>> subscribe = new Subscribe<>(dataKey, getSelf());
|
||||
|
|
@ -92,9 +94,8 @@ public class DataBot extends AbstractActor {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void postStop(){
|
||||
public void postStop() {
|
||||
tickTask.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
//#data-bot
|
||||
// #data-bot
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue