Search in sources :

Example 26 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class ConnectionView method getField.

@Override
public Object getField(RemotingConnection connection, String fieldName) {
    List<ServerSession> sessions = server.getSessions(connection.getID().toString());
    switch(fieldName) {
        case "connectionID":
            return connection.getID();
        case "remoteAddress":
            return connection.getRemoteAddress();
        case "users":
            Set<String> users = new HashSet<>();
            for (ServerSession session : sessions) {
                String username = session.getUsername() == null ? "" : session.getUsername();
                users.add(username);
            }
            return users;
        case "creationTime":
            return new Date(connection.getCreationTime());
        case "implementation":
            return connection.getClass().getSimpleName();
        case "protocol":
            return connection.getProtocolName();
        case "clientID":
            return connection.getClientID();
        case "localAddress":
            return connection.getTransportLocalAddress();
        case "sessionCount":
            return sessions.size();
        default:
            throw new IllegalArgumentException("Unsupported field, " + fieldName);
    }
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) Date(java.util.Date) HashSet(java.util.HashSet)

Example 27 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class ConnectionView method toJson.

@Override
public JsonObjectBuilder toJson(RemotingConnection connection) {
    List<ServerSession> sessions = server.getSessions(connection.getID().toString());
    Set<String> users = new HashSet<>();
    for (ServerSession session : sessions) {
        String username = session.getUsername() == null ? "" : session.getUsername();
        users.add(username);
    }
    return JsonLoader.createObjectBuilder().add("connectionID", toString(connection.getID())).add("remoteAddress", toString(connection.getRemoteAddress())).add("users", StringUtil.joinStringList(users, ",")).add("creationTime", new Date(connection.getCreationTime()).toString()).add("implementation", toString(connection.getClass().getSimpleName())).add("protocol", toString(connection.getProtocolName())).add("clientID", toString(connection.getClientID())).add("localAddress", toString(connection.getTransportLocalAddress())).add("sessionCount", server.getSessions(connection.getID().toString()).size());
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) Date(java.util.Date) HashSet(java.util.HashSet)

Example 28 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class ConnectionFilterPredicate method apply.

@Override
public boolean apply(RemotingConnection connection) {
    // Using switch over enum vs string comparison is better for perf.
    if (f == null)
        return true;
    switch(f) {
        case CONNECTION_ID:
            return matches(connection.getID());
        case CLIENT_ID:
            return matches(connection.getClientID());
        case USERS:
            List<ServerSession> sessions = server.getSessions(connection.getID().toString());
            Set<String> users = new HashSet<>();
            for (ServerSession session : sessions) {
                String username = session.getUsername() == null ? "" : session.getUsername();
                users.add(username);
            }
            return matchAny(users);
        case PROTOCOL:
            return matches(connection.getProtocolName());
        case SESSION_COUNT:
            return matches(server.getSessions(connection.getID().toString()).size());
        case REMOTE_ADDRESS:
            return matches(connection.getTransportConnection().getRemoteAddress());
        case LOCAL_ADDRESS:
            return matches(connection.getTransportConnection().getLocalAddress());
        case SESSION_ID:
            return matchAny(server.getSessions(connection.getID().toString()));
    }
    return true;
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) HashSet(java.util.HashSet)

Example 29 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class StompConnection method autoCreateDestinationIfPossible.

public void autoCreateDestinationIfPossible(String queue, RoutingType routingType) throws ActiveMQStompException {
    ServerSession session = getSession().getCoreSession();
    try {
        SimpleString simpleQueue = SimpleString.toSimpleString(queue);
        if (manager.getServer().getAddressInfo(simpleQueue) == null) {
            AddressSettings addressSettings = manager.getServer().getAddressSettingsRepository().getMatch(queue);
            RoutingType effectiveAddressRoutingType = routingType == null ? addressSettings.getDefaultAddressRoutingType() : routingType;
            if (addressSettings.isAutoCreateAddresses()) {
                session.createAddress(simpleQueue, effectiveAddressRoutingType, true);
            }
            // only auto create the queue if the address is ANYCAST
            if (effectiveAddressRoutingType == RoutingType.ANYCAST && addressSettings.isAutoCreateQueues()) {
                session.createQueue(simpleQueue, simpleQueue, routingType == null ? addressSettings.getDefaultQueueRoutingType() : routingType, null, false, true, true);
            }
        }
    } catch (ActiveMQQueueExistsException e) {
    // ignore
    } catch (Exception e) {
        throw new ActiveMQStompException(e.getMessage(), e).setHandler(frameHandler);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 30 with ServerSession

use of org.apache.activemq.artemis.core.server.ServerSession in project activemq-artemis by apache.

the class ActiveMQServerImpl method getSessions.

@Override
public synchronized List<ServerSession> getSessions(final String connectionID) {
    Set<Entry<String, ServerSession>> sessionEntries = sessions.entrySet();
    List<ServerSession> matchingSessions = new ArrayList<>();
    for (Entry<String, ServerSession> sessionEntry : sessionEntries) {
        ServerSession serverSession = sessionEntry.getValue();
        if (serverSession.getConnectionID().toString().equals(connectionID)) {
            matchingSessions.add(serverSession);
        }
    }
    return matchingSessions;
}
Also used : Entry(java.util.Map.Entry) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

ServerSession (org.apache.activemq.artemis.core.server.ServerSession)32 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)11 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 ServerConsumer (org.apache.activemq.artemis.core.server.ServerConsumer)7 HashSet (java.util.HashSet)6 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 Test (org.junit.Test)5 Date (java.util.Date)4 JsonArrayBuilder (javax.json.JsonArrayBuilder)4 JsonObjectBuilder (javax.json.JsonObjectBuilder)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)4 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)4 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)4 LinkedList (java.util.LinkedList)3 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)3 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2