Package com.github.twitch4j.pubsub
Class TwitchPubSubConnectionPool
java.lang.Object
com.github.twitch4j.common.pool.AbstractConnectionPool<C>
com.github.twitch4j.common.pool.SubscriptionConnectionPool<C,X,Y,Z>
com.github.twitch4j.common.pool.TwitchModuleConnectionPool<TwitchPubSub,PubSubRequest,PubSubSubscription,Boolean,TwitchPubSubBuilder>
com.github.twitch4j.pubsub.TwitchPubSubConnectionPool
- All Implemented Interfaces:
TransactionalSubscriber<PubSubRequest,
,PubSubSubscription, Boolean> ITwitchPubSub
,AutoCloseable
public class TwitchPubSubConnectionPool
extends TwitchModuleConnectionPool<TwitchPubSub,PubSubRequest,PubSubSubscription,Boolean,TwitchPubSubBuilder>
implements ITwitchPubSub
A pool for PubSub connections to help navigate rate-limits.
Warning: Passing a ScheduledThreadPoolExecutor
with too small corePoolSize can lead to
connections in the pool not behaving properly. Not specifying an executor allows connections to create their own
at will. If enough connections are made, this could pollute one's runtime environment.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
TwitchPubSubConnectionPool.TwitchPubSubConnectionPoolBuilder<C extends TwitchPubSubConnectionPool,
B extends TwitchPubSubConnectionPool.TwitchPubSubConnectionPoolBuilder<C, B>> Nested classes/interfaces inherited from class com.github.twitch4j.common.pool.TwitchModuleConnectionPool
TwitchModuleConnectionPool.TwitchModuleConnectionPoolBuilder<C,
X, Y, Z, B, C2 extends TwitchModuleConnectionPool<C, X, Y, Z, B>, B2 extends TwitchModuleConnectionPool.TwitchModuleConnectionPoolBuilder<C, X, Y, Z, B, C2, B2>> Nested classes/interfaces inherited from class com.github.twitch4j.common.pool.SubscriptionConnectionPool
SubscriptionConnectionPool.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 inherited from class com.github.twitch4j.common.pool.TwitchModuleConnectionPool
advancedConfiguration, executor, proxyConfig
Fields inherited from class com.github.twitch4j.common.pool.SubscriptionConnectionPool
closed, disposeUnusedConnections, maxSubscriptionsPerConnection, saturatedConnections, subscriptions, unsaturatedConnections
-
Constructor Summary
ModifierConstructorDescriptionprotected
-
Method Summary
Modifier and TypeMethodDescriptionbuilder()
protected TwitchPubSub
protected void
disposeConnection
(TwitchPubSub connection) long
protected PubSubRequest
getRequestFromSubscription
(PubSubSubscription subscription) protected int
getSubscriptionSize
(PubSubRequest pubSubRequest) protected PubSubSubscription
handleDuplicateSubscription
(TwitchPubSub twitchPubSub, TwitchPubSub old, PubSubRequest pubSubRequest) protected PubSubSubscription
handleSubscription
(TwitchPubSub twitchPubSub, PubSubRequest pubSubRequest) protected Boolean
handleUnsubscription
(TwitchPubSub twitchPubSub, PubSubSubscription pubSubSubscription) listenOnTopic
(PubSubRequest request) Send WS Message to subscribe to a topicsubscribe
(PubSubRequest pubSubRequest) Submits a subscription request.boolean
unsubscribeFromTopic
(PubSubSubscription subscription) Unsubscribe from a topic.Methods inherited from class com.github.twitch4j.common.pool.TwitchModuleConnectionPool
getConnectionEventManager, getDefaultConnectionEventManager, getEventManager, getExecutor
Methods inherited from class com.github.twitch4j.common.pool.SubscriptionConnectionPool
close, getConnections, numConnections, numSubscriptions, unsubscribe
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.github.twitch4j.pubsub.ITwitchPubSub
close, getEventManager, listenForAdPropertyRefreshEvents, listenForAdsEvents, listenForAdsManagerEvents, listenForAutomodLevelsModificationEvents, listenForAutomodQueueEvents, listenForBitsBadgeEvents, listenForBountyBoardEvents, listenForBroadcastSettingUpdateEvents, listenForCelebrationEvents, listenForChannelBitsLeaderboardAllTimeEvents, listenForChannelBitsLeaderboardEvents, listenForChannelBitsLeaderboardEvents, listenForChannelBitsLeaderboardMonthlyEvents, listenForChannelChatroomEvents, listenForChannelDropEvents, listenForChannelExtensionEvents, listenForChannelPointsRedemptionEvents, listenForChannelPredictionsEvents, listenForChannelPrimeGiftStatusEvents, listenForChannelSquadEvents, listenForChannelSubGiftsEvents, listenForChannelSubLeaderboardAllTimeEvents, listenForChannelSubLeaderboardEvents, listenForChannelSubLeaderboardEvents, listenForChannelSubLeaderboardMonthlyEvents, listenForChannelUnbanRequestEvents, listenForCharityCampaignEvents, listenForChatHighlightEvents, listenForCheerEvents, listenForCommerceEvents, listenForCommunityBoostEvents, listenForCreatorGoalsEvents, listenForCrowdChantEvents, listenForDashboardActivityFeedEvents, listenForExtensionControlEvents, listenForFollowingEvents, listenForFollows, listenForFriendshipEvents, listenForHypeTrainEvents, listenForHypeTrainRewardEvents, listenForLeaderboardAllTimeEvents, listenForLeaderboardEvents, listenForLeaderboardEvents, listenForLeaderboardMonthlyEvents, listenForLowTrustUsersEvents, listenForModerationEvents, listenForModerationEvents, listenForOnsiteNotificationEvents, listenForPinnedChatEvents, listenForPollEvents, listenForPresenceEvents, listenForPublicBitEvents, listenForPublicCheerEvents, listenForRadioEvents, listenForRaidEvents, listenForShieldModeEvents, listenForShoutoutEvents, listenForStreamChangeEvents, listenForStreamChatRoomEvents, listenForSubscriptionEvents, listenForUserBitsUpdateEvents, listenForUserCampaignEvents, listenForUserChannelPointsEvents, listenForUserChatroomEvents, listenForUserDropEvents, listenForUserImageUpdateEvents, listenForUserModerationNotificationEvents, listenForUserPredictionsEvents, listenForUserPropertiesUpdateEvents, listenForUserSubscribeEvents, listenForUserUnbanRequestEvents, listenForVideoPlaybackByNameEvents, listenForVideoPlaybackEvents, listenForWatchPartyEvents, listenForWhisperEvents, listenOnTopic, listenOnTopic, listenOnTopic
-
Constructor Details
-
TwitchPubSubConnectionPool
protected TwitchPubSubConnectionPool(TwitchPubSubConnectionPool.TwitchPubSubConnectionPoolBuilder<?, ?> b)
-
-
Method Details
-
listenOnTopic
Description copied from interface:ITwitchPubSub
Send WS Message to subscribe to a topic- Specified by:
listenOnTopic
in interfaceITwitchPubSub
- Parameters:
request
- Topic- Returns:
- PubSubSubscription to be listened to
-
unsubscribeFromTopic
Description copied from interface:ITwitchPubSub
Unsubscribe from a topic. Usage example:PubSubSubscription subscription = twitchPubSub.listenForCheerEvents(...); // ... twitchPubSub.unsubscribeFromTopic(subscription);
- Specified by:
unsubscribeFromTopic
in interfaceITwitchPubSub
- Parameters:
subscription
- PubSubSubscription to be unlistened from- Returns:
- whether the subscription was previously subscribed to
-
subscribe
Description copied from interface:TransactionalSubscriber
Submits a subscription request.- Specified by:
subscribe
in interfaceTransactionalSubscriber<PubSubRequest,
PubSubSubscription, Boolean> - Overrides:
subscribe
in classSubscriptionConnectionPool<TwitchPubSub,
PubSubRequest, PubSubSubscription, Boolean> - Parameters:
pubSubRequest
- the subscription request- Returns:
- a response to the request
-
createConnection
- Specified by:
createConnection
in classAbstractConnectionPool<TwitchPubSub>
-
disposeConnection
- Specified by:
disposeConnection
in classAbstractConnectionPool<TwitchPubSub>
-
handleSubscription
protected PubSubSubscription handleSubscription(TwitchPubSub twitchPubSub, PubSubRequest pubSubRequest) - Specified by:
handleSubscription
in classSubscriptionConnectionPool<TwitchPubSub,
PubSubRequest, PubSubSubscription, Boolean>
-
handleDuplicateSubscription
protected PubSubSubscription handleDuplicateSubscription(TwitchPubSub twitchPubSub, TwitchPubSub old, PubSubRequest pubSubRequest) - Specified by:
handleDuplicateSubscription
in classSubscriptionConnectionPool<TwitchPubSub,
PubSubRequest, PubSubSubscription, Boolean>
-
handleUnsubscription
protected Boolean handleUnsubscription(TwitchPubSub twitchPubSub, PubSubSubscription pubSubSubscription) - Specified by:
handleUnsubscription
in classSubscriptionConnectionPool<TwitchPubSub,
PubSubRequest, PubSubSubscription, Boolean>
-
getRequestFromSubscription
- Specified by:
getRequestFromSubscription
in classSubscriptionConnectionPool<TwitchPubSub,
PubSubRequest, PubSubSubscription, Boolean>
-
getSubscriptionSize
- Specified by:
getSubscriptionSize
in classSubscriptionConnectionPool<TwitchPubSub,
PubSubRequest, PubSubSubscription, Boolean>
-
getLatency
public long getLatency()- Specified by:
getLatency
in interfaceITwitchPubSub
- Returns:
- the most recently measured round-trip latency for the socket(s) in milliseconds, or -1 if unknown
-
builder
-