public void connectionRemoved(Connection connection) { if (connection.isClient() && connection instanceof TcpIpConnection && nodeEngine.isActive()) { final ClientEndpoint endpoint = endpoints.get(connection); if (endpoint != null && node.getLocalMember().getUuid().equals(endpoint.getPrincipal().getOwnerUuid())) { removeEndpoint(connection, true); if (!endpoint.isFirstConnection()) { return; } NodeEngine nodeEngine = node.nodeEngine; final Collection<MemberImpl> memberList = nodeEngine.getClusterService().getMemberList(); for (MemberImpl member : memberList) { final ClientDisconnectionOperation op = new ClientDisconnectionOperation(endpoint.getUuid()); op.setNodeEngine(nodeEngine) .setServiceName(SERVICE_NAME) .setService(this) .setResponseHandler(ResponseHandlerFactory.createEmptyResponseHandler()); if (member.localMember()) { nodeEngine.getOperationService().runOperation(op); } else { nodeEngine.getOperationService().send(op, member.getAddress()); } } } } }
protected Set<Data> keySetInternal() { final NodeEngine nodeEngine = getNodeEngine(); try { Map<Integer, Object> results = nodeEngine .getOperationService() .invokeOnAllPartitions( CollectionService.SERVICE_NAME, new MultiMapOperationFactory(proxyId, OperationFactoryType.KEY_SET)); Set<Data> keySet = new HashSet<Data>(); for (Object result : results.values()) { if (result == null) { continue; } CollectionResponse response = nodeEngine.toObject(result); if (response.getCollection() != null) { keySet.addAll(response.getCollection()); } } return keySet; } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
public void invalidateAllNearCaches(String mapName, Set<Data> keys) { if (!isNearCacheEnabled(mapName)) { return; } if (keys == null || keys.isEmpty()) { return; } // send operation. Operation operation = new NearCacheKeySetInvalidationOperation(mapName, keys).setServiceName(SERVICE_NAME); Collection<MemberImpl> members = nodeEngine.getClusterService().getMemberList(); for (MemberImpl member : members) { try { if (member.localMember()) continue; nodeEngine.getOperationService().send(operation, member.getAddress()); } catch (Throwable throwable) { logger.warning(throwable); } } // below local invalidation is for the case the data is cached before partition is // owned/migrated for (final Data key : keys) { invalidateNearCache(mapName, key); } }
@Override public void onReplicationEvent(WanReplicationEvent replicationEvent) { Object eventObject = replicationEvent.getEventObject(); if (eventObject instanceof MapReplicationUpdate) { MapReplicationUpdate replicationUpdate = (MapReplicationUpdate) eventObject; EntryView entryView = replicationUpdate.getEntryView(); MapMergePolicy mergePolicy = replicationUpdate.getMergePolicy(); String mapName = replicationUpdate.getMapName(); MapContainer mapContainer = getMapContainer(mapName); MergeOperation operation = new MergeOperation( mapName, toData(entryView.getKey(), mapContainer.getPartitioningStrategy()), entryView, mergePolicy); try { int partitionId = nodeEngine.getPartitionService().getPartitionId(entryView.getKey()); Future f = nodeEngine .getOperationService() .invokeOnPartition(SERVICE_NAME, operation, partitionId); f.get(); } catch (Throwable t) { throw ExceptionUtil.rethrow(t); } } else if (eventObject instanceof MapReplicationRemove) { MapReplicationRemove replicationRemove = (MapReplicationRemove) eventObject; WanOriginatedDeleteOperation operation = new WanOriginatedDeleteOperation( replicationRemove.getMapName(), replicationRemove.getKey()); try { int partitionId = nodeEngine.getPartitionService().getPartitionId(replicationRemove.getKey()); Future f = nodeEngine .getOperationService() .invokeOnPartition(SERVICE_NAME, operation, partitionId); f.get(); } catch (Throwable t) { throw ExceptionUtil.rethrow(t); } } }
public void clear() { final NodeEngine nodeEngine = getNodeEngine(); try { nodeEngine .getOperationService() .invokeOnAllPartitions( CollectionService.SERVICE_NAME, new MultiMapOperationFactory(proxyId, OperationFactoryType.CLEAR)); } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
protected Map entrySetInternal() { final NodeEngine nodeEngine = getNodeEngine(); try { Map<Integer, Object> results = nodeEngine .getOperationService() .invokeOnAllPartitions( CollectionService.SERVICE_NAME, new MultiMapOperationFactory(proxyId, OperationFactoryType.ENTRY_SET)); return results; } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
protected <T> T invoke(CollectionOperation operation) { final NodeEngine nodeEngine = getNodeEngine(); try { Invocation inv = nodeEngine .getOperationService() .createInvocationBuilder(getServiceName(), operation, partitionId) .build(); Future f = inv.invoke(); return nodeEngine.toObject(f.get()); } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
private Object invokeData(CollectionOperation operation, Data dataKey) { final NodeEngine nodeEngine = getNodeEngine(); try { int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey); Invocation inv = nodeEngine .getOperationService() .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId) .build(); Future f = inv.invoke(); return nodeEngine.toObject(f.get()); } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
public void invalidateAllNearCaches(String mapName, Data key) { if (!isNearCacheEnabled(mapName)) { return; } Collection<MemberImpl> members = nodeEngine.getClusterService().getMemberList(); for (MemberImpl member : members) { try { if (member.localMember()) continue; Operation operation = new InvalidateNearCacheOperation(mapName, key).setServiceName(SERVICE_NAME); nodeEngine.getOperationService().send(operation, member.getAddress()); } catch (Throwable throwable) { throw new HazelcastException(throwable); } } // below local invalidation is for the case the data is cached before partition is // owned/migrated invalidateNearCache(mapName, key); }
public int size() { final NodeEngine nodeEngine = getNodeEngine(); try { Map<Integer, Object> results = nodeEngine .getOperationService() .invokeOnAllPartitions( CollectionService.SERVICE_NAME, new MultiMapOperationFactory(proxyId, OperationFactoryType.SIZE)); int size = 0; for (Object obj : results.values()) { if (obj == null) { continue; } Integer result = nodeEngine.toObject(obj); size += result; } return size; } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
@Override public void run() throws Exception { if (!valid) { return; } final NodeEngine nodeEngine = getNodeEngine(); final PartitionServiceImpl partitionService = (PartitionServiceImpl) nodeEngine.getPartitionService(); partitionService.updatePartitionReplicaVersions( getPartitionId(), replicaVersions, getReplicaIndex()); if (backupOp != null) { backupOp.setNodeEngine(nodeEngine); backupOp.setResponseHandler(ResponseHandlerFactory.createEmptyResponseHandler()); backupOp.setCallerUuid(getCallerUuid()); OperationAccessor.setCallerAddress(backupOp, getCallerAddress()); OperationAccessor.setInvocationTime(backupOp, Clock.currentTimeMillis()); final OperationService operationService = nodeEngine.getOperationService(); operationService.runOperation(backupOp); } }
private <T> T invoke(Operation operation, Data dataKey) { final NodeEngine nodeEngine = getNodeEngine(); try { int partitionId = nodeEngine.getPartitionService().getPartitionId(dataKey); Invocation invocation = nodeEngine .getOperationService() .createInvocationBuilder(CollectionService.SERVICE_NAME, operation, partitionId) .build(); Future f; Object o; if (config.isStatisticsEnabled()) { long time = System.currentTimeMillis(); f = invocation.invoke(); o = f.get(); if (operation instanceof PutOperation) { getService() .getLocalMultiMapStatsImpl(proxyId) .incrementPuts(System.currentTimeMillis() - time); } else if (operation instanceof RemoveOperation || operation instanceof RemoveAllOperation) { getService() .getLocalMultiMapStatsImpl(proxyId) .incrementRemoves(System.currentTimeMillis() - time); } else if (operation instanceof GetAllOperation) { getService() .getLocalMultiMapStatsImpl(proxyId) .incrementGets(System.currentTimeMillis() - time); } } else { f = invocation.invoke(); o = f.get(); } return (T) nodeEngine.toObject(o); } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }
protected boolean containsInternal(Data key, Data value) { final NodeEngine nodeEngine = getNodeEngine(); try { Map<Integer, Object> results = nodeEngine .getOperationService() .invokeOnAllPartitions( CollectionService.SERVICE_NAME, new MultiMapOperationFactory(proxyId, OperationFactoryType.CONTAINS, key, value)); for (Object obj : results.values()) { if (obj == null) { continue; } Boolean result = nodeEngine.toObject(obj); if (result) { return true; } } return false; } catch (Throwable throwable) { throw ExceptionUtil.rethrow(throwable); } }