Search in sources :

Example 1 with OperationResponseHandler

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;
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.Operation) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler)

Example 2 with OperationResponseHandler

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;
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) MapOperation(com.hazelcast.map.impl.operation.MapOperation) Operation(com.hazelcast.spi.Operation) RemoveFromLoadAllOperation(com.hazelcast.map.impl.operation.RemoveFromLoadAllOperation) MapOperationProvider(com.hazelcast.map.impl.operation.MapOperationProvider) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler) MapOperation(com.hazelcast.map.impl.operation.MapOperation)

Example 3 with OperationResponseHandler

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();
            }
        }
    }
}
Also used : BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException)

Example 4 with OperationResponseHandler

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);
    }
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) OperationService(com.hazelcast.spi.OperationService) Operation(com.hazelcast.spi.Operation) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler)

Example 5 with OperationResponseHandler

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();
}
Also used : HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) Address(com.hazelcast.nio.Address) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException)

Aggregations

OperationResponseHandler (com.hazelcast.spi.OperationResponseHandler)8 Operation (com.hazelcast.spi.Operation)6 NodeEngine (com.hazelcast.spi.NodeEngine)5 ILogger (com.hazelcast.logging.ILogger)2 BlockingOperation (com.hazelcast.spi.BlockingOperation)2 OperationService (com.hazelcast.spi.OperationService)2 PartitionMigratingException (com.hazelcast.spi.exception.PartitionMigratingException)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)1 MapOperation (com.hazelcast.map.impl.operation.MapOperation)1 MapOperationProvider (com.hazelcast.map.impl.operation.MapOperationProvider)1 RemoveFromLoadAllOperation (com.hazelcast.map.impl.operation.RemoveFromLoadAllOperation)1 Address (com.hazelcast.nio.Address)1 UrgentSystemOperation (com.hazelcast.spi.UrgentSystemOperation)1