Class TwitchClientHelper

java.lang.Object
com.github.twitch4j.TwitchClientHelper
All Implemented Interfaces:
java.lang.AutoCloseable

public class TwitchClientHelper
extends java.lang.Object
implements java.lang.AutoCloseable
A helper class that covers a few basic use cases of most library users
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int REQUIRED_THREAD_COUNT  
  • Constructor Summary

    Constructors
    Constructor Description
    TwitchClientHelper​(com.github.twitch4j.helix.TwitchHelix twitchHelix, com.github.philippheuer.events4j.core.EventManager eventManager, java.util.concurrent.ScheduledThreadPoolExecutor executor)
    Constructor
  • Method Summary

    Modifier and Type Method Description
    void close()
    Close
    void disableFollowEventListener​(java.lang.Iterable<java.lang.String> channelNames)
    Disable Follow Listener for the given channel names
    void disableFollowEventListener​(java.lang.String channelName)
    Disable Follow Listener
    boolean disableFollowEventListenerForId​(java.lang.String channelId)
    Disable Follow Listener, without invoking a Helix API call
    void disableStreamEventListener​(java.lang.Iterable<java.lang.String> channelNames)
    Disable StreamEvent Listener for the given channel names
    void disableStreamEventListener​(java.lang.String channelName)
    Disable StreamEvent Listener
    boolean disableStreamEventListenerForId​(java.lang.String channelId)
    Disable StreamEventListener, without invoking a Helix API call
    java.util.Collection<com.github.twitch4j.helix.domain.User> enableFollowEventListener​(java.lang.Iterable<java.lang.String> channelNames)
    Enable Follow Listener for the given channel names
    @Nullable com.github.twitch4j.helix.domain.User enableFollowEventListener​(java.lang.String channelName)
    Follow Listener
    boolean enableFollowEventListener​(java.lang.String channelId, java.lang.String channelName)
    Enable Follow Listener, without invoking a Helix API call
    java.util.Collection<com.github.twitch4j.helix.domain.User> enableStreamEventListener​(java.lang.Iterable<java.lang.String> channelNames)
    Enable StreamEvent Listener for the given channel names
    @Nullable com.github.twitch4j.helix.domain.User enableStreamEventListener​(java.lang.String channelName)
    Enable StreamEvent Listener
    boolean enableStreamEventListener​(java.lang.String channelId, java.lang.String channelName)
    Enable StreamEvent Listener, without invoking a Helix API call
    java.util.Optional<ChannelCache> getCachedInformation​(java.lang.String channelId)
    Get cached information for a channel's stream status and follower count.
    void setThreadDelay​(long threadDelay)
    Updates ExponentialBackoffStrategy.getBaseMillis() for each of the independent listeners (i.e. stream status and followers)
    void setThreadRate​(long threadRate)
    Updates ExponentialBackoffStrategy.getBaseMillis() for each of the independent listeners (i.e. stream status and followers)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • TwitchClientHelper

      public TwitchClientHelper​(com.github.twitch4j.helix.TwitchHelix twitchHelix, com.github.philippheuer.events4j.core.EventManager eventManager, java.util.concurrent.ScheduledThreadPoolExecutor executor)
      Constructor
      Parameters:
      twitchHelix - TwitchHelix
      eventManager - EventManager
      executor - ScheduledThreadPoolExecutor
  • Method Details

    • enableStreamEventListener

      @Nullable public @Nullable com.github.twitch4j.helix.domain.User enableStreamEventListener​(java.lang.String channelName)
      Enable StreamEvent Listener
      Parameters:
      channelName - Channel Name
    • enableStreamEventListener

      public java.util.Collection<com.github.twitch4j.helix.domain.User> enableStreamEventListener​(java.lang.Iterable<java.lang.String> channelNames)
      Enable StreamEvent Listener for the given channel names
      Parameters:
      channelNames - the channel names to be added
    • enableStreamEventListener

      public boolean enableStreamEventListener​(java.lang.String channelId, java.lang.String channelName)
      Enable StreamEvent Listener, without invoking a Helix API call
      Parameters:
      channelId - Channel Id
      channelName - Channel Name
      Returns:
      true if the channel was added, false otherwise
    • disableStreamEventListener

      public void disableStreamEventListener​(java.lang.String channelName)
      Disable StreamEvent Listener
      Parameters:
      channelName - Channel Name
    • disableStreamEventListener

      public void disableStreamEventListener​(java.lang.Iterable<java.lang.String> channelNames)
      Disable StreamEvent Listener for the given channel names
      Parameters:
      channelNames - the channel names to be removed
    • disableStreamEventListenerForId

      public boolean disableStreamEventListenerForId​(java.lang.String channelId)
      Disable StreamEventListener, without invoking a Helix API call
      Parameters:
      channelId - Channel Id
      Returns:
      true if the channel was removed, false otherwise
    • enableFollowEventListener

      @Nullable public @Nullable com.github.twitch4j.helix.domain.User enableFollowEventListener​(java.lang.String channelName)
      Follow Listener
      Parameters:
      channelName - Channel Name
    • enableFollowEventListener

      public java.util.Collection<com.github.twitch4j.helix.domain.User> enableFollowEventListener​(java.lang.Iterable<java.lang.String> channelNames)
      Enable Follow Listener for the given channel names
      Parameters:
      channelNames - the channel names to be added
    • enableFollowEventListener

      public boolean enableFollowEventListener​(java.lang.String channelId, java.lang.String channelName)
      Enable Follow Listener, without invoking a Helix API call
      Parameters:
      channelId - Channel Id
      channelName - Channel Name
      Returns:
      true if the channel was added, false otherwise
    • disableFollowEventListener

      public void disableFollowEventListener​(java.lang.String channelName)
      Disable Follow Listener
      Parameters:
      channelName - Channel Name
    • disableFollowEventListener

      public void disableFollowEventListener​(java.lang.Iterable<java.lang.String> channelNames)
      Disable Follow Listener for the given channel names
      Parameters:
      channelNames - the channel names to be removed
    • disableFollowEventListenerForId

      public boolean disableFollowEventListenerForId​(java.lang.String channelId)
      Disable Follow Listener, without invoking a Helix API call
      Parameters:
      channelId - Channel Id
      Returns:
      true when a previously-tracked channel was removed, false otherwise
    • setThreadRate

      public void setThreadRate​(long threadRate)
      Updates ExponentialBackoffStrategy.getBaseMillis() for each of the independent listeners (i.e. stream status and followers)
      Parameters:
      threadRate - the maximum rate of api calls per second
    • setThreadDelay

      public void setThreadDelay​(long threadDelay)
      Updates ExponentialBackoffStrategy.getBaseMillis() for each of the independent listeners (i.e. stream status and followers)
      Parameters:
      threadDelay - the minimum milliseconds delay between each api call
    • getCachedInformation

      public java.util.Optional<ChannelCache> getCachedInformation​(java.lang.String channelId)
      Get cached information for a channel's stream status and follower count.

      For this information to be valid, the respective event listeners need to be enabled for the channel.

      For thread safety, the setters on this object should not be used; only getters.

      Parameters:
      channelId - The ID of the channel whose cache is to be retrieved.
      Returns:
      ChannelCache in an optional wrapper.
    • close

      public void close()
      Close
      Specified by:
      close in interface java.lang.AutoCloseable