Search in sources :

Example 26 with Operation

use of com.hazelcast.spi.Operation 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 27 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class PostJoinOperation method writeInternal.

@Override
protected void writeInternal(final ObjectDataOutput out) throws IOException {
    final int len = operations != null ? operations.length : 0;
    out.writeInt(len);
    if (len > 0) {
        for (Operation op : operations) {
            out.writeObject(op);
        }
    }
}
Also used : Operation(com.hazelcast.spi.Operation) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation)

Example 28 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class PartitionServiceProxy method isClusterSafe.

@Override
public boolean isClusterSafe() {
    Collection<Member> members = nodeEngine.getClusterService().getMembers();
    if (members == null || members.isEmpty()) {
        return true;
    }
    final Collection<Future<Boolean>> futures = new ArrayList<Future<Boolean>>(members.size());
    for (Member member : members) {
        final Address target = member.getAddress();
        final Operation operation = new SafeStateCheckOperation();
        final Future<Boolean> future = nodeEngine.getOperationService().invokeOnTarget(InternalPartitionService.SERVICE_NAME, operation, target);
        futures.add(future);
    }
    // todo this max wait is appropriate?
    final int maxWaitTime = getMaxWaitTime();
    Collection<Boolean> results = FutureUtil.returnWithDeadline(futures, maxWaitTime, TimeUnit.SECONDS, exceptionHandler);
    if (results.size() != futures.size()) {
        return false;
    }
    for (Boolean result : results) {
        if (!result) {
            return false;
        }
    }
    return true;
}
Also used : Address(com.hazelcast.nio.Address) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) ArrayList(java.util.ArrayList) InternalCompletableFuture(com.hazelcast.spi.InternalCompletableFuture) Future(java.util.concurrent.Future) Operation(com.hazelcast.spi.Operation) SafeStateCheckOperation(com.hazelcast.internal.partition.operation.SafeStateCheckOperation) Member(com.hazelcast.core.Member)

Example 29 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class ReplicaSyncResponse method nodeNotOwnsBackup.

/** Fail all replication operations with the exception that this node is no longer the replica with the sent index */
private void nodeNotOwnsBackup(InternalPartitionImpl partition) {
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    Address thisAddress = getNodeEngine().getThisAddress();
    int currentReplicaIndex = partition.getReplicaIndex(thisAddress);
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        logger.finest("This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + " anymore. current replicaIndex=" + currentReplicaIndex);
    }
    if (tasks != null) {
        Throwable throwable = new WrongTargetException(thisAddress, partition.getReplicaAddress(replicaIndex), partitionId, replicaIndex, getClass().getName());
        for (Operation op : tasks) {
            prepareOperation(op);
            onOperationFailure(op, throwable);
        }
    }
}
Also used : Address(com.hazelcast.nio.Address) ILogger(com.hazelcast.logging.ILogger) UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) PartitionAwareOperation(com.hazelcast.spi.PartitionAwareOperation) Operation(com.hazelcast.spi.Operation) BackupOperation(com.hazelcast.spi.BackupOperation) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException)

Example 30 with Operation

use of com.hazelcast.spi.Operation in project hazelcast by hazelcast.

the class ReplicaSyncResponse method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    replicaVersions = in.readLongArray();
    int size = in.readInt();
    if (size > 0) {
        tasks = new ArrayList<Operation>(size);
        for (int i = 0; i < size; i++) {
            Operation op = in.readObject();
            tasks.add(op);
        }
    }
}
Also used : UrgentSystemOperation(com.hazelcast.spi.UrgentSystemOperation) PartitionAwareOperation(com.hazelcast.spi.PartitionAwareOperation) Operation(com.hazelcast.spi.Operation) BackupOperation(com.hazelcast.spi.BackupOperation)

Aggregations

Operation (com.hazelcast.spi.Operation)216 QuickTest (com.hazelcast.test.annotation.QuickTest)60 Test (org.junit.Test)60 OperationService (com.hazelcast.spi.OperationService)39 ParallelTest (com.hazelcast.test.annotation.ParallelTest)39 Future (java.util.concurrent.Future)19 Member (com.hazelcast.core.Member)18 Address (com.hazelcast.nio.Address)18 Data (com.hazelcast.nio.serialization.Data)18 HazelcastInstance (com.hazelcast.core.HazelcastInstance)17 AssertTask (com.hazelcast.test.AssertTask)17 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)15 ArrayList (java.util.ArrayList)15 InternalCompletableFuture (com.hazelcast.spi.InternalCompletableFuture)14 NodeEngine (com.hazelcast.spi.NodeEngine)14 BackupAwareOperation (com.hazelcast.spi.BackupAwareOperation)13 BlockingOperation (com.hazelcast.spi.BlockingOperation)13 MapOperation (com.hazelcast.map.impl.operation.MapOperation)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 Config (com.hazelcast.config.Config)10