Package com.castlabs.sdk.broadpeak

# Class SessionManager

java.lang.Object
com.castlabs.sdk.broadpeak.SessionManager

public class SessionManager extends Object
Container for multiple `SessionApi`. Provides methods for indexing them by url and config in a convenient and quick manner.

Note that URLs shall be unique. As otherwise a collision might occur.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static Pattern`
  `TOKEN_URL_PATTERN`
  Regular expression to extract the session id out of a redirected Broadpeak URL.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SessionManager(com.castlabs.sdk.broadpeak.PlayerInfoApi infoApi)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `SessionWrapper`
  `addSession(PlayerConfig config)`
  Create and adds the a session
  `void`
  `clear()`
  Removes all Sessions
  `boolean`
  `contains(PlayerConfig config)`
  `static String`
  `extractBroadpeakToken(String url)`
  `SessionWrapper`
  `getSessionByConfig(PlayerConfig config)`
  Returns the Session which contains the provided `PlayerConfig`
  `Collection<SessionWrapper>`
  `getSessions()`
  `SessionWrapper`
  `maybeUpdateUrl(Request request)`
  Updates the given URL in case it contains a token and it needs to be replaced by an updated one due to a renewal.
  `void`
  `onCurrentSessionChanged(SessionWrapper newSession)`
  `void`
  `removeSession(SessionWrapper session)`
  Removes the provided session
  `void`
  `renew(SessionWrapper wrapper)`
  `int`
  `size()`

  ### Methods inherited from class java.lang.Object

  `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### TOKEN_URL_PATTERN

    public static Pattern TOKEN_URL_PATTERN
    Regular expression to extract the session id out of a redirected Broadpeak URL. The default value is: `Pattern.compile("bpk-token/([^/]+)/")` and can be customised if needed.

- ## Constructor Details

  - ### SessionManager

    public SessionManager(@NonNull com.castlabs.sdk.broadpeak.PlayerInfoApi infoApi)

- ## Method Details

  - ### removeSession

    public void removeSession(@NonNull SessionWrapper session)
    Removes the provided session
    Parameters:
      `session` - the session to remove

  - ### getSessionByConfig

    @Nullable public SessionWrapper getSessionByConfig(PlayerConfig config)
    Returns the Session which contains the provided `PlayerConfig`
    Parameters:
      `config` - the config for which to return the Session
    Returns:
      the Session

  - ### getSessions

    @NonNull public Collection<SessionWrapper> getSessions()
    Returns:
      all Sessions

  - ### clear

    public void clear()
    Removes all Sessions

  - ### size

    public int size()
    Returns:
      the number of sessions

  - ### contains

    public boolean contains(@NonNull PlayerConfig config)
    Parameters:
      `config` - the config to look for
    Returns:
      whether the provided configuration has a linked Session to it

  - ### renew

    public void renew(SessionWrapper wrapper)

  - ### addSession

    public SessionWrapper addSession(PlayerConfig config)
    Create and adds the a session
    Parameters:
      `config` - The PlayerConfig to create the session
    Returns:
      The session that has been just created

  - ### maybeUpdateUrl

    public SessionWrapper maybeUpdateUrl(Request request) throws BroadpeakSessionException, IOException
    Updates the given URL in case it contains a token and it needs to be replaced by an updated one due to a renewal. In case the renewal hasn't yet been completed, it will wait for it.
    Parameters:
      `request` - the request of which to update the URL
    Throws:
      `BroadpeakSessionException`
      `IOException`

  - ### onCurrentSessionChanged

    public void onCurrentSessionChanged(SessionWrapper newSession)

  - ### extractBroadpeakToken

    @Nullable public static String extractBroadpeakToken(@NonNull String url)