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();
}
}
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();
}
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();
}
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;
}
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();
}
}
Aggregations