Search in sources :

Example 1 with Command

use of org.apache.activemq.command.Command 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 Command

use of org.apache.activemq.command.Command 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 Command

use of org.apache.activemq.command.Command in project activemq-artemis by apache.

the class QueueOptimizedDispatchExceptionTest method TestOptimizedDispatchCME.

@Test
public void TestOptimizedDispatchCME() throws Exception {
    final PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(destination);
    final ConnectionContext contextNotInTx = new ConnectionContext();
    contextNotInTx.setConnection(new Connection() {

        @Override
        public void stop() throws Exception {
        }

        @Override
        public void start() throws Exception {
        }

        @Override
        public void updateClient(ConnectionControl control) {
        }

        @Override
        public void serviceExceptionAsync(IOException e) {
        }

        @Override
        public void serviceException(Throwable error) {
        }

        @Override
        public Response service(Command command) {
            return null;
        }

        @Override
        public boolean isSlow() {
            return false;
        }

        @Override
        public boolean isNetworkConnection() {
            return false;
        }

        @Override
        public boolean isManageable() {
            return false;
        }

        @Override
        public boolean isFaultTolerantConnection() {
            return false;
        }

        @Override
        public boolean isConnected() {
            return true;
        }

        @Override
        public boolean isBlocked() {
            return false;
        }

        @Override
        public boolean isActive() {
            return false;
        }

        @Override
        public ConnectionStatistics getStatistics() {
            return null;
        }

        @Override
        public String getRemoteAddress() {
            return null;
        }

        @Override
        public int getDispatchQueueSize() {
            return 0;
        }

        @Override
        public Connector getConnector() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public String getConnectionId() {
            return null;
        }

        @Override
        public void dispatchSync(Command message) {
        }

        @Override
        public void dispatchAsync(Command command) {
        }

        @Override
        public int getActiveTransactionCount() {
            return 0;
        }

        @Override
        public Long getOldestActiveTransactionDuration() {
            return null;
        }
    });
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    final Queue queue = new Queue(broker, destination, queueMessageStore, destinationStatistics, broker.getTaskRunnerFactory());
    final MockMemoryUsage usage = new MockMemoryUsage();
    queue.setOptimizedDispatch(true);
    queue.initialize();
    queue.start();
    queue.memoryUsage = usage;
    ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
    ProducerInfo producerInfo = new ProducerInfo();
    ProducerState producerState = new ProducerState(producerInfo);
    producerExchange.setProducerState(producerState);
    producerExchange.setConnectionContext(contextNotInTx);
    // populate the queue store, exceed memory limit so that cache is disabled
    for (int i = 0; i < count; i++) {
        Message message = getMessage(i);
        queue.send(producerExchange, message);
    }
    usage.setFull(false);
    try {
        queue.wakeup();
    } catch (Exception e) {
        LOG.error("Queue threw an unexpected exception: " + e.toString());
        fail("Should not throw an exception.");
    }
}
Also used : MessageStore(org.apache.activemq.store.MessageStore) Connector(org.apache.activemq.broker.Connector) ProducerBrokerExchange(org.apache.activemq.broker.ProducerBrokerExchange) ProducerInfo(org.apache.activemq.command.ProducerInfo) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) Connection(org.apache.activemq.broker.Connection) IOException(java.io.IOException) IOException(java.io.IOException) Response(org.apache.activemq.command.Response) ConnectionControl(org.apache.activemq.command.ConnectionControl) Command(org.apache.activemq.command.Command) ProducerState(org.apache.activemq.state.ProducerState) ConnectionContext(org.apache.activemq.broker.ConnectionContext) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) Test(org.junit.Test)

Example 4 with Command

use of org.apache.activemq.command.Command in project activemq-artemis by apache.

the class UdpTestSupport method testSendingSmallMessage.

public void testSendingSmallMessage() throws Exception {
    ConsumerInfo expected = new ConsumerInfo();
    expected.setSelector("Cheese");
    expected.setExclusive(true);
    expected.setExclusive(true);
    expected.setPrefetchSize(3456);
    try {
        LOG.info("About to send: " + expected);
        producer.oneway(expected);
        Command received = assertCommandReceived();
        assertTrue("Should have received a ConsumerInfo but was: " + received, received instanceof ConsumerInfo);
        ConsumerInfo actual = (ConsumerInfo) received;
        assertEquals("Selector", expected.getSelector(), actual.getSelector());
        assertEquals("isExclusive", expected.isExclusive(), actual.isExclusive());
        assertEquals("getPrefetchSize", expected.getPrefetchSize(), actual.getPrefetchSize());
    } catch (Exception e) {
        LOG.info("Caught: " + e);
        e.printStackTrace();
        fail("Failed to send to transport: " + e);
    }
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Command(org.apache.activemq.command.Command) IOException(java.io.IOException) MessageNotWriteableException(javax.jms.MessageNotWriteableException)

Example 5 with Command

use of org.apache.activemq.command.Command in project activemq-artemis by apache.

the class UdpTestSupport method assertSendTextMessage.

protected void assertSendTextMessage(ActiveMQDestination destination, String text) throws MessageNotWriteableException {
    large = true;
    ActiveMQTextMessage expected = new ActiveMQTextMessage();
    expected.setText(text);
    expected.setDestination(destination);
    try {
        LOG.info("About to send message of type: " + expected.getClass());
        producer.oneway(expected);
        // lets send a dummy command to ensure things don't block if we
        // discard the last one
        // keepalive does not have a commandId...
        // producer.oneway(new KeepAliveInfo());
        producer.oneway(new ProducerInfo());
        producer.oneway(new ProducerInfo());
        Command received = assertCommandReceived();
        assertTrue("Should have received an ActiveMQTextMessage but was: " + received, received instanceof ActiveMQTextMessage);
        ActiveMQTextMessage actual = (ActiveMQTextMessage) received;
        assertEquals("getDestination", expected.getDestination(), actual.getDestination());
        assertEquals("getText", expected.getText(), actual.getText());
        LOG.info("Received text message with: " + actual.getText().length() + " character(s)");
    } catch (Exception e) {
        LOG.info("Caught: " + e);
        e.printStackTrace();
        fail("Failed to send to transport: " + e);
    }
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) Command(org.apache.activemq.command.Command) IOException(java.io.IOException) MessageNotWriteableException(javax.jms.MessageNotWriteableException) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Aggregations

Command (org.apache.activemq.command.Command)6 IOException (java.io.IOException)4 Response (org.apache.activemq.command.Response)3 MessageNotWriteableException (javax.jms.MessageNotWriteableException)2 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)2 ControlCommand (org.apache.activemq.command.ControlCommand)2 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)2 ExceptionResponse (org.apache.activemq.command.ExceptionResponse)2 FlushCommand (org.apache.activemq.command.FlushCommand)2 IntegerResponse (org.apache.activemq.command.IntegerResponse)2 ProducerInfo (org.apache.activemq.command.ProducerInfo)2 IllegalStateException (javax.jms.IllegalStateException)1 InvalidClientIDException (javax.jms.InvalidClientIDException)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 JMSSecurityException (javax.jms.JMSSecurityException)1 XAException (javax.transaction.xa.XAException)1 ActiveMQAddressExistsException (org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)1 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)1