use of com.hazelcast.spi.OperationResponseHandler 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.OperationResponseHandler in project hazelcast by hazelcast.
the class BasicRecordStoreLoader method createOperation.
private Operation createOperation(List<Data> keyValueSequence, final AtomicInteger finishedBatchCounter) {
final NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
MapOperationProvider operationProvider = mapServiceContext.getMapOperationProvider(name);
MapOperation operation = operationProvider.createPutFromLoadAllOperation(name, keyValueSequence);
operation.setNodeEngine(nodeEngine);
operation.setOperationResponseHandler(new OperationResponseHandler() {
@Override
public void sendResponse(Operation op, Object obj) {
if (finishedBatchCounter.decrementAndGet() == 0) {
loaded.set(true);
}
}
});
operation.setPartitionId(partitionId);
OperationAccessor.setCallerAddress(operation, nodeEngine.getThisAddress());
operation.setCallerUuid(nodeEngine.getLocalMember().getUuid());
operation.setServiceName(MapService.SERVICE_NAME);
return operation;
}
use of com.hazelcast.spi.OperationResponseHandler in project hazelcast by hazelcast.
the class OperationParkerImpl method onPartitionMigrate.
// This is executed under partition migration lock!
public void onPartitionMigrate(Address thisAddress, MigrationInfo migrationInfo) {
if (!thisAddress.equals(migrationInfo.getSource())) {
return;
}
int partitionId = migrationInfo.getPartitionId();
for (Queue<ParkedOperation> parkQueue : parkQueueMap.values()) {
Iterator<ParkedOperation> it = parkQueue.iterator();
while (it.hasNext()) {
if (Thread.interrupted()) {
return;
}
ParkedOperation parkedOperation = it.next();
if (!parkedOperation.isValid()) {
continue;
}
Operation op = parkedOperation.getOperation();
if (partitionId == op.getPartitionId()) {
parkedOperation.setValid(false);
PartitionMigratingException pme = new PartitionMigratingException(thisAddress, partitionId, op.getClass().getName(), op.getServiceName());
OperationResponseHandler responseHandler = op.getOperationResponseHandler();
responseHandler.sendResponse(op, pme);
it.remove();
}
}
}
}
use of com.hazelcast.spi.OperationResponseHandler in project hazelcast by hazelcast.
the class PartitionIteratingOperation method executeOperations.
private void executeOperations() {
NodeEngine nodeEngine = getNodeEngine();
OperationResponseHandler responseHandler = new OperationResponseHandlerImpl(partitions);
OperationService operationService = nodeEngine.getOperationService();
Object service = getServiceName() == null ? null : getService();
for (int partitionId : partitions) {
Operation operation = operationFactory.createOperation().setNodeEngine(nodeEngine).setPartitionId(partitionId).setReplicaIndex(getReplicaIndex()).setOperationResponseHandler(responseHandler).setServiceName(getServiceName()).setService(service).setCallerUuid(extractCallerUuid());
OperationAccessor.setCallerAddress(operation, getCallerAddress());
operationService.execute(operation);
}
}
use of com.hazelcast.spi.OperationResponseHandler in project hazelcast by hazelcast.
the class OperationParkerImpl method shutdown.
public void shutdown() {
logger.finest("Stopping tasks...");
expirationTaskFuture.cancel(true);
expirationExecutor.shutdown();
final Object response = new HazelcastInstanceNotActiveException();
final Address thisAddress = nodeEngine.getThisAddress();
for (Queue<ParkedOperation> parkQueue : parkQueueMap.values()) {
for (ParkedOperation parkedOperation : parkQueue) {
if (!parkedOperation.isValid()) {
continue;
}
Operation op = parkedOperation.getOperation();
// only for local invocations, remote ones will be expired via #onMemberLeft()
if (thisAddress.equals(op.getCallerAddress())) {
try {
OperationResponseHandler responseHandler = op.getOperationResponseHandler();
responseHandler.sendResponse(op, response);
} catch (Exception e) {
logger.finest("While sending HazelcastInstanceNotActiveException response...", e);
}
}
}
parkQueue.clear();
}
parkQueueMap.clear();
}
Aggregations