Search in sources :

Example 21 with ServerSession

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

the class ActiveMQServerControlImpl method listProducers.

@Override
public String listProducers(@Parameter(name = "Options") String options, @Parameter(name = "Page Number") int page, @Parameter(name = "Page Size") int pageSize) throws Exception {
    checkStarted();
    clearIO();
    try {
        Set<ServerProducer> producers = new HashSet<>();
        for (ServerSession session : server.getSessions()) {
            producers.addAll(session.getServerProducers().values());
        }
        ProducerView view = new ProducerView(server);
        view.setCollection(producers);
        view.setOptions(options);
        return view.getResultsAsJson(page, pageSize);
    } finally {
        blockOnIO();
    }
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ServerProducer(org.apache.activemq.artemis.core.server.ServerProducer) ProducerView(org.apache.activemq.artemis.core.management.impl.view.ProducerView) HashSet(java.util.HashSet)

Example 22 with ServerSession

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

the class ActiveMQServerControlImpl method listSessionsAsJSON.

@Override
public String listSessionsAsJSON(final String connectionID) throws Exception {
    checkStarted();
    clearIO();
    JsonArrayBuilder array = JsonLoader.createArrayBuilder();
    try {
        List<ServerSession> sessions = server.getSessions(connectionID);
        for (ServerSession sess : sessions) {
            JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("sessionID", sess.getName()).add("creationTime", sess.getCreationTime()).add("consumerCount", sess.getServerConsumers().size());
            if (sess.getValidatedUser() != null) {
                obj.add("principal", sess.getValidatedUser());
            }
            array.add(obj);
        }
    } finally {
        blockOnIO();
    }
    return array.build().toString();
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 23 with ServerSession

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

the class ActiveMQServerControlImpl method listAllSessionsAsJSON.

@Override
public String listAllSessionsAsJSON() throws Exception {
    checkStarted();
    clearIO();
    JsonArrayBuilder array = JsonLoader.createArrayBuilder();
    try {
        Set<ServerSession> sessions = server.getSessions();
        for (ServerSession sess : sessions) {
            JsonObjectBuilder obj = JsonLoader.createObjectBuilder().add("sessionID", sess.getName()).add("creationTime", sess.getCreationTime()).add("consumerCount", sess.getServerConsumers().size());
            if (sess.getValidatedUser() != null) {
                obj.add("principal", sess.getValidatedUser());
            }
            array.add(obj);
        }
    } finally {
        blockOnIO();
    }
    return array.build().toString();
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 24 with ServerSession

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

the class ActiveMQServerControlImpl method closeConnectionsForUser.

@Override
public boolean closeConnectionsForUser(final String userName) {
    boolean closed = false;
    checkStarted();
    clearIO();
    try {
        for (ServerSession serverSession : server.getSessions()) {
            if (serverSession.getUsername() != null && serverSession.getUsername().equals(userName)) {
                RemotingConnection connection = null;
                for (RemotingConnection potentialConnection : remotingService.getConnections()) {
                    if (potentialConnection.getID().toString().equals(serverSession.getConnectionID().toString())) {
                        connection = potentialConnection;
                    }
                }
                if (connection != null) {
                    remotingService.removeConnection(connection.getID());
                    connection.fail(ActiveMQMessageBundle.BUNDLE.connectionsForUserClosedByManagement(userName));
                    closed = true;
                }
            }
        }
    } finally {
        blockOnIO();
    }
    return closed;
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)

Example 25 with ServerSession

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

the class ActiveMQServerControlImpl method listConsumersAsJSON.

@Override
public String listConsumersAsJSON(String connectionID) throws Exception {
    checkStarted();
    clearIO();
    try {
        JsonArrayBuilder array = JsonLoader.createArrayBuilder();
        Set<RemotingConnection> connections = server.getRemotingService().getConnections();
        for (RemotingConnection connection : connections) {
            if (connectionID.equals(connection.getID().toString())) {
                List<ServerSession> sessions = server.getSessions(connectionID);
                for (ServerSession session : sessions) {
                    Set<ServerConsumer> consumers = session.getServerConsumers();
                    for (ServerConsumer consumer : consumers) {
                        JsonObject obj = toJSONObject(consumer);
                        if (obj != null) {
                            array.add(obj);
                        }
                    }
                }
            }
        }
        return array.build().toString();
    } finally {
        blockOnIO();
    }
}
Also used : ServerSession(org.apache.activemq.artemis.core.server.ServerSession) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer)

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