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
|
|
@ -19,52 +19,56 @@ public class ClusterClientTest extends JUnitSuite {
|
|||
|
||||
@ClassRule
|
||||
public static AkkaJUnitActorSystemResource actorSystemResource =
|
||||
new AkkaJUnitActorSystemResource("DistributedPubSubMediatorTest",
|
||||
ConfigFactory.parseString(
|
||||
"akka.actor.provider = \"cluster\"\n" +
|
||||
"akka.remote.netty.tcp.port=0\n" +
|
||||
"akka.remote.artery.canonical.port=0"));
|
||||
new AkkaJUnitActorSystemResource(
|
||||
"DistributedPubSubMediatorTest",
|
||||
ConfigFactory.parseString(
|
||||
"akka.actor.provider = \"cluster\"\n"
|
||||
+ "akka.remote.netty.tcp.port=0\n"
|
||||
+ "akka.remote.artery.canonical.port=0"));
|
||||
|
||||
private final ActorSystem system = actorSystemResource.getSystem();
|
||||
|
||||
//#initialContacts
|
||||
// #initialContacts
|
||||
Set<ActorPath> initialContacts() {
|
||||
return new HashSet<ActorPath>(Arrays.asList(
|
||||
ActorPaths.fromString("akka.tcp://OtherSys@host1:2552/system/receptionist"),
|
||||
ActorPaths.fromString("akka.tcp://OtherSys@host2:2552/system/receptionist")));
|
||||
return new HashSet<ActorPath>(
|
||||
Arrays.asList(
|
||||
ActorPaths.fromString("akka.tcp://OtherSys@host1:2552/system/receptionist"),
|
||||
ActorPaths.fromString("akka.tcp://OtherSys@host2:2552/system/receptionist")));
|
||||
}
|
||||
//#initialContacts
|
||||
|
||||
// #initialContacts
|
||||
|
||||
@Test
|
||||
public void demonstrateUsage() {
|
||||
//#server
|
||||
// #server
|
||||
ActorRef serviceA = system.actorOf(Props.create(Service.class), "serviceA");
|
||||
ClusterClientReceptionist.get(system).registerService(serviceA);
|
||||
|
||||
ActorRef serviceB = system.actorOf(Props.create(Service.class), "serviceB");
|
||||
ClusterClientReceptionist.get(system).registerService(serviceB);
|
||||
//#server
|
||||
// #server
|
||||
|
||||
//#client
|
||||
final ActorRef c = system.actorOf(ClusterClient.props(
|
||||
ClusterClientSettings.create(system).withInitialContacts(initialContacts())),
|
||||
"client");
|
||||
// #client
|
||||
final ActorRef c =
|
||||
system.actorOf(
|
||||
ClusterClient.props(
|
||||
ClusterClientSettings.create(system).withInitialContacts(initialContacts())),
|
||||
"client");
|
||||
c.tell(new ClusterClient.Send("/user/serviceA", "hello", true), ActorRef.noSender());
|
||||
c.tell(new ClusterClient.SendToAll("/user/serviceB", "hi"), ActorRef.noSender());
|
||||
//#client
|
||||
// #client
|
||||
|
||||
system.actorOf(Props.create(ClientListener.class, c));
|
||||
system.actorOf(Props.create(ReceptionistListener.class, ClusterClientReceptionist.get(system).underlying()));
|
||||
system.actorOf(
|
||||
Props.create(
|
||||
ReceptionistListener.class, ClusterClientReceptionist.get(system).underlying()));
|
||||
}
|
||||
|
||||
static public class Service extends UntypedAbstractActor {
|
||||
public void onReceive(Object msg) {
|
||||
}
|
||||
public static class Service extends UntypedAbstractActor {
|
||||
public void onReceive(Object msg) {}
|
||||
}
|
||||
|
||||
//#clientEventsListener
|
||||
static public class ClientListener extends AbstractActor {
|
||||
// #clientEventsListener
|
||||
public static class ClientListener extends AbstractActor {
|
||||
private final ActorRef targetClient;
|
||||
private final Set<ActorPath> contactPoints = new HashSet<>();
|
||||
|
||||
|
|
@ -80,26 +84,31 @@ public class ClusterClientTest extends JUnitSuite {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(ContactPoints.class, msg -> {
|
||||
contactPoints.addAll(msg.getContactPoints());
|
||||
// Now do something with an up-to-date "contactPoints"
|
||||
})
|
||||
.match(ContactPointAdded.class, msg -> {
|
||||
contactPoints.add(msg.contactPoint());
|
||||
// Now do something with an up-to-date "contactPoints"
|
||||
})
|
||||
.match(ContactPointRemoved.class, msg -> {
|
||||
contactPoints.remove(msg.contactPoint());
|
||||
// Now do something with an up-to-date "contactPoints"
|
||||
})
|
||||
.build();
|
||||
.match(
|
||||
ContactPoints.class,
|
||||
msg -> {
|
||||
contactPoints.addAll(msg.getContactPoints());
|
||||
// Now do something with an up-to-date "contactPoints"
|
||||
})
|
||||
.match(
|
||||
ContactPointAdded.class,
|
||||
msg -> {
|
||||
contactPoints.add(msg.contactPoint());
|
||||
// Now do something with an up-to-date "contactPoints"
|
||||
})
|
||||
.match(
|
||||
ContactPointRemoved.class,
|
||||
msg -> {
|
||||
contactPoints.remove(msg.contactPoint());
|
||||
// Now do something with an up-to-date "contactPoints"
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
//#clientEventsListener
|
||||
// #clientEventsListener
|
||||
|
||||
//#receptionistEventsListener
|
||||
static public class ReceptionistListener extends AbstractActor {
|
||||
// #receptionistEventsListener
|
||||
public static class ReceptionistListener extends AbstractActor {
|
||||
private final ActorRef targetReceptionist;
|
||||
private final Set<ActorRef> clusterClients = new HashSet<>();
|
||||
|
||||
|
|
@ -115,22 +124,27 @@ public class ClusterClientTest extends JUnitSuite {
|
|||
@Override
|
||||
public Receive createReceive() {
|
||||
return receiveBuilder()
|
||||
.match(ClusterClients.class, msg -> {
|
||||
clusterClients.addAll(msg.getClusterClients());
|
||||
// Now do something with an up-to-date "clusterClients"
|
||||
})
|
||||
.match(ClusterClientUp.class, msg -> {
|
||||
clusterClients.add(msg.clusterClient());
|
||||
// Now do something with an up-to-date "clusterClients"
|
||||
})
|
||||
.match(ClusterClientUnreachable.class, msg -> {
|
||||
clusterClients.remove(msg.clusterClient());
|
||||
// Now do something with an up-to-date "clusterClients"
|
||||
})
|
||||
.build();
|
||||
.match(
|
||||
ClusterClients.class,
|
||||
msg -> {
|
||||
clusterClients.addAll(msg.getClusterClients());
|
||||
// Now do something with an up-to-date "clusterClients"
|
||||
})
|
||||
.match(
|
||||
ClusterClientUp.class,
|
||||
msg -> {
|
||||
clusterClients.add(msg.clusterClient());
|
||||
// Now do something with an up-to-date "clusterClients"
|
||||
})
|
||||
.match(
|
||||
ClusterClientUnreachable.class,
|
||||
msg -> {
|
||||
clusterClients.remove(msg.clusterClient());
|
||||
// Now do something with an up-to-date "clusterClients"
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
//#receptionistEventsListener
|
||||
// #receptionistEventsListener
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue