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