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
Nested ClassesModifier and TypeClassDescriptionstatic classTwitchPubSubConnectionPool.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, proxyConfigFields inherited from class com.github.twitch4j.common.pool.SubscriptionConnectionPool
closed, disposeUnusedConnections, maxSubscriptionsPerConnection, saturatedConnections, subscriptions, unsaturatedConnections -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionbuilder()protected TwitchPubSubprotected voiddisposeConnection(TwitchPubSub connection) longprotected PubSubRequestgetRequestFromSubscription(PubSubSubscription subscription) protected intgetSubscriptionSize(PubSubRequest pubSubRequest) protected PubSubSubscriptionhandleDuplicateSubscription(TwitchPubSub twitchPubSub, TwitchPubSub old, PubSubRequest pubSubRequest) protected PubSubSubscriptionhandleSubscription(TwitchPubSub twitchPubSub, PubSubRequest pubSubRequest) protected BooleanhandleUnsubscription(TwitchPubSub twitchPubSub, PubSubSubscription pubSubSubscription) listenOnTopic(PubSubRequest request) Send WS Message to subscribe to a topicsubscribe(PubSubRequest pubSubRequest) Submits a subscription request.booleanunsubscribeFromTopic(PubSubSubscription subscription) Unsubscribe from a topic.Methods inherited from class com.github.twitch4j.common.pool.TwitchModuleConnectionPool
getConnectionEventManager, getDefaultConnectionEventManager, getEventManager, getExecutorMethods inherited from class com.github.twitch4j.common.pool.SubscriptionConnectionPool
close, getConnections, numConnections, numSubscriptions, unsubscribeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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, listenForSharedChatEvents, 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:ITwitchPubSubSend WS Message to subscribe to a topic- Specified by:
listenOnTopicin interfaceITwitchPubSub- Parameters:
request- Topic- Returns:
- PubSubSubscription to be listened to
-
unsubscribeFromTopic
Description copied from interface:ITwitchPubSubUnsubscribe from a topic. Usage example:PubSubSubscription subscription = twitchPubSub.listenForCheerEvents(...); // ... twitchPubSub.unsubscribeFromTopic(subscription);- Specified by:
unsubscribeFromTopicin interfaceITwitchPubSub- Parameters:
subscription- PubSubSubscription to be unlistened from- Returns:
- whether the subscription was previously subscribed to
-
subscribe
Description copied from interface:TransactionalSubscriberSubmits a subscription request.- Specified by:
subscribein interfaceTransactionalSubscriber<PubSubRequest,PubSubSubscription, Boolean> - Overrides:
subscribein classSubscriptionConnectionPool<TwitchPubSub,PubSubRequest, PubSubSubscription, Boolean> - Parameters:
pubSubRequest- the subscription request- Returns:
- a response to the request
-
createConnection
- Specified by:
createConnectionin classAbstractConnectionPool<TwitchPubSub>
-
disposeConnection
- Specified by:
disposeConnectionin classAbstractConnectionPool<TwitchPubSub>
-
handleSubscription
protected PubSubSubscription handleSubscription(TwitchPubSub twitchPubSub, PubSubRequest pubSubRequest) - Specified by:
handleSubscriptionin classSubscriptionConnectionPool<TwitchPubSub,PubSubRequest, PubSubSubscription, Boolean>
-
handleDuplicateSubscription
protected PubSubSubscription handleDuplicateSubscription(TwitchPubSub twitchPubSub, TwitchPubSub old, PubSubRequest pubSubRequest) - Specified by:
handleDuplicateSubscriptionin classSubscriptionConnectionPool<TwitchPubSub,PubSubRequest, PubSubSubscription, Boolean>
-
handleUnsubscription
protected Boolean handleUnsubscription(TwitchPubSub twitchPubSub, PubSubSubscription pubSubSubscription) - Specified by:
handleUnsubscriptionin classSubscriptionConnectionPool<TwitchPubSub,PubSubRequest, PubSubSubscription, Boolean>
-
getRequestFromSubscription
- Specified by:
getRequestFromSubscriptionin classSubscriptionConnectionPool<TwitchPubSub,PubSubRequest, PubSubSubscription, Boolean>
-
getSubscriptionSize
- Specified by:
getSubscriptionSizein classSubscriptionConnectionPool<TwitchPubSub,PubSubRequest, PubSubSubscription, Boolean>
-
getLatency
public long getLatency()- Specified by:
getLatencyin interfaceITwitchPubSub- Returns:
- the most recently measured round-trip latency for the socket(s) in milliseconds, or -1 if unknown
-
builder
-