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>,java.lang.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 Classes Modifier and Type Class Description static 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
Fields Modifier and Type Field Description protected booleandisposeUnusedConnectionsWhether connections without subscriptions should be disposed of.protected intmaxSubscriptionsPerConnectionThe maximum number of outstanding subscriptions a connection may have.protected java.util.Set<C>saturatedConnectionsConnections that are already at the maximum subscriptions.protected java.util.concurrent.ConcurrentMap<S,C>subscriptionsA mapping of which connections hold what subscriptions.protected java.util.concurrent.ConcurrentMap<C,java.lang.Integer>unsaturatedConnectionsA mapping of connections that are not saturated yet to the number of subscriptions they have. -
Constructor Summary
Constructors Modifier Constructor Description protectedSubscriptionConnectionPool(SubscriptionConnectionPool.SubscriptionConnectionPoolBuilder<C,S,T,U,?,?> b) -
Method Summary
Modifier and Type Method Description protected java.lang.Iterable<C>getConnections()protected abstract SgetRequestFromSubscription(T t)protected abstract intgetSubscriptionSize(S s)protected abstract ThandleDuplicateSubscription(C c, C old, S s)protected abstract ThandleSubscription(C c, S s)protected abstract UhandleUnsubscription(C c, T t)intnumConnections()intnumSubscriptions()Tsubscribe(S s)Submits a subscription request.Uunsubscribe(T t)Submits an unsubscription request.Methods inherited from class com.github.twitch4j.common.pool.AbstractConnectionPool
close, createConnection, disposeConnectionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
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:
- PubSub Limits, Previous Chat Limits
-
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.
-
-
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>
-
numSubscriptions
public int numSubscriptions()- Returns:
- the total number of subscriptions held by all connections
-
handleSubscription
-
handleDuplicateSubscription
-
handleUnsubscription
-
getRequestFromSubscription
-
getSubscriptionSize
-