Permalink
Browse files

增加集群测试

  • Loading branch information...
1 parent e04b0f5 commit adc3db67b02dd5d8e20af26a1a8544467c1c0eab decker committed Jun 7, 2012
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
80 pom.xml
@@ -1,39 +1,41 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.decker</groupId>
- <artifactId>gossiper</artifactId>
- <packaging>jar</packaging>
- <version>1.0-SNAPSHOT</version>
- <name>gossiper</name>
- <url>http://maven.apache.org</url>
- <dependencies>
- <dependency>
- <groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
- <version>2.0.1</version>
- </dependency>
- </dependencies>
-
- <repositories>
- <repository>
- <id>typesafe</id>
- <name>Typesafe Repository</name>
- <url>http://repo.typesafe.com/typesafe/releases/</url>
- </repository>
- </repositories>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.6</source>
- <target>1.6</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.decker</groupId>
+ <artifactId>akka-sample-cluster1</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>akka-sample-cluster</name>
+ <description>akka-sample-cluster</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.scala-lang</groupId>
+ <artifactId>scala-library</artifactId>
+ <version>2.9.1-1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.netty</groupId>
+ <artifactId>netty</artifactId>
+ <version>3.2.7.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.protobuf</groupId>
+ <artifactId>protobuf-java</artifactId>
+ <version>2.4.1</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
@@ -0,0 +1,24 @@
+package org.decker;
+
+import scala.collection.immutable.SortedSet;
+
+import com.typesafe.config.ConfigFactory;
+
+import akka.cluster.*;
+import akka.actor.ActorSystem;
+import akka.actor.ExtendedActorSystem;
+
+public class App {
+ public static void main(String [] argv) {
+ ActorSystem system = ExtendedActorSystem.create("Node0", ConfigFactory.load().getConfig("Node0"));
+ Cluster cluster = Cluster.get((ExtendedActorSystem) system);
+ System.out.println("status:" + cluster.status());
+
+ cluster.registerListener(new MembershipChangeListener(){
+ public void notify(SortedSet<Member> currentMemberRing) {
+ System.out.println("MemberChangeListner node 0 " + currentMemberRing);
+ }
+
+ });
+ }
+}
@@ -0,0 +1,68 @@
+package org.decker;
+
+import java.util.Iterator;
+
+import scala.collection.immutable.SortedSet;
+
+import com.typesafe.config.ConfigFactory;
+
+import akka.cluster.*;
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import akka.actor.Address;
+import akka.actor.ExtendedActorSystem;
+import akka.actor.Props;
+import akka.actor.UntypedActor;
+
+public class App1 {
+
+ static ActorRef storage;
+ static Cluster cluster;
+
+ public static void main(String [] argv) {
+ ActorSystem system = ExtendedActorSystem.create("Node1", ConfigFactory.load().getConfig("Node1"));
+ cluster = Cluster.get((ExtendedActorSystem) system);
+ System.out.println("status:" + cluster.status());
+
+ cluster.registerListener(new MembershipChangeListener(){
+ public void notify(SortedSet<Member> currentMemberRing) {
+ System.out.println("MemberChangeListner node 1 " + currentMemberRing);
+ //MemberList memberList = new MemberList(currentMemberRing, cluster);
+ //storage.tell(currentMemberRing);
+ }
+
+ });
+
+ Address address = new Address("akka", "Node0", "127.0.0.1", 2552);
+ System.out.println("node1 join node 0 : " + address);
+ cluster.join(address);
+
+ //storage = system.actorOf(new Props(Storage.class), "storage");
+ }
+
+ public class MemberList {
+ SortedSet<Member> currentMemberRing;
+ Cluster cluster;
+
+ MemberList(SortedSet<Member> currentMemberRing, Cluster cluster) {
+ this.currentMemberRing = currentMemberRing;
+ this.cluster = cluster;
+ }
+ }
+ public class Storage extends UntypedActor {
+
+ @Override
+ public void onReceive(Object message) throws Exception {
+ if(message instanceof MemberList ) {
+ Iterator iterator = (Iterator) ((MemberList) message).currentMemberRing.iterator();
+ while( iterator.hasNext()) {
+ Member o = (Member) iterator.next();
+ if(o instanceof Member) {
+
+ }
+ }
+ }
+ }
+
+ }
+}
@@ -0,0 +1,90 @@
+Node0 {
+ include "common"
+ akka {
+ # Akka version, checked against the runtime version of Akka.
+ version = "2.1-SNAPSHOT"
+
+ # Home directory of Akka, modules in the deploy directory will be loaded
+ home = ""
+
+ # Event handlers to register at boot time (Logging$DefaultLogger logs to STDOUT)
+ event-handlers = ["akka.event.Logging$DefaultLogger"]
+
+ # Log level used by the configured loggers (see "event-handlers") assoon
+ # as they have been started; before that, see "stdout-loglevel"
+ # Options: ERROR, WARNING, INFO, DEBUG
+ loglevel = "INFO"
+
+ # Log level for the very basic logger activated during AkkaApplication startup
+ # Options: ERROR, WARNING, INFO, DEBUG
+ stdout-loglevel = "WARNING"
+
+ # Log the complete configuration at INFO level when the actor system is started.
+ # This is useful when you are uncertain of what configuration is used.
+ log-config-on-start = "off"
+ loglevel = DEBUG
+ stdout-loglevel = DEBUG
+
+ actor {
+ provider = "akka.remote.RemoteActorRefProvider"
+
+ }
+
+ remote {
+ transport = "akka.remote.netty.NettyRemoteTransport"
+ netty {
+ hostname = "127.0.0.1"
+ port = 2552
+ }
+ }
+ cluster {
+ failure-detector.threshold = 3
+ auto-down = on
+ }
+
+ }
+}
+
+Node1 {
+ include "common"
+ akka {
+ # Akka version, checked against the runtime version of Akka.
+ version = "2.1-SNAPSHOT"
+
+ # Home directory of Akka, modules in the deploy directory will be loaded
+ home = ""
+
+ # Event handlers to register at boot time (Logging$DefaultLogger logs to STDOUT)
+ event-handlers = ["akka.event.Logging$DefaultLogger"]
+
+ # Log level used by the configured loggers (see "event-handlers") assoon
+ # as they have been started; before that, see "stdout-loglevel"
+ # Options: ERROR, WARNING, INFO, DEBUG
+ loglevel = "INFO"
+
+ # Log level for the very basic logger activated during AkkaApplication startup
+ # Options: ERROR, WARNING, INFO, DEBUG
+ stdout-loglevel = "WARNING"
+
+ # Log the complete configuration at INFO level when the actor system is started.
+ # This is useful when you are uncertain of what configuration is used.
+ log-config-on-start = "off"
+ loglevel = DEBUG
+ stdout-loglevel = DEBUG
+
+ actor {
+ provider = "akka.remote.RemoteActorRefProvider"
+ }
+
+ remote {
+ transport = "akka.remote.netty.NettyRemoteTransport"
+ netty {
+ hostname = "127.0.0.1"
+ port = 2553
+ }
+ }
+ cluster {
+ node-to-join = "akka://Node0@localhost:2552"
+ }
+ }
+}

0 comments on commit adc3db6

Please sign in to comment.