ARTEMIS-5012 update docs & code to clarify resource-limit-settings
This commit is contained in:
parent
ca66de4bde
commit
f3bcab88dc
|
@ -1830,10 +1830,10 @@ public class ActiveMQServerImpl implements ActiveMQServer {
|
|||
if (configuration.getResourceLimitSettings() != null && configuration.getResourceLimitSettings().containsKey(username)) {
|
||||
ResourceLimitSettings limits = configuration.getResourceLimitSettings().get(username);
|
||||
|
||||
if (limits.getMaxConnections() == -1) {
|
||||
if (limits.getMaxSessions() == -1) {
|
||||
return;
|
||||
} else if (limits.getMaxConnections() == 0 || getSessionCountForUser(username) >= limits.getMaxConnections()) {
|
||||
throw ActiveMQMessageBundle.BUNDLE.sessionLimitReached(username, limits.getMaxConnections());
|
||||
} else if (limits.getMaxSessions() == 0 || getSessionCountForUser(username) >= limits.getMaxSessions()) {
|
||||
throw ActiveMQMessageBundle.BUNDLE.sessionLimitReached(username, limits.getMaxSessions());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
|
||||
public static final SimpleString DEFAULT_MATCH = null;
|
||||
|
||||
public static final Integer DEFAULT_MAX_CONNECTIONS = -1;
|
||||
public static final Integer DEFAULT_MAX_SESSIONS = -1;
|
||||
|
||||
public static final Integer DEFAULT_MAX_QUEUES = -1;
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
|
||||
SimpleString match = null;
|
||||
|
||||
Integer maxConnections = null;
|
||||
Integer maxSessions = null;
|
||||
|
||||
Integer maxQueues = null;
|
||||
|
||||
|
@ -56,8 +56,13 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
return match != null ? match : DEFAULT_MATCH;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public int getMaxConnections() {
|
||||
return maxConnections != null ? maxConnections : DEFAULT_MAX_CONNECTIONS;
|
||||
return getMaxSessions();
|
||||
}
|
||||
|
||||
public int getMaxSessions() {
|
||||
return maxSessions != null ? maxSessions : DEFAULT_MAX_SESSIONS;
|
||||
}
|
||||
|
||||
public int getMaxQueues() {
|
||||
|
@ -78,8 +83,13 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
this.match = match;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void setMaxConnections(int maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
setMaxSessions(maxConnections);
|
||||
}
|
||||
|
||||
public void setMaxSessions(int maxSessions) {
|
||||
this.maxSessions = maxSessions;
|
||||
}
|
||||
|
||||
public void setMaxQueues(int maxQueues) {
|
||||
|
@ -99,7 +109,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
@Override
|
||||
public int getEncodeSize() {
|
||||
return SimpleString.sizeofNullableString(match) +
|
||||
BufferHelper.sizeOfNullableInteger(maxConnections) +
|
||||
BufferHelper.sizeOfNullableInteger(maxSessions) +
|
||||
BufferHelper.sizeOfNullableInteger(maxQueues);
|
||||
// BufferHelper.sizeOfNullableLong(maxQueueSizeBytes) +
|
||||
// SimpleString.sizeofNullableString(queueNameRegex);
|
||||
|
@ -109,7 +119,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
public void encode(ActiveMQBuffer buffer) {
|
||||
buffer.writeNullableSimpleString(match);
|
||||
|
||||
BufferHelper.writeNullableInteger(buffer, maxConnections);
|
||||
BufferHelper.writeNullableInteger(buffer, maxSessions);
|
||||
|
||||
BufferHelper.writeNullableInteger(buffer, maxQueues);
|
||||
|
||||
|
@ -122,7 +132,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
public void decode(ActiveMQBuffer buffer) {
|
||||
match = buffer.readNullableSimpleString();
|
||||
|
||||
maxConnections = BufferHelper.readNullableInteger(buffer);
|
||||
maxSessions = BufferHelper.readNullableInteger(buffer);
|
||||
|
||||
maxQueues = BufferHelper.readNullableInteger(buffer);
|
||||
|
||||
|
@ -139,7 +149,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((match == null) ? 0 : match.hashCode());
|
||||
result = prime * result + ((maxConnections == null) ? 0 : maxConnections.hashCode());
|
||||
result = prime * result + ((maxSessions == null) ? 0 : maxSessions.hashCode());
|
||||
result = prime * result + ((maxQueues == null) ? 0 : maxQueues.hashCode());
|
||||
// result = prime * result + ((maxQueueSizeBytes == null) ? 0 : maxQueueSizeBytes.hashCode());
|
||||
// result = prime * result + ((queueNameRegex == null) ? 0 : queueNameRegex.hashCode());
|
||||
|
@ -160,7 +170,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
if (match != null ? !match.equals(that.match) : that.match != null) {
|
||||
return false;
|
||||
}
|
||||
if (maxConnections != null ? !maxConnections.equals(that.maxConnections) : that.maxConnections != null) {
|
||||
if (maxSessions != null ? !maxSessions.equals(that.maxSessions) : that.maxSessions != null) {
|
||||
return false;
|
||||
}
|
||||
return maxQueues != null ? maxQueues.equals(that.maxQueues) : that.maxQueues == null;
|
||||
|
@ -172,8 +182,7 @@ public class ResourceLimitSettings implements Serializable, EncodingSupport {
|
|||
@Override
|
||||
public String toString() {
|
||||
return "ResourceLimitSettings [match=" + match +
|
||||
", maxConnections=" +
|
||||
maxConnections +
|
||||
", maxSessions=" + maxSessions +
|
||||
", maxQueues=" +
|
||||
maxQueues +
|
||||
// ", maxQueueSizeBytes=" +
|
||||
|
|
|
@ -4511,7 +4511,15 @@
|
|||
<xsd:element name="max-connections" type="xsd:int" default="-1" maxOccurs="1" minOccurs="0">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
how many connections are allowed by the matched user (-1 means no limit, default is -1)
|
||||
DEPRECATED: use max-sessions instead
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="max-sessions" type="xsd:int" default="-1" maxOccurs="1" minOccurs="0">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
how many sessions are allowed by the matched user (-1 means no limit, default is -1)
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
|
|
|
@ -1137,7 +1137,9 @@ public class ConfigurationImplTest extends AbstractConfigurationTestBase {
|
|||
}
|
||||
}
|
||||
|
||||
// continue testing deprecated method
|
||||
assertEquals(100, configuration.getResourceLimitSettings().get("joe").getMaxConnections());
|
||||
assertEquals(100, configuration.getResourceLimitSettings().get("joe").getMaxSessions());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -584,7 +584,9 @@ public class FileConfigurationTest extends AbstractConfigurationTestBase {
|
|||
assertTrue(conf.isMirrorPageTransaction());
|
||||
|
||||
assertTrue(conf.getResourceLimitSettings().containsKey("myUser"));
|
||||
// continue testing deprecated method
|
||||
assertEquals(104, conf.getResourceLimitSettings().get("myUser").getMaxConnections());
|
||||
assertEquals(104, conf.getResourceLimitSettings().get("myUser").getMaxSessions());
|
||||
assertEquals(13, conf.getResourceLimitSettings().get("myUser").getMaxQueues());
|
||||
|
||||
assertEquals(2, conf.getQueueConfigs().size());
|
||||
|
|
|
@ -14,7 +14,7 @@ Here is an example of the XML used to set resource limits:
|
|||
----
|
||||
<resource-limit-settings>
|
||||
<resource-limit-setting match="myUser">
|
||||
<max-connections>5</max-connections>
|
||||
<max-sessions>5</max-sessions>
|
||||
<max-queues>3</max-queues>
|
||||
</resource-limit-setting>
|
||||
</resource-limit-settings>
|
||||
|
@ -23,10 +23,25 @@ Here is an example of the XML used to set resource limits:
|
|||
Unlike the `match` from `address-setting`, this `match` does not use any wild-card syntax.
|
||||
It's a simple 1:1 mapping of the limits to a *user*.
|
||||
|
||||
max-connections::
|
||||
How many connections the matched user can make to the broker.
|
||||
max-sessions::
|
||||
How many sessions the matched user can create on the broker.
|
||||
The default is -1 which means there is no limit.
|
||||
+
|
||||
.Why _sessions_ and not _connections_?
|
||||
****
|
||||
The _session_ is the fundamental networked resource in the Core API.
|
||||
|
||||
There is no conceptual separation between a _connection_ and a _session_ in the Core API as there is, for example, in JMS/Jakarta Messaging.
|
||||
When an application uses the Core JMS implementation to create a JMS `Connection` what's actually created behind-the-scenes is a Core session.
|
||||
This session is used to validate the client application's credentials and JMS client ID (if available).
|
||||
When the application creates a JMS `Session` then another Core session is created.
|
||||
|
||||
The same basic thing happens for the other supported protocols (e.g. STOMP, AMQP, MQTT). When a client creates a network connection to the broker the broker responds by creating an internal, server-side session.
|
||||
|
||||
The number of these sessions can be limited on a per-user basis.
|
||||
|
||||
To be clear, the broker _does_ track basic TCP connections, and these too can be limited (i.e. via the `connectionsAllowed` acceptor URL parameter), but these connections don't carry credentials and therefore cannot be limited on a per-user basis.
|
||||
****
|
||||
max-queues::
|
||||
How many queues the matched user can create.
|
||||
The default is -1 which means there is no limit.
|
||||
|
|
Loading…
Reference in New Issue