+clu #17870 add Java api for joinSeedNodes

This commit is contained in:
Konrad Malawski 2015-07-01 10:38:13 +02:00
parent afa9549307
commit 75c5810970
3 changed files with 43 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import akka.ConfigurationException
import akka.actor._
import akka.dispatch.MonitorableThreadFactory
import akka.event.{ Logging, LoggingAdapter }
import akka.japi.Util
import akka.pattern._
import akka.remote.{ DefaultFailureDetectorRegistry, FailureDetector, _ }
import com.typesafe.config.{ Config, ConfigFactory }
@ -265,13 +266,23 @@ class Cluster(val system: ExtendedActorSystem) extends Extension {
* An actor system can only join a cluster once. Additional attempts will be ignored.
* When it has successfully joined it must be restarted to be able to join another
* cluster or to join the same cluster again.
*
* JAVA API: Use akka.japi.Util.immutableSeq to convert a java.lang.Iterable
* to the type needed for the seedNodes parameter.
*/
def joinSeedNodes(seedNodes: immutable.Seq[Address]): Unit =
clusterCore ! InternalClusterAction.JoinSeedNodes(seedNodes.toVector)
/**
* Java API
*
* Join the specified seed nodes without defining them in config.
* Especially useful from tests when Addresses are unknown before startup time.
*
* An actor system can only join a cluster once. Additional attempts will be ignored.
* When it has successfully joined it must be restarted to be able to join another
* cluster or to join the same cluster again.
*/
def joinSeedNodes(seedNodes: java.util.List[Address]): Unit =
joinSeedNodes(Util.immutableSeq(seedNodes))
/**
* Send command to issue state transition to LEAVING for the node specified by 'address'.
* The member will go through the status changes [[MemberStatus]] `Leaving` (not published to

View file

@ -3,6 +3,7 @@
*/
package akka.cluster
import akka.actor.Address
import com.typesafe.config.ConfigFactory
import akka.remote.testkit.MultiNodeConfig
import akka.remote.testkit.MultiNodeSpec
@ -45,7 +46,8 @@ abstract class SingletonClusterSpec(multiNodeConfig: SingletonClusterMultiNodeCo
"become singleton cluster when started with seed-nodes" taggedAs LongRunningTest in {
runOn(first) {
cluster.joinSeedNodes(Vector(first))
val nodes: immutable.IndexedSeq[Address] = Vector(first) //
cluster.joinSeedNodes(nodes)
awaitMembersUp(1)
clusterView.isSingletonCluster should ===(true)
}

View file

@ -0,0 +1,26 @@
/**
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.cluster;
import akka.actor.ActorSystem;
import akka.actor.Address;
import java.util.Collections;
import java.util.List;
// Doc code, compile only
@SuppressWarnings("ConstantConditions")
public class ClusterJavaCompileTest {
final ActorSystem system = null;
final Cluster cluster = null;
public void compileJoinSeedNodesInJava() {
final List<Address> addresses = Collections.singletonList(new Address("akka.tcp", "MySystem"));
cluster.joinSeedNodes(addresses);
}
}