use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class OpenWireConnection method disconnect.
private void disconnect(ActiveMQException me, String reason, boolean fail) {
if (context == null || destroyed) {
return;
}
// Don't allow things to be added to the connection state while we
// are shutting down.
// is it necessary? even, do we need state at all?
state.shutdown();
// Then call the listeners
// this should closes underlying sessions
callFailureListeners(me);
// this should clean up temp dests
callClosingListeners();
destroyed = true;
// before closing transport, sendCommand the last response if any
Command command = context.getLastCommand();
if (command != null && command.isResponseRequired()) {
Response lastResponse = new Response();
lastResponse.setCorrelationId(command.getCommandId());
try {
dispatchSync(lastResponse);
} catch (Throwable e) {
ActiveMQServerLogger.LOGGER.warn(e.getMessage(), e);
}
}
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class OpenWireConnection method bufferReceived.
@Override
public void bufferReceived(Object connectionID, ActiveMQBuffer buffer) {
super.bufferReceived(connectionID, buffer);
try {
recoverOperationContext();
Command command = (Command) inWireFormat.unmarshal(buffer);
// log the openwire command
if (logger.isTraceEnabled()) {
traceBufferReceived(connectionID, command);
}
boolean responseRequired = command.isResponseRequired();
int commandId = command.getCommandId();
// ignore pings
if (command.getClass() != KeepAliveInfo.class) {
Response response = null;
try {
setLastCommand(command);
response = command.visit(commandProcessorInstance);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.warn("Errors occurred during the buffering operation ", e);
if (responseRequired) {
response = convertException(e);
}
} finally {
setLastCommand(null);
}
if (response instanceof ExceptionResponse) {
Throwable cause = ((ExceptionResponse) response).getException();
if (!responseRequired) {
serviceException(cause);
response = null;
}
// stop the connection to prevent dangling sockets
if (command instanceof ConnectionInfo) {
delayedStop(2000, cause.getMessage(), cause);
}
}
if (responseRequired) {
if (response == null) {
response = new Response();
response.setCorrelationId(commandId);
}
}
// sent.
if (context != null) {
if (context.isDontSendReponse()) {
context.setDontSendReponse(false);
response = null;
}
}
sendAsyncResponse(commandId, response);
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.debug(e);
sendException(e);
} finally {
clearupOperationContext();
}
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class StubConnection method send.
public void send(Command command) throws Exception {
if (command instanceof Message) {
Message message = (Message) command;
message.setProducerId(message.getMessageId().getProducerId());
}
command.setResponseRequired(false);
if (connection != null) {
Response response = connection.service(command);
if (response != null && response.isException()) {
ExceptionResponse er = (ExceptionResponse) response;
throw JMSExceptionSupport.create(er.getException());
}
} else if (transport != null) {
transport.oneway(command);
}
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class ResponseTest method populateObject.
@Override
protected void populateObject(Object object) throws Exception {
super.populateObject(object);
Response info = (Response) object;
info.setCorrelationId(1);
}
use of org.apache.activemq.command.Response in project activemq-artemis by apache.
the class ResponseTest method createObject.
@Override
public Object createObject() throws Exception {
Response info = new Response();
populateObject(info);
return info;
}
Aggregations