Search in sources :

Example 1 with ErrorResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse in project hazelcast by hazelcast.

the class InboundResponseHandler method handle.

@Override
public void handle(Packet packet) throws Exception {
    Response response = serializationService.toObject(packet);
    Address sender = packet.getConn().getEndPoint();
    try {
        if (response instanceof NormalResponse) {
            NormalResponse normalResponse = (NormalResponse) response;
            notifyNormalResponse(normalResponse.getCallId(), normalResponse.getValue(), normalResponse.getBackupAcks(), sender);
        } else if (response instanceof BackupAckResponse) {
            notifyBackupComplete(response.getCallId());
        } else if (response instanceof CallTimeoutResponse) {
            notifyCallTimeout(response.getCallId(), sender);
        } else if (response instanceof ErrorResponse) {
            ErrorResponse errorResponse = (ErrorResponse) response;
            notifyErrorResponse(errorResponse.getCallId(), errorResponse.getCause(), sender);
        } else {
            logger.severe("Unrecognized response: " + response);
        }
    } catch (Throwable e) {
        logger.severe("While processing response...", e);
    }
}
Also used : CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Response(com.hazelcast.spi.impl.operationservice.impl.responses.Response) BackupAckResponse(com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) BackupAckResponse(com.hazelcast.spi.impl.operationservice.impl.responses.BackupAckResponse) Address(com.hazelcast.nio.Address) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 2 with ErrorResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse 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;
        }
    }
}
Also used : Address(com.hazelcast.cluster.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress) ServerConnection(com.hazelcast.internal.server.ServerConnection) Operations.isJoinOperation(com.hazelcast.spi.impl.operationservice.Operations.isJoinOperation) ReadonlyOperation(com.hazelcast.spi.impl.operationservice.ReadonlyOperation) BlockingOperation(com.hazelcast.spi.impl.operationservice.BlockingOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) Operations.isMigrationOperation(com.hazelcast.spi.impl.operationservice.Operations.isMigrationOperation) PartitionIteratingOperation(com.hazelcast.spi.impl.operationservice.impl.operations.PartitionIteratingOperation) Operations.isWanReplicationOperation(com.hazelcast.spi.impl.operationservice.Operations.isWanReplicationOperation) UUID(java.util.UUID) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 3 with ErrorResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse in project hazelcast by hazelcast.

the class InboundResponseHandler method accept.

@Override
public void accept(Packet packet) {
    checkNotNull(packet, "packet can't be null");
    checkTrue(packet.getPacketType() == OPERATION, "Packet type is not OPERATION");
    checkTrue(packet.isFlagRaised(FLAG_OP_RESPONSE), "FLAG_OP_RESPONSE is not set");
    byte[] bytes = packet.toByteArray();
    int typeId = Bits.readInt(bytes, OFFSET_TYPE_ID, useBigEndian);
    long callId = Bits.readLong(bytes, OFFSET_CALL_ID, useBigEndian);
    Address sender = packet.getConn().getRemoteAddress();
    try {
        switch(typeId) {
            case NORMAL_RESPONSE:
                byte backupAcks = bytes[OFFSET_BACKUP_ACKS];
                notifyNormalResponse(callId, packet, backupAcks, sender);
                break;
            case BACKUP_ACK_RESPONSE:
                notifyBackupComplete(callId);
                break;
            case CALL_TIMEOUT_RESPONSE:
                notifyCallTimeout(callId, sender);
                break;
            case ERROR_RESPONSE:
                ErrorResponse errorResponse = serializationService.toObject(packet);
                notifyErrorResponse(callId, errorResponse.getCause(), sender);
                break;
            default:
                logger.severe("Unrecognized type: " + typeId + " packet:" + packet);
        }
    } catch (Throwable e) {
        logger.severe("While processing response...", e);
    }
}
Also used : Address(com.hazelcast.cluster.Address) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 4 with ErrorResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse in project hazelcast by hazelcast.

the class OutboundResponseHandlerTest method sendResponse_whenErrorResponse.

@Test
public void sendResponse_whenErrorResponse() {
    ErrorResponse response = new ErrorResponse(new Exception(), 10, false);
    Operation op = createDummyOperation(10);
    ArgumentCaptor<Packet> argument = ArgumentCaptor.forClass(Packet.class);
    when(connectionManager.transmit(argument.capture(), eq(thatAddress), anyInt())).thenReturn(true);
    // make the call
    handler.sendResponse(op, response);
    // verify that the right object was send
    assertEquals(serializationService.toData(response), argument.getValue());
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Operation(com.hazelcast.spi.impl.operationservice.Operation) IOException(java.io.IOException) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with ErrorResponse

use of com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse in project hazelcast by hazelcast.

the class OutboundResponseHandler method sendResponse.

@Override
public void sendResponse(Operation operation, Object obj) {
    Address target = operation.getCallerAddress();
    ServerConnectionManager connectionManager = operation.getConnection().getConnectionManager();
    boolean send;
    if (obj == null) {
        send = sendNormalResponse(connectionManager, target, operation.getCallId(), 0, operation.isUrgent(), null);
    } else if (obj.getClass() == NormalResponse.class) {
        NormalResponse response = (NormalResponse) obj;
        send = sendNormalResponse(connectionManager, target, response.getCallId(), response.getBackupAcks(), response.isUrgent(), response.getValue());
    } else if (obj.getClass() == ErrorResponse.class || obj.getClass() == CallTimeoutResponse.class) {
        send = send(connectionManager, target, (Response) obj);
    } else if (obj instanceof Throwable) {
        send = send(connectionManager, target, new ErrorResponse((Throwable) obj, operation.getCallId(), operation.isUrgent()));
    } else {
        // most regular responses not wrapped in a NormalResponse. So we are now completely skipping the
        // NormalResponse instance
        send = sendNormalResponse(connectionManager, target, operation.getCallId(), 0, operation.isUrgent(), obj);
    }
    if (!send) {
        logger.warning("Cannot send response: " + obj + " to " + target + ". " + operation);
    }
}
Also used : ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Response(com.hazelcast.spi.impl.operationservice.impl.responses.Response) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Address(com.hazelcast.cluster.Address) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Aggregations

ErrorResponse (com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)8 Address (com.hazelcast.cluster.Address)3 Operation (com.hazelcast.spi.impl.operationservice.Operation)3 CallTimeoutResponse (com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse)3 NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)3 Packet (com.hazelcast.internal.nio.Packet)2 Response (com.hazelcast.spi.impl.operationservice.impl.responses.Response)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 ServerConnection (com.hazelcast.internal.server.ServerConnection)1 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)1 Address (com.hazelcast.nio.Address)1 ResponseAlreadySentException (com.hazelcast.spi.exception.ResponseAlreadySentException)1 BlockingOperation (com.hazelcast.spi.impl.operationservice.BlockingOperation)1 OperationAccessor.setCallerAddress (com.hazelcast.spi.impl.operationservice.OperationAccessor.setCallerAddress)1 Operations.isJoinOperation (com.hazelcast.spi.impl.operationservice.Operations.isJoinOperation)1 Operations.isMigrationOperation (com.hazelcast.spi.impl.operationservice.Operations.isMigrationOperation)1 Operations.isWanReplicationOperation (com.hazelcast.spi.impl.operationservice.Operations.isWanReplicationOperation)1