Search in sources :

Example 1 with Response

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);
        }
    }
}
Also used : DataArrayResponse(org.apache.activemq.command.DataArrayResponse) Response(org.apache.activemq.command.Response) IntegerResponse(org.apache.activemq.command.IntegerResponse) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) ControlCommand(org.apache.activemq.command.ControlCommand) FlushCommand(org.apache.activemq.command.FlushCommand) Command(org.apache.activemq.command.Command)

Example 2 with Response

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();
    }
}
Also used : DataArrayResponse(org.apache.activemq.command.DataArrayResponse) Response(org.apache.activemq.command.Response) IntegerResponse(org.apache.activemq.command.IntegerResponse) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) ControlCommand(org.apache.activemq.command.ControlCommand) FlushCommand(org.apache.activemq.command.FlushCommand) Command(org.apache.activemq.command.Command) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQRemoteDisconnectException(org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException) IllegalStateException(javax.jms.IllegalStateException) XAException(javax.transaction.xa.XAException) InvalidDestinationException(javax.jms.InvalidDestinationException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) IOException(java.io.IOException) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) JMSSecurityException(javax.jms.JMSSecurityException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) InvalidClientIDException(javax.jms.InvalidClientIDException)

Example 3 with Response

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);
    }
}
Also used : Response(org.apache.activemq.command.Response) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) ExceptionResponse(org.apache.activemq.command.ExceptionResponse) Message(org.apache.activemq.command.Message)

Example 4 with Response

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);
}
Also used : Response(org.apache.activemq.command.Response)

Example 5 with Response

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;
}
Also used : Response(org.apache.activemq.command.Response)

Aggregations

Response (org.apache.activemq.command.Response)32 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)7 Message (org.apache.activemq.command.Message)7 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)6 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)5 ProducerInfo (org.apache.activemq.command.ProducerInfo)5 IOException (java.io.IOException)4 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 ExceptionResponse (org.apache.activemq.command.ExceptionResponse)4 SessionInfo (org.apache.activemq.command.SessionInfo)4 TransactionId (org.apache.activemq.command.TransactionId)4 TransactionInfo (org.apache.activemq.command.TransactionInfo)4 XATransactionId (org.apache.activemq.command.XATransactionId)4 Command (org.apache.activemq.command.Command)3 Test (org.junit.Test)3 InvalidDestinationException (javax.jms.InvalidDestinationException)2 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 ControlCommand (org.apache.activemq.command.ControlCommand)2 FlushCommand (org.apache.activemq.command.FlushCommand)2