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);
}
}
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;
}
}
}
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);
}
}
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());
}
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);
}
}
Aggregations