Skip to content

Commit

Permalink
Allow global and per-session max Subscriptions to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Aug 24, 2022
1 parent 4534381 commit 938ed51
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Expand Up @@ -90,6 +90,24 @@ default Double getMaxSubscriptionLifetime() {
return (double) TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
}

/**
* Get the maximum number of Subscriptions, across all Sessions, that can be created.
*
* @return the maximum number of Subscriptions, across all Sessions, that can be created.
*/
default UInteger getMaxSubscriptions() {
return uint(Integer.MAX_VALUE);
}

/**
* Get the maximum number of Subscriptions, per Session, that can be created.
*
* @return the maximum number of Subscriptions, per Session, that can be created.
*/
default UInteger getMaxSubscriptionsPerSession() {
return uint(Integer.MAX_VALUE);
}

default Double getMaxSupportedSampleRate() {
return (double) TimeUnit.MILLISECONDS.convert(24, TimeUnit.HOURS);
}
Expand Down
Expand Up @@ -156,6 +156,16 @@ public List<Subscription> getSubscriptions() {
public void createSubscription(ServiceRequest service) {
CreateSubscriptionRequest request = (CreateSubscriptionRequest) service.getRequest();

if (subscriptions.size() >= server.getConfig().getLimits().getMaxSubscriptionsPerSession().intValue()) {
service.setServiceFault(StatusCodes.Bad_TooManySubscriptions);
return;
}

if (server.getSubscriptions().size() >= server.getConfig().getLimits().getMaxSubscriptions().intValue()) {
service.setServiceFault(StatusCodes.Bad_TooManySubscriptions);
return;
}

UInteger subscriptionId = nextSubscriptionId();

Subscription subscription = new Subscription(
Expand Down Expand Up @@ -204,7 +214,8 @@ public void createSubscription(ServiceRequest service) {
ResponseHeader header = service.createResponseHeader();

CreateSubscriptionResponse response = new CreateSubscriptionResponse(
header, subscriptionId,
header,
subscriptionId,
subscription.getPublishingInterval(),
uint(subscription.getLifetimeCount()),
uint(subscription.getMaxKeepAliveCount())
Expand Down

0 comments on commit 938ed51

Please sign in to comment.