use of io.scalecube.cluster.ClusterImpl in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerManagerGossipImpl method start.
@Override
public void start() {
final String localIp = NetworkUtil.LOCAL_IP;
monoCluster = new ClusterImpl().config(clusterConfig -> clusterConfig.externalHost(localIp).externalPort(gossipListenPort)).membership(membershipConfig -> membershipConfig.seedMembers(seedMembers()).syncInterval(5_000)).transportFactory(TcpTransportFactory::new).transport(transportConfig -> transportConfig.port(gossipListenPort)).handler(cluster1 -> this).start();
// subscribe and start & join the cluster
monoCluster.subscribe();
this.localBroker = new RSocketBroker(localIp, brokerProperties.getExternalDomain());
this.consistentHash = new KetamaConsistentHash<>(12, Collections.singletonList(localIp));
brokers.put(localIp, localBroker);
log.info(RsocketErrorCode.message("RST-300002"));
Metrics.globalRegistry.gauge("cluster.broker.count", this, (DoubleFunction<RSocketBrokerManagerGossipImpl>) brokerManagerGossip -> brokerManagerGossip.brokers.size());
this.status = 1;
}
use of io.scalecube.cluster.ClusterImpl in project ignite-3 by apache.
the class ItScaleCubeNetworkMessagingTest method stopForcefully.
/**
* Find the cluster's transport and force it to stop.
*
* @param cluster Cluster to be shutdown.
* @throws Exception If failed to stop.
*/
private static void stopForcefully(ClusterService cluster) throws Exception {
Field clusterSvcImplField = cluster.getClass().getDeclaredField("val$clusterSvc");
clusterSvcImplField.setAccessible(true);
ClusterService innerClusterSvc = (ClusterService) clusterSvcImplField.get(cluster);
Field clusterImplField = innerClusterSvc.getClass().getDeclaredField("cluster");
clusterImplField.setAccessible(true);
ClusterImpl clusterImpl = (ClusterImpl) clusterImplField.get(innerClusterSvc);
Field transportField = clusterImpl.getClass().getDeclaredField("transport");
transportField.setAccessible(true);
Transport transport = (Transport) transportField.get(clusterImpl);
Method stop = transport.getClass().getDeclaredMethod("stop");
stop.setAccessible(true);
Mono<?> invoke = (Mono<?>) stop.invoke(transport);
invoke.block();
}
use of io.scalecube.cluster.ClusterImpl in project ignite-3 by apache.
the class ScaleCubeClusterServiceFactory method createClusterService.
/**
* Creates a new {@link ClusterService} using the provided context. The created network will not be in the "started" state.
*
* @param context Cluster context.
* @param networkConfiguration Network configuration.
* @param nettyBootstrapFactory Bootstrap factory.
* @return New cluster service.
*/
public ClusterService createClusterService(ClusterLocalConfiguration context, NetworkConfiguration networkConfiguration, NettyBootstrapFactory nettyBootstrapFactory) {
var messageFactory = new NetworkMessagesFactory();
var topologyService = new ScaleCubeTopologyService();
UserObjectSerializationContext userObjectSerialization = createUserObjectSerializationContext();
var messagingService = new DefaultMessagingService(messageFactory, topologyService, userObjectSerialization);
return new AbstractClusterService(context, topologyService, messagingService) {
private volatile ClusterImpl cluster;
private volatile ConnectionManager connectionMgr;
private volatile CompletableFuture<Void> shutdownFuture;
/**
* {@inheritDoc}
*/
@Override
public void start() {
String consistentId = context.getName();
var serializationService = new SerializationService(context.getSerializationRegistry(), userObjectSerialization);
UUID launchId = UUID.randomUUID();
NetworkView configView = networkConfiguration.value();
connectionMgr = new ConnectionManager(configView, serializationService, consistentId, () -> new RecoveryServerHandshakeManager(launchId, consistentId, messageFactory), () -> new RecoveryClientHandshakeManager(launchId, consistentId, messageFactory), nettyBootstrapFactory);
connectionMgr.start();
var transport = new ScaleCubeDirectMarshallerTransport(connectionMgr.getLocalAddress(), messagingService, topologyService, messageFactory);
NodeFinder finder = NodeFinderFactory.createNodeFinder(configView.nodeFinder());
cluster = new ClusterImpl(clusterConfig(configView.membership())).handler(cl -> new ClusterMessageHandler() {
/**
* {@inheritDoc}
*/
@Override
public void onMembershipEvent(MembershipEvent event) {
topologyService.onMembershipEvent(event);
}
}).config(opts -> opts.memberAlias(consistentId)).transport(opts -> opts.transportFactory(transportConfig -> transport)).membership(opts -> opts.seedMembers(parseAddresses(finder.findNodes())));
shutdownFuture = cluster.onShutdown().toFuture();
// resolve cyclic dependencies
topologyService.setCluster(cluster);
messagingService.setConnectionManager(connectionMgr);
cluster.startAwait();
// emit an artificial event as if the local member has joined the topology (ScaleCube doesn't do that)
var localMembershipEvent = MembershipEvent.createAdded(cluster.member(), null, System.currentTimeMillis());
topologyService.onMembershipEvent(localMembershipEvent);
}
/**
* {@inheritDoc}
*/
@Override
public void stop() {
// local member will be null, if cluster has not been started
if (cluster.member() == null) {
return;
}
cluster.shutdown();
try {
shutdownFuture.get(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IgniteInternalException("Interrupted while waiting for the ClusterService to stop", e);
} catch (TimeoutException e) {
throw new IgniteInternalException("Timeout while waiting for the ClusterService to stop", e);
} catch (ExecutionException e) {
throw new IgniteInternalException("Unable to stop the ClusterService", e.getCause());
}
connectionMgr.stop();
// Messaging service checks connection manager's status before sending a message, so connection manager should be
// stopped before messaging service
messagingService.stop();
}
/**
* {@inheritDoc}
*/
@Override
public void beforeNodeStop() {
stop();
}
/**
* {@inheritDoc}
*/
@Override
public boolean isStopped() {
return shutdownFuture.isDone();
}
};
}
Aggregations