Package com.github.twitch4j.common.pool
Class SubscriptionConnectionPool<C,S,T,U>
java.lang.Object
com.github.twitch4j.common.pool.AbstractConnectionPool<C>
com.github.twitch4j.common.pool.SubscriptionConnectionPool<C,S,T,U>
- Type Parameters:
C- the connection typeS- the subscription requestT- transactional subscription response and potential unsubscription requestU- the unsubscription response
- All Implemented Interfaces:
TransactionalSubscriber<S,,T, U> AutoCloseable
- Direct Known Subclasses:
TwitchModuleConnectionPool
public abstract class SubscriptionConnectionPool<C,S,T,U>
extends AbstractConnectionPool<C>
implements TransactionalSubscriber<S,T,U>
A pool of connections for making subscriptions (and potentially unsubscribing from later).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSubscriptionConnectionPool.SubscriptionConnectionPoolBuilder<C,S, T, U, C2 extends SubscriptionConnectionPool<C, S, T, U>, B extends SubscriptionConnectionPool.SubscriptionConnectionPoolBuilder<C, S, T, U, C2, B>> Nested classes/interfaces inherited from class com.github.twitch4j.common.pool.AbstractConnectionPool
AbstractConnectionPool.AbstractConnectionPoolBuilder<C,C2 extends AbstractConnectionPool<C>, B extends AbstractConnectionPool.AbstractConnectionPoolBuilder<C, C2, B>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final AtomicBooleanTracks whether the pool has been closed.protected final booleanWhether connections without subscriptions should be disposed of.protected final intThe maximum number of outstanding subscriptions a connection may have.Connections that are already at the maximum subscriptions.protected final ConcurrentMap<S,C> A mapping of which connections hold what subscriptions.protected final ConcurrentMap<C,Integer> A mapping of connections that are not saturated yet to the number of subscriptions they have. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSubscriptionConnectionPool(SubscriptionConnectionPool.SubscriptionConnectionPoolBuilder<C, S, T, U, ?, ?> b) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()protected abstract Sprotected abstract intprotected abstract ThandleDuplicateSubscription(C c, C old, S s) protected abstract ThandleSubscription(C c, S s) protected abstract UhandleUnsubscription(C c, T t) intintSubmits a subscription request.unsubscribe(T t) Submits an unsubscription request.Methods inherited from class com.github.twitch4j.common.pool.AbstractConnectionPool
createConnection, disposeConnection
-
Field Details
-
disposeUnusedConnections
protected final boolean disposeUnusedConnectionsWhether connections without subscriptions should be disposed of. Default: true.As an optimization, this can be set to false to not dispose of connections in an environment where it is known that a large burst of unsubscriptions will be followed by enough subscriptions such that connections will never need to be disposed of automatically. However, be wary of configuring this as a misstep in your calculations may lead to connections sitting idly while consuming resources.
-
maxSubscriptionsPerConnection
protected final int maxSubscriptionsPerConnectionThe maximum number of outstanding subscriptions a connection may have. Default: 50.50 is a reasonable default given that it is the standard limit imposed on PubSub connections by Twitch and it is the previously-documented rate-limit on the number of possible JOINs in chat in a short burst.
- See Also:
-
saturatedConnections
Connections that are already at the maximum subscriptions. -
unsaturatedConnections
A mapping of connections that are not saturated yet to the number of subscriptions they have. -
subscriptions
A mapping of which connections hold what subscriptions. -
closed
Tracks whether the pool has been closed.
-
-
Constructor Details
-
SubscriptionConnectionPool
protected SubscriptionConnectionPool(SubscriptionConnectionPool.SubscriptionConnectionPoolBuilder<C, S, T, U, ?, ?> b)
-
-
Method Details
-
subscribe
Description copied from interface:TransactionalSubscriberSubmits a subscription request.- Specified by:
subscribein interfaceTransactionalSubscriber<C,S, T> - Parameters:
s- the subscription request- Returns:
- a response to the request
-
unsubscribe
Description copied from interface:TransactionalSubscriberSubmits an unsubscription request.- Specified by:
unsubscribein interfaceTransactionalSubscriber<C,S, T> - Parameters:
t- the unsubscription request- Returns:
- a response to the request
-
numConnections
public int numConnections()- Overrides:
numConnectionsin classAbstractConnectionPool<C>- Returns:
- the number of open connections held by this pool.
-
getConnections
- Specified by:
getConnectionsin classAbstractConnectionPool<C>
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classAbstractConnectionPool<C>
-
numSubscriptions
public int numSubscriptions()- Returns:
- the total number of subscriptions held by all connections
-
handleSubscription
-
handleDuplicateSubscription
-
handleUnsubscription
-
getRequestFromSubscription
-
getSubscriptionSize
-