Search in sources :

Example 1 with AMQConnectionContext

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext in project activemq-artemis by apache.

the class OpenWireConnection method initContext.

public AMQConnectionContext initContext(ConnectionInfo info) throws Exception {
    WireFormatInfo wireFormatInfo = inWireFormat.getPreferedWireFormatInfo();
    // they were not.
    if (wireFormatInfo != null && wireFormatInfo.getVersion() <= 2) {
        info.setClientMaster(true);
    }
    state = new ConnectionState(info);
    context = new AMQConnectionContext();
    state.reset(info);
    // Setup the context.
    String clientId = info.getClientId();
    context.setBroker(protocolManager);
    context.setClientId(clientId);
    context.setClientMaster(info.isClientMaster());
    context.setConnection(this);
    context.setConnectionId(info.getConnectionId());
    // for now we pass the manager as the connector and see what happens
    // it should be related to activemq's Acceptor
    context.setFaultTolerant(info.isFaultTolerant());
    context.setUserName(info.getUserName());
    context.setWireFormatInfo(wireFormatInfo);
    context.setReconnect(info.isFailoverReconnect());
    context.setConnectionState(state);
    if (info.getClientIp() == null) {
        info.setClientIp(getRemoteAddress());
    }
    createInternalSession(info);
    return context;
}
Also used : AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) WireFormatInfo(org.apache.activemq.command.WireFormatInfo) ConnectionState(org.apache.activemq.state.ConnectionState) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 2 with AMQConnectionContext

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext in project activemq-artemis by apache.

the class OpenWireConnection method removeDestination.

public void removeDestination(ActiveMQDestination dest) throws Exception {
    if (dest.isQueue()) {
        try {
            server.destroyQueue(new SimpleString(dest.getPhysicalName()), getRemotingConnection());
        } catch (ActiveMQNonExistentQueueException neq) {
            // this is ok, ActiveMQ 5 allows this and will actually do it quite often
            ActiveMQServerLogger.LOGGER.debug("queue never existed");
        }
    } else {
        Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(dest.getPhysicalName()));
        for (Binding binding : bindings.getBindings()) {
            Queue b = (Queue) binding.getBindable();
            if (b.getConsumerCount() > 0) {
                throw new Exception("Destination still has an active subscription: " + dest.getPhysicalName());
            }
            if (b.isDurable()) {
                throw new Exception("Destination still has durable subscription: " + dest.getPhysicalName());
            }
            b.deleteQueue();
        }
    }
    if (!AdvisorySupport.isAdvisoryTopic(dest)) {
        AMQConnectionContext context = getContext();
        DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.REMOVE_OPERATION_TYPE, dest);
        ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
        protocolManager.fireAdvisory(context, topic, advInfo);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) DestinationInfo(org.apache.activemq.command.DestinationInfo) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) ActiveMQTempQueue(org.apache.activemq.command.ActiveMQTempQueue) Queue(org.apache.activemq.artemis.core.server.Queue) 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 AMQConnectionContext

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext in project activemq-artemis by apache.

the class OpenWireConnection method addDestination.

public void addDestination(DestinationInfo info) throws Exception {
    boolean created = false;
    ActiveMQDestination dest = info.getDestination();
    if (!protocolManager.isSupportAdvisory() && AdvisorySupport.isAdvisoryTopic(dest)) {
        return;
    }
    SimpleString qName = SimpleString.toSimpleString(dest.getPhysicalName());
    if (server.locateQueue(qName) == null) {
        AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(dest.getPhysicalName());
        AddressInfo addressInfo = new AddressInfo(qName, dest.isTopic() ? RoutingType.MULTICAST : RoutingType.ANYCAST);
        if (AdvisorySupport.isAdvisoryTopic(dest) && protocolManager.isSuppressInternalManagementObjects()) {
            addressInfo.setInternal(true);
        }
        if (dest.isQueue() && (addressSettings.isAutoCreateQueues() || dest.isTemporary())) {
            try {
                internalSession.createQueue(addressInfo, qName, null, dest.isTemporary(), !dest.isTemporary(), !dest.isTemporary());
                created = true;
            } catch (ActiveMQQueueExistsException exists) {
            // The queue may have been created by another thread in the mean time.  Catch and do nothing.
            }
        } else if (dest.isTopic() && (addressSettings.isAutoCreateAddresses() || dest.isTemporary())) {
            try {
                internalSession.createAddress(addressInfo, !dest.isTemporary());
                created = true;
            } catch (ActiveMQAddressExistsException exists) {
            // The address may have been created by another thread in the mean time.  Catch and do nothing.
            }
        }
    }
    if (dest.isTemporary()) {
        // Openwire needs to store the DestinationInfo in order to send
        // Advisory messages to clients
        this.state.addTempDestination(info);
    }
    if (created && !AdvisorySupport.isAdvisoryTopic(dest)) {
        AMQConnectionContext context = getContext();
        DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.ADD_OPERATION_TYPE, dest);
        ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
        protocolManager.fireAdvisory(context, topic, advInfo);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DestinationInfo(org.apache.activemq.command.DestinationInfo) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException) AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 4 with AMQConnectionContext

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext in project activemq-artemis by apache.

the class OpenWireProtocolManager method removeConnection.

public void removeConnection(ConnectionInfo info, Throwable error) throws InvalidClientIDException {
    synchronized (clientIdSet) {
        String clientId = info.getClientId();
        if (clientId != null) {
            AMQConnectionContext context = this.clientIdSet.get(clientId);
            if (context != null && context.decRefCount() == 0) {
                // connection is still there and need to close
                context.getConnection().disconnect(error != null);
                this.connections.remove(context.getConnection());
                this.clientIdSet.remove(clientId);
            }
        } else {
            throw new InvalidClientIDException("No clientID specified for connection disconnect request");
        }
    }
}
Also used : AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) InvalidClientIDException(javax.jms.InvalidClientIDException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 5 with AMQConnectionContext

use of org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext 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)

Aggregations

AMQConnectionContext (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext)6 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)5 InvalidClientIDException (javax.jms.InvalidClientIDException)4 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)4 ActiveMQAddressExistsException (org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)3 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)3 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)3 DestinationInfo (org.apache.activemq.command.DestinationInfo)3 IOException (java.io.IOException)2 IllegalStateException (javax.jms.IllegalStateException)2 InvalidDestinationException (javax.jms.InvalidDestinationException)2 JMSSecurityException (javax.jms.JMSSecurityException)2 XAException (javax.transaction.xa.XAException)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ActiveMQNonExistentQueueException (org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException)2 ActiveMQRemoteDisconnectException (org.apache.activemq.artemis.api.core.ActiveMQRemoteDisconnectException)2 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)2 ActiveMQTempQueue (org.apache.activemq.command.ActiveMQTempQueue)2 Binding (org.apache.activemq.artemis.core.postoffice.Binding)1 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)1