use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class OperationBackupHandler method checkServiceNamespaces.
private void checkServiceNamespaces(BackupAwareOperation backupAwareOp, Operation backupOp) {
Operation op = (Operation) backupAwareOp;
Object service;
try {
service = op.getService();
} catch (Exception ignored) {
// operation doesn't know its service name
return;
}
if (service instanceof FragmentedMigrationAwareService) {
assert backupAwareOp instanceof ServiceNamespaceAware : service + " is instance of FragmentedMigrationAwareService, " + backupAwareOp + " should implement ServiceNamespaceAware!";
assert backupOp instanceof ServiceNamespaceAware : service + " is instance of FragmentedMigrationAwareService, " + backupOp + " should implement ServiceNamespaceAware!";
} else {
assert !(backupAwareOp instanceof ServiceNamespaceAware) : service + " is NOT instance of FragmentedMigrationAwareService, " + backupAwareOp + " should NOT implement ServiceNamespaceAware!";
assert !(backupOp instanceof ServiceNamespaceAware) : service + " is NOT instance of FragmentedMigrationAwareService, " + backupOp + " should NOT implement ServiceNamespaceAware!";
}
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class OperationBackupHandler method sendSingleBackup.
private int sendSingleBackup(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int replica) {
Operation backupOp = getBackupOperation(backupAwareOp);
PartitionReplica target = partition.getReplica(replica);
if (target != null) {
if (skipSendingBackupToTarget(partition, target)) {
return 0;
}
// without any unnecessary memory allocation and copy when it is used as object inside `Backup`.
if (backupOp instanceof TargetAware) {
((TargetAware) backupOp).setTarget(target.address());
}
boolean isSyncBackup = syncBackups == 1;
Backup backup = newBackup(backupAwareOp, backupOp, replicaVersions, 1, isSyncBackup);
outboundOperationHandler.send(backup, target.address());
if (isSyncBackup) {
return 1;
}
}
return 0;
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class OperationRunnerImpl method run.
@Override
public boolean run(Packet packet) throws Exception {
long startNanos = System.nanoTime();
boolean publishCurrentTask = publishCurrentTask();
if (publishCurrentTask) {
currentTask = packet;
}
ServerConnection connection = packet.getConn();
Address caller = connection.getRemoteAddress();
UUID callerUuid = connection.getRemoteUuid();
Operation op = null;
try {
Object object = nodeEngine.toObject(packet);
op = (Operation) object;
op.setNodeEngine(nodeEngine);
setCallerAddress(op, caller);
setConnection(op, connection);
setCallerUuidIfNotSet(op, callerUuid);
setOperationResponseHandler(op);
if (!ensureValidMember(op)) {
return false;
}
if (publishCurrentTask) {
currentTask = null;
}
return run(op, startNanos);
} catch (Throwable throwable) {
// If exception happens we need to extract the callId from the bytes directly!
long callId = extractOperationCallId(packet);
outboundResponseHandler.send(connection.getConnectionManager(), caller, new ErrorResponse(throwable, callId, packet.isUrgent()));
logOperationDeserializationException(throwable, callId);
throw ExceptionUtil.rethrow(throwable);
} finally {
if (op != null) {
op.clearThreadContext();
}
if (publishCurrentTask) {
currentTask = null;
}
}
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class CacheProxySupport method replaceAsyncInternal.
protected <T> InvocationFuture<T> replaceAsyncInternal(K key, V oldValue, V newValue, ExpiryPolicy expiryPolicy, boolean hasOldValue, boolean isGet, boolean withCompletionEvent) {
ensureOpen();
if (hasOldValue) {
validateNotNull(key, oldValue, newValue);
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, oldValue, newValue);
} else {
validateNotNull(key, newValue);
CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, newValue);
}
Data keyData = serializationService.toData(key);
Data oldValueData = serializationService.toData(oldValue);
Data newValueData = serializationService.toData(newValue);
Operation operation;
if (isGet) {
operation = operationProvider.createGetAndReplaceOperation(keyData, newValueData, expiryPolicy, IGNORE_COMPLETION);
} else {
operation = operationProvider.createReplaceOperation(keyData, oldValueData, newValueData, expiryPolicy, IGNORE_COMPLETION);
}
return invoke(operation, keyData, withCompletionEvent);
}
use of com.hazelcast.spi.impl.operationservice.Operation in project hazelcast by hazelcast.
the class ClientEngineImpl method getClientsInCluster.
Map<UUID, String> getClientsInCluster() {
OperationService operationService = node.nodeEngine.getOperationService();
Map<UUID, String> clientsMap = new HashMap<>();
for (Member member : node.getClusterService().getMembers()) {
Address target = member.getAddress();
Operation clientInfoOperation = new GetConnectedClientsOperation();
Future<Map<UUID, String>> future = operationService.invokeOnTarget(SERVICE_NAME, clientInfoOperation, target);
try {
Map<UUID, String> endpoints = future.get();
if (endpoints == null) {
continue;
}
// Merge connected clients according to their UUID
clientsMap.putAll(endpoints);
} catch (Exception e) {
logger.warning("Cannot get client information from: " + target.toString(), e);
}
}
return clientsMap;
}
Aggregations