Search in sources :

Example 1 with ConnectionInfo

use of org.apache.activemq.command.ConnectionInfo 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 2 with ConnectionInfo

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

the class OpenWireProtocolManager method addConnection.

public void addConnection(OpenWireConnection connection, ConnectionInfo info) throws Exception {
    String username = info.getUserName();
    String password = info.getPassword();
    try {
        validateUser(username, password, connection);
    } catch (ActiveMQSecurityException e) {
        // We need to send an exception used by the openwire
        SecurityException ex = new SecurityException("User name [" + username + "] or password is invalid.");
        ex.initCause(e);
        throw ex;
    }
    String clientId = info.getClientId();
    if (clientId == null) {
        throw new InvalidClientIDException("No clientID specified for connection request");
    }
    synchronized (clientIdSet) {
        AMQConnectionContext context;
        context = clientIdSet.get(clientId);
        if (context != null) {
            if (info.isFailoverReconnect()) {
                OpenWireConnection oldConnection = context.getConnection();
                oldConnection.disconnect(true);
                connections.remove(oldConnection);
                connection.reconnect(context, info);
            } else {
                throw new InvalidClientIDException("Broker: " + getBrokerName() + " - Client: " + clientId + " already connected from " + context.getConnection().getRemoteAddress());
            }
        } else {
            // new connection
            context = connection.initContext(info);
            clientIdSet.put(clientId, context);
        }
        connections.add(connection);
        ActiveMQTopic topic = AdvisorySupport.getConnectionAdvisoryTopic();
        // do not distribute passwords in advisory messages. usernames okay
        ConnectionInfo copy = info.copy();
        copy.setPassword("");
        fireAdvisory(context, topic, copy);
        // init the conn
        context.getConnection().addSessions(context.getConnectionState().getSessionIds());
    }
}
Also used : ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) InvalidClientIDException(javax.jms.InvalidClientIDException) AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException)

Example 3 with ConnectionInfo

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

the class RecoveryBrokerTest method testQueuePersistentMessagesNotLostOnRestart.

public void testQueuePersistentMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    Message message = createMessage(producerInfo, destination);
    message.setPersistent(true);
    connection.send(message);
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // Message should have been dropped due to broker restart.
    Message m = receiveMessage(connection);
    assertNotNull("Should have received a message by now!", m);
    assertEquals(m.getMessageId(), message.getMessageId());
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 4 with ConnectionInfo

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

the class RecoveryBrokerTest method testQueuePersistentCommittedMessagesNotLostOnRestart.

public void testQueuePersistentCommittedMessagesNotLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Commit
    connection.send(createCommitTransaction1Phase(connectionInfo, txid));
    connection.request(closeConnectionInfo(connectionInfo));
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    for (int i = 0; i < 4; i++) {
        Message m = receiveMessage(connection);
        assertNotNull(m);
    }
    assertNoMessagesLeft(connection);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) Message(org.apache.activemq.command.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 5 with ConnectionInfo

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

the class RecoveryBrokerTest method testQueuePersistentUncommitedMessagesLostOnRestart.

public void testQueuePersistentUncommitedMessagesLostOnRestart() throws Exception {
    ActiveMQDestination destination = new ActiveMQQueue("TEST");
    // Setup the producer and send the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo);
    connection.send(createBeginTransaction(connectionInfo, txid));
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo, destination);
        message.setPersistent(true);
        message.setTransactionId(txid);
        connection.send(message);
    }
    // Don't commit
    // restart the broker.
    restartBroker();
    // Setup the consumer and receive the message.
    connection = createConnection();
    connectionInfo = createConnectionInfo();
    sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    // No messages should be delivered.
    Message m = receiveMessage(connection);
    assertNull(m);
}
Also used : ProducerInfo(org.apache.activemq.command.ProducerInfo) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) LocalTransactionId(org.apache.activemq.command.LocalTransactionId) Message(org.apache.activemq.command.Message) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) SessionInfo(org.apache.activemq.command.SessionInfo) ConnectionInfo(org.apache.activemq.command.ConnectionInfo) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Aggregations

ConnectionInfo (org.apache.activemq.command.ConnectionInfo)110 SessionInfo (org.apache.activemq.command.SessionInfo)77 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 Message (org.apache.activemq.command.Message)71 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)44 StubConnection (org.apache.activemq.broker.StubConnection)18 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)18 MessageAck (org.apache.activemq.command.MessageAck)15 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)10 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 ConnectionId (org.apache.activemq.command.ConnectionId)6 RemoveInfo (org.apache.activemq.command.RemoveInfo)6 IOException (java.io.IOException)5 Response (org.apache.activemq.command.Response)5 Test (org.junit.Test)5 ConnectionContext (org.apache.activemq.broker.ConnectionContext)4