metadata = ImmutableMap.of("name", "Carol");
+ Cluster carol = Cluster.joinAwait(metadata, alice.address());
+
+ // Start Dan on port 3000
+ ClusterConfig configWithFixedPort = ClusterConfig.builder()
+ .seedMembers(alice.address())
+ .portAutoIncrement(false)
+ .port(3000)
+ .build();
+ Cluster dan = Cluster.joinAwait(configWithFixedPort);
+
+ // Start Eve in separate cluster (separate sync group)
+ ClusterConfig configWithSyncGroup = ClusterConfig.builder()
+ .seedMembers(alice.address(), bob.address(), carol.address(), dan.address()) // won't join anyway
+ .syncGroup("another cluster")
+ .build();
+ Cluster eve = Cluster.joinAwait(configWithSyncGroup);
+
+ // Print cluster members of each node
+
+ System.out.println("Alice (" + alice.address() + ") cluster: "
+ + alice.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
+
+ System.out.println("Bob (" + bob.address() + ") cluster: "
+ + bob.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
+
+ System.out.println("Carol (" + carol.address() + ") cluster: "
+ + carol.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
+
+ System.out.println("Dan (" + dan.address() + ") cluster: "
+ + dan.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
+
+ System.out.println("Eve (" + eve.address() + ") cluster: " // alone in cluster
+ + eve.members().stream().map(Member::toString).collect(joining("\n", "\n", "\n")));
+ }
+
+}
diff --git a/examples/src/main/java/io/scalecube/examples/ClusterMetadataExample.java b/examples/src/main/java/io/scalecube/examples/ClusterMetadataExample.java
new file mode 100644
index 00000000..7b681fc9
--- /dev/null
+++ b/examples/src/main/java/io/scalecube/examples/ClusterMetadataExample.java
@@ -0,0 +1,54 @@
+package io.scalecube.examples;
+
+import io.scalecube.cluster.Cluster;
+import io.scalecube.cluster.Member;
+import io.scalecube.transport.Message;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Using Cluster metadata: metadata is set of custom parameters that may be used by application developers to attach
+ * additional business information and identifications to cluster members.
+ *
+ *
+ * in this example we see how to attach logical name to a cluster member we nick name Joe
+ *
+ *
+ * @author ronen_h, Anton Kharenko
+ */
+public class ClusterMetadataExample {
+
+ /**
+ * Main method.
+ */
+ public static void main(String[] args) throws Exception {
+ // Start seed cluster member Alice
+ Cluster alice = Cluster.joinAwait();
+
+ // Join Joe to cluster with metadata
+ Map metadata = ImmutableMap.of("name", "Joe");
+ Cluster joe = Cluster.joinAwait(metadata, alice.address());
+
+ // Subscribe Joe to listen for incoming messages and print them to system out
+ joe.listen()
+ .map(Message::data)
+ .subscribe(System.out::println);
+
+ // Scan the list of members in the cluster and find Joe there
+ Optional joeMemberOptional = alice.otherMembers().stream()
+ .filter(member -> "Joe".equals(member.metadata().get("name")))
+ .findAny();
+
+ // Send hello to Joe
+ if (joeMemberOptional.isPresent()) {
+ alice.send(joeMemberOptional.get(), Message.fromData("Hello Joe"));
+ }
+
+ TimeUnit.SECONDS.sleep(3);
+ }
+
+}
diff --git a/examples/src/main/java/io/scalecube/examples/GossipExample.java b/examples/src/main/java/io/scalecube/examples/GossipExample.java
new file mode 100644
index 00000000..077a1ed4
--- /dev/null
+++ b/examples/src/main/java/io/scalecube/examples/GossipExample.java
@@ -0,0 +1,39 @@
+package io.scalecube.examples;
+
+import io.scalecube.cluster.Cluster;
+import io.scalecube.transport.Message;
+
+/**
+ * Basic example for member gossiping between cluster members. to run the example Start ClusterNodeA and cluster
+ * ClusterNodeB A listen on gossip B spread gossip
+ *
+ * @author ronen hamias, Anton Kharenko
+ *
+ */
+public class GossipExample {
+
+ /**
+ * Main method.
+ */
+ public static void main(String[] args) throws Exception {
+ // Start cluster nodes and subscribe on listening gossips
+ Cluster alice = Cluster.joinAwait();
+ alice.listenGossips().subscribe(gossip -> System.out.println("Alice heard: " + gossip.data()));
+
+ Cluster bob = Cluster.joinAwait(alice.address());
+ bob.listenGossips().subscribe(gossip -> System.out.println("Bob heard: " + gossip.data()));
+
+ Cluster carol = Cluster.joinAwait(alice.address());
+ carol.listenGossips().subscribe(gossip -> System.out.println("Carol heard: " + gossip.data()));
+
+ Cluster dan = Cluster.joinAwait(alice.address());
+ dan.listenGossips().subscribe(gossip -> System.out.println("Dan heard: " + gossip.data()));
+
+ // Start cluster node Eve that joins cluster and spreads gossip
+ Cluster eve = Cluster.joinAwait(alice.address());
+ eve.spreadGossip(Message.fromData("Gossip from Eve"));
+
+ // Avoid exit main thread immediately ]:->
+ Thread.sleep(1000);
+ }
+}
diff --git a/examples/src/main/java/io/scalecube/examples/MembershipEventsExample.java b/examples/src/main/java/io/scalecube/examples/MembershipEventsExample.java
new file mode 100644
index 00000000..3f18843e
--- /dev/null
+++ b/examples/src/main/java/io/scalecube/examples/MembershipEventsExample.java
@@ -0,0 +1,60 @@
+package io.scalecube.examples;
+
+import io.scalecube.cluster.Cluster;
+import io.scalecube.cluster.ClusterConfig;
+import io.scalecube.cluster.ClusterMath;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.Future;
+
+/**
+ * Example of subscribing and listening for cluster membership events which is emmited when new member joins or leave
+ * cluster.
+ *
+ * @author Anton Kharenko
+ */
+public class MembershipEventsExample {
+
+ private static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
+
+ /**
+ * Main method.
+ */
+ public static void main(String[] args) throws Exception {
+ // Alice init cluster
+ Cluster alice = Cluster.joinAwait(ImmutableMap.of("name", "Alice"));
+ System.out.println(now() + " Alice join members: " + alice.members());
+ alice.listenMembership()
+ .subscribe(event -> System.out.println(now() + " Alice received: " + event));
+
+ // Bob join cluster
+ Cluster bob = Cluster.joinAwait(ImmutableMap.of("name", "Bob"), alice.address());
+ System.out.println(now() + " Bob join members: " + bob.members());
+ bob.listenMembership()
+ .subscribe(event -> System.out.println(now() + " Bob received: " + event));
+
+ // Carol join cluster
+ Cluster carol = Cluster.joinAwait(ImmutableMap.of("name", "Carol"), alice.address(), bob.address());
+ System.out.println(now() + " Carol join members: " + carol.members());
+ carol.listenMembership()
+ .subscribe(event -> System.out.println(now() + " Carol received: " + event));
+
+ // Bob leave cluster
+ Future shutdownFuture = bob.shutdown();
+ shutdownFuture.get();
+
+ // Avoid exit main thread immediately ]:->
+ long pingInterval = ClusterConfig.DEFAULT_PING_INTERVAL;
+ long suspicionTimeout = ClusterMath.suspicionTimeout(ClusterConfig.DEFAULT_SUSPICION_MULT, 4, pingInterval);
+ long maxRemoveTimeout = suspicionTimeout + 3 * pingInterval;
+ Thread.sleep(maxRemoveTimeout);
+ }
+
+ private static String now() {
+ return sdf.format(new Date());
+ }
+
+}
diff --git a/examples/src/main/java/io/scalecube/examples/MessagingExample.java b/examples/src/main/java/io/scalecube/examples/MessagingExample.java
new file mode 100644
index 00000000..8d4ef1aa
--- /dev/null
+++ b/examples/src/main/java/io/scalecube/examples/MessagingExample.java
@@ -0,0 +1,49 @@
+package io.scalecube.examples;
+
+import io.scalecube.cluster.Cluster;
+import io.scalecube.transport.Message;
+
+/**
+ * Basic example for member transport between cluster members to run the example Start ClusterNodeA and cluster
+ * ClusterNodeB A listen on transport messages B send message to member A.
+ *
+ * @author ronen hamias, Anton Kharenko
+ *
+ */
+public class MessagingExample {
+
+ /**
+ * Main method.
+ */
+ public static void main(String[] args) throws Exception {
+ // Start cluster node Alice to listen and respond for incoming greeting messages
+ Cluster alice = Cluster.joinAwait();
+ alice.listen().subscribe(msg -> {
+ System.out.println("Alice received: " + msg.data());
+ alice.send(msg.sender(), Message.fromData("Greetings from Alice"));
+ });
+
+ // Join cluster node Bob to cluster with Alice, listen and respond for incoming greeting messages
+ Cluster bob = Cluster.joinAwait(alice.address());
+ bob.listen().subscribe(msg -> {
+ System.out.println("Bob received: " + msg.data());
+ bob.send(msg.sender(), Message.fromData("Greetings from Bob"));
+ });
+
+ // Join cluster node Carol to cluster with Alice and Bob
+ Cluster carol = Cluster.joinAwait(alice.address(), bob.address());
+
+ // Subscribe Carol to listen for incoming messages and print them to system out
+ carol.listen()
+ .map(msg -> "Carol received: " + msg.data())
+ .subscribe(System.out::println);
+
+ // Send from Carol greeting message to all other cluster members (which is Alice and Bob)
+ Message greetingMsg = Message.fromData("Greetings from Carol");
+ carol.otherMembers().forEach(member -> carol.send(member, greetingMsg));
+
+ // Avoid exit main thread immediately ]:->
+ Thread.sleep(1000);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 00000000..8f09e789
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,370 @@
+
+
+ 4.0.0
+
+ io.scalecube
+ scalecube-parent
+ 1.0.9-SNAPSHOT
+ pom
+
+ ScaleCube
+
+ ScaleCube is a lightweight decentralized cluster membership, failure detection, messaging and
+ gossip protocol library for the Java VM.
+
+ 2015
+ http://scalecube.io
+
+
+
+ The Apache License, Version 2.0
+ http://www.apache.org/licenses/LICENSE-2.0.txt
+
+
+
+
+ 3.0.3
+
+
+
+ https://github.com/scalecube/scalecube
+ scm:git:git@github.com:scalecube/scalecube.git
+ scm:git:git@github.com:scalecube/scalecube.git
+
+ HEAD
+
+
+
+
+ scalecube.io
+ The ScaleCube Project Contributors
+ info@scalecube.io
+ The ScaleCube Project
+ http://scalecube.io/
+
+
+
+
+
+ ossrh
+ https://oss.sonatype.org/content/repositories/snapshots
+
+
+ ossrh
+ https://oss.sonatype.org/service/local/staging/deploy/maven2/
+
+
+
+
+ -Xms1024m -Xmx2048m
+ UTF-8
+ UTF-8
+
+ 1.7.7
+ 1.3.0
+ 19.0
+ 2.0.3
+ 4.1.21.Final
+ 2.3.0
+ 1.6.0
+ 3.4.0
+ 3.1.2
+ 2.9.0
+
+ true
+
+
+
+ transport
+ cluster
+ testlib
+ benchmark
+ examples
+ utils
+ stresstests
+
+
+
+
+
+
+