use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class AbstractJoiner method startClusterMerge.
protected void startClusterMerge(final Address targetAddress) {
ClusterServiceImpl clusterService = node.clusterService;
if (!prepareClusterState(clusterService)) {
return;
}
OperationService operationService = node.nodeEngine.getOperationService();
Collection<Member> memberList = clusterService.getMembers();
Collection<Future> futures = new ArrayList<Future>(memberList.size());
for (Member member : memberList) {
if (!member.localMember()) {
Operation op = new MergeClustersOperation(targetAddress);
Future<Object> future = operationService.invokeOnTarget(ClusterServiceImpl.SERVICE_NAME, op, member.getAddress());
futures.add(future);
}
}
waitWithDeadline(futures, SPLIT_BRAIN_MERGE_TIMEOUT_SECONDS, TimeUnit.SECONDS, splitBrainMergeExceptionHandler);
Operation mergeClustersOperation = new MergeClustersOperation(targetAddress);
mergeClustersOperation.setNodeEngine(node.nodeEngine).setService(clusterService).setOperationResponseHandler(createEmptyResponseHandler());
operationService.run(mergeClustersOperation);
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class ClusterJoinManager method checkIfJoinRequestFromAnExistingMember.
private boolean checkIfJoinRequestFromAnExistingMember(JoinMessage joinMessage, Connection connection) {
Address target = joinMessage.getAddress();
MemberImpl member = clusterService.getMember(target);
if (member == null) {
return checkIfUsingAnExistingMemberUuid(joinMessage);
}
if (joinMessage.getUuid().equals(member.getUuid())) {
sendMasterAnswer(target);
if (node.isMaster()) {
if (logger.isFineEnabled()) {
logger.fine(format("Ignoring join request, member already exists: %s", joinMessage));
}
// send members update back to node trying to join again...
Operation[] postJoinOps = nodeEngine.getPostJoinOperations();
boolean isPostJoinOperation = postJoinOps != null && postJoinOps.length > 0;
PostJoinOperation postJoinOp = isPostJoinOperation ? new PostJoinOperation(postJoinOps) : null;
PartitionRuntimeState partitionRuntimeState = node.getPartitionService().createPartitionState();
List<MemberInfo> memberInfos = createMemberInfoList(clusterService.getMemberImpls());
Operation operation = new FinalizeJoinOperation(member.getUuid(), memberInfos, postJoinOp, clusterClock.getClusterTime(), clusterService.getClusterId(), clusterClock.getClusterStartTime(), clusterStateManager.getState(), clusterService.getClusterVersion(), partitionRuntimeState, false);
nodeEngine.getOperationService().send(operation, target);
}
return true;
}
// and wants to join back, so drop old member and process join request if this node becomes master
if (node.isMaster() || target.equals(node.getMasterAddress())) {
String msg = format("New join request has been received from an existing endpoint %s." + " Removing old member and processing join request...", member);
logger.warning(msg);
clusterService.doRemoveAddress(target, msg, false);
Connection existing = node.connectionManager.getConnection(target);
if (existing != connection) {
if (existing != null) {
existing.close(msg, null);
}
node.connectionManager.registerConnection(target, connection);
}
return false;
}
return true;
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class ClusterServiceImpl method shutdownNodes.
private void shutdownNodes() {
final Operation op = new ShutdownNodeOperation();
logger.info("Sending shutting down operations to all members...");
Collection<Member> members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
final long timeout = node.getProperties().getNanos(GroupProperty.CLUSTER_SHUTDOWN_TIMEOUT_SECONDS);
final long startTime = System.nanoTime();
while ((System.nanoTime() - startTime) < timeout && !members.isEmpty()) {
for (Member member : members) {
nodeEngine.getOperationService().send(op, member.getAddress());
}
try {
Thread.sleep(CLUSTER_SHUTDOWN_SLEEP_DURATION_IN_MILLIS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
logger.warning("Shutdown sleep interrupted. ", e);
break;
}
members = getMembers(NON_LOCAL_MEMBER_SELECTOR);
}
logger.info("Number of other nodes remaining: " + getSize(NON_LOCAL_MEMBER_SELECTOR) + ". Shutting down itself.");
final HazelcastInstanceImpl hazelcastInstance = node.hazelcastInstance;
hazelcastInstance.getLifecycleService().shutdown();
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class PostJoinOperation method beforeRun.
@Override
public void beforeRun() throws Exception {
if (operations != null && operations.length > 0) {
final NodeEngine nodeEngine = getNodeEngine();
final int len = operations.length;
for (int i = 0; i < len; i++) {
final Operation op = operations[i];
op.setNodeEngine(nodeEngine);
op.setOperationResponseHandler(new OperationResponseHandler() {
@Override
public void sendResponse(Operation op, Object obj) {
if (obj instanceof Throwable) {
Throwable t = (Throwable) obj;
ILogger logger = nodeEngine.getLogger(op.getClass());
logger.warning("Error while running post-join operation: " + t.getClass().getSimpleName() + ": " + t.getMessage());
if (logger.isFineEnabled()) {
logger.fine("Error while running post-join operation: ", t);
}
}
}
});
OperationAccessor.setCallerAddress(op, getCallerAddress());
OperationAccessor.setConnection(op, getConnection());
operations[i] = op;
}
}
}
use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.
the class PostJoinOperation method writeInternal.
@Override
protected void writeInternal(final ObjectDataOutput out) throws IOException {
final int len = operations != null ? operations.length : 0;
out.writeInt(len);
if (len > 0) {
for (Operation op : operations) {
out.writeObject(op);
}
}
}
Aggregations