public void clearInternal() { try { Operation clearOperation = operationProvider.createClearOperation(name); clearOperation.setServiceName(SERVICE_NAME); BinaryOperationFactory factory = new BinaryOperationFactory(clearOperation, getNodeEngine()); Map<Integer, Object> resultMap = operationService.invokeOnAllPartitions(SERVICE_NAME, factory); int numberOfAffectedEntries = 0; for (Object object : resultMap.values()) { numberOfAffectedEntries += (Integer) object; } MemberSelector selector = MemberSelectors.and(LITE_MEMBER_SELECTOR, NON_LOCAL_MEMBER_SELECTOR); for (Member member : getNodeEngine().getClusterService().getMembers(selector)) { operationService.invokeOnTarget( SERVICE_NAME, new ClearOperation(name), member.getAddress()); } if (numberOfAffectedEntries > 0) { publishMapEvent(numberOfAffectedEntries, EntryEventType.CLEAR_ALL); } } catch (Throwable t) { throw rethrow(t); } }
private void rollbackTxBackup() { final OperationService operationService = nodeEngine.getOperationService(); final List<Future> futures = new ArrayList<Future>(txLogs.size()); // rollback tx backup if (durability > 0 && transactionType.equals(TransactionType.TWO_PHASE)) { for (Address backupAddress : backupAddresses) { if (nodeEngine.getClusterService().getMember(backupAddress) != null) { final Future f = operationService.invokeOnTarget( TransactionManagerServiceImpl.SERVICE_NAME, new RollbackTxBackupOperation(txnId), backupAddress); futures.add(f); } } for (Future future : futures) { try { future.get(timeoutMillis, TimeUnit.MILLISECONDS); } catch (Throwable e) { nodeEngine.getLogger(getClass()).warning("Error during tx rollback backup!", e); } } futures.clear(); } }
@Override public Xid[] recover(int flag) throws XAException { NodeEngine nodeEngine = getNodeEngine(); XAService xaService = getService(); OperationService operationService = nodeEngine.getOperationService(); ClusterService clusterService = nodeEngine.getClusterService(); Collection<Member> memberList = clusterService.getMembers(); List<InternalCompletableFuture<SerializableList>> futureList = new ArrayList<InternalCompletableFuture<SerializableList>>(); for (Member member : memberList) { if (member.localMember()) { continue; } CollectRemoteTransactionsOperation op = new CollectRemoteTransactionsOperation(); Address address = member.getAddress(); InternalCompletableFuture<SerializableList> future = operationService.invokeOnTarget(SERVICE_NAME, op, address); futureList.add(future); } HashSet<SerializableXID> xids = new HashSet<SerializableXID>(); xids.addAll(xaService.getPreparedXids()); for (InternalCompletableFuture<SerializableList> future : futureList) { SerializableList xidSet = future.getSafely(); for (Data xidData : xidSet) { SerializableXID xid = nodeEngine.toObject(xidData); xids.add(xid); } } return xids.toArray(new SerializableXID[xids.size()]); }
@Override public Future invokeOnTarget(Object operation, Address address) { checkNotNull(operation, "operation cannot be null"); checkNotNull(address, "address cannot be null"); Operation op = (Operation) operation; return operationService.invokeOnTarget(MapService.SERVICE_NAME, op, address); }
protected void destroyCacheOnAllMembers(String name, String callerUuid) { final OperationService operationService = nodeEngine.getOperationService(); final Collection<Member> members = nodeEngine.getClusterService().getMembers(); for (Member member : members) { if (!member.localMember() && !member.getUuid().equals(callerUuid)) { final CacheDestroyOperation op = new CacheDestroyOperation(name, true); operationService.invokeOnTarget(AbstractCacheService.SERVICE_NAME, op, member.getAddress()); } } }
@Override public Map<ClientType, Integer> getConnectedClientStats() { int numberOfCppClients = 0; int numberOfDotNetClients = 0; int numberOfJavaClients = 0; int numberOfOtherClients = 0; Operation clientInfoOperation = new GetConnectedClientsOperation(); OperationService operationService = node.nodeEngine.getOperationService(); Map<ClientType, Integer> resultMap = new HashMap<ClientType, Integer>(); Map<String, ClientType> clientsMap = new HashMap<String, ClientType>(); for (Member member : node.getClusterService().getMembers()) { Address target = member.getAddress(); Future<Map<String, ClientType>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target); try { Map<String, ClientType> endpoints = future.get(); if (endpoints == null) { continue; } // Merge connected clients according to their uuid. for (Map.Entry<String, ClientType> entry : endpoints.entrySet()) { clientsMap.put(entry.getKey(), entry.getValue()); } } catch (Exception e) { logger.warning("Cannot get client information from: " + target.toString(), e); } } // Now we are regrouping according to the client type for (ClientType clientType : clientsMap.values()) { switch (clientType) { case JAVA: numberOfJavaClients++; break; case CSHARP: numberOfDotNetClients++; break; case CPP: numberOfCppClients++; break; default: numberOfOtherClients++; } } resultMap.put(ClientType.CPP, numberOfCppClients); resultMap.put(ClientType.CSHARP, numberOfDotNetClients); resultMap.put(ClientType.JAVA, numberOfJavaClients); resultMap.put(ClientType.OTHER, numberOfOtherClients); return resultMap; }
private List<Future> startTxBackup() { final OperationService operationService = nodeEngine.getOperationService(); List<Future> futures = new ArrayList<Future>(backupAddresses.length); for (Address backupAddress : backupAddresses) { if (nodeEngine.getClusterService().getMember(backupAddress) != null) { final Future f = operationService.invokeOnTarget( TransactionManagerServiceImpl.SERVICE_NAME, new BeginTxBackupOperation(txOwnerUuid, txnId, xid), backupAddress); futures.add(f); } } return futures; }
private void purgeTxBackups() { if (durability > 0 && transactionType.equals(TransactionType.TWO_PHASE)) { final OperationService operationService = nodeEngine.getOperationService(); for (Address backupAddress : backupAddresses) { if (nodeEngine.getClusterService().getMember(backupAddress) != null) { try { operationService.invokeOnTarget( TransactionManagerServiceImpl.SERVICE_NAME, new PurgeTxBackupOperation(txnId), backupAddress); } catch (Throwable e) { nodeEngine.getLogger(getClass()).warning("Error during purging backups!", e); } } } } }
public void removeMapInterceptorInternal(String id) { NodeEngine nodeEngine = getNodeEngine(); mapServiceContext.removeInterceptor(name, id); Collection<Member> members = nodeEngine.getClusterService().getMembers(); for (Member member : members) { try { if (member.localMember()) { continue; } RemoveInterceptorOperation op = new RemoveInterceptorOperation(name, id); Future future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress()); future.get(); } catch (Throwable t) { throw rethrow(t); } } }
private void replicateTxnLog() throws InterruptedException, ExecutionException, java.util.concurrent.TimeoutException { final List<Future> futures = new ArrayList<Future>(txLogs.size()); final OperationService operationService = nodeEngine.getOperationService(); for (Address backupAddress : backupAddresses) { if (nodeEngine.getClusterService().getMember(backupAddress) != null) { final Future f = operationService.invokeOnTarget( TransactionManagerServiceImpl.SERVICE_NAME, new ReplicateTxOperation(txLogs, txOwnerUuid, txnId, timeoutMillis, startTime), backupAddress); futures.add(f); } } for (Future future : futures) { future.get(timeoutMillis, TimeUnit.MILLISECONDS); } futures.clear(); }
public String addMapInterceptorInternal(MapInterceptor interceptor) { NodeEngine nodeEngine = getNodeEngine(); if (interceptor instanceof HazelcastInstanceAware) { ((HazelcastInstanceAware) interceptor) .setHazelcastInstance(nodeEngine.getHazelcastInstance()); } String id = mapServiceContext.generateInterceptorId(name, interceptor); Collection<Member> members = nodeEngine.getClusterService().getMembers(); for (Member member : members) { try { AddInterceptorOperation op = new AddInterceptorOperation(id, interceptor, name); Future future = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress()); future.get(); } catch (Throwable t) { throw rethrow(t); } } return id; }
protected void startClusterMerge(final Address targetAddress) { ClusterServiceImpl clusterService = node.clusterService; if (!prepareClusterState(clusterService)) { return; } OperationService operationService = node.nodeEngine.getOperationService(); Collection<Member> memberList = clusterService.getMembers(); for (Member member : memberList) { if (!member.localMember()) { Operation op = new MergeClustersOperation(targetAddress); operationService.invokeOnTarget(ClusterServiceImpl.SERVICE_NAME, op, member.getAddress()); } } Operation mergeClustersOperation = new MergeClustersOperation(targetAddress); mergeClustersOperation .setNodeEngine(node.nodeEngine) .setService(clusterService) .setOperationResponseHandler(createEmptyResponseHandler()); operationService.runOperationOnCallingThread(mergeClustersOperation); }