1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
| package org.liuyehcf.akka.cluster;
import akka.actor.ActorSystem; import akka.actor.Address; import akka.cluster.Cluster; import com.typesafe.config.Config; import com.typesafe.config.ConfigFactory; import org.liuyehcf.akka.common.util.AkkaConfigUtils; import org.liuyehcf.akka.common.util.IPUtils;
import java.util.Collections;
public class ClusterBoot { private static final class SeedNode { public static void main(String[] args) { Config clusterConfig = ConfigFactory.parseString( String.format( AkkaConfigUtils.loadConfig("cluster-with-static-seed-node.conf"), "127.0.0.1", 1100 ) );
ActorSystem.create("MyClusterSystem", clusterConfig); } }
private static final class Member1 { public static void main(String[] args) { Config clusterConfig = ConfigFactory.parseString( String.format( AkkaConfigUtils.loadConfig("cluster-with-static-seed-node.conf"), IPUtils.getLocalIp(), 1101 ) );
ActorSystem system = ActorSystem.create("MyClusterSystem", clusterConfig); system.actorOf(SimpleClusterListener.props()); } }
private static final class Member2 { public static void main(String[] args) { Config clusterConfig = ConfigFactory.parseString( String.format( AkkaConfigUtils.loadConfig("cluster-with-static-seed-node.conf"), IPUtils.getLocalIp(), 1102 ) );
ActorSystem system = ActorSystem.create("MyClusterSystem", clusterConfig); system.actorOf(SimpleClusterListener.props()); } }
private static final class Member3 { public static void main(String[] args) { Config clusterConfig = ConfigFactory.parseString( String.format( AkkaConfigUtils.loadConfig("cluster-with-none-seed-node.conf"), IPUtils.getLocalIp(), 1103 ) );
ActorSystem system = ActorSystem.create("MyClusterSystem", clusterConfig); system.actorOf(SimpleClusterListener.props());
final Cluster cluster = Cluster.get(system); Address address = new Address("akka.tcp", "MyClusterSystem", IPUtils.getLocalIp(), 1102); cluster.joinSeedNodes(Collections.singletonList(address)); } } }
|