Class CometdWebConferencingService

java.lang.Object
org.exoplatform.webconferencing.cometd.CometdWebConferencingService
All Implemented Interfaces:
org.picocontainer.Startable

public class CometdWebConferencingService extends Object implements org.picocontainer.Startable
Created by The eXo Platform SAS.
Version:
$Id: CometdWebConferencingService.java 00000 Aug 17, 2017 pnedonosko $
Author:
Peter Nedonosko
  • Field Details

    • CALLS_CHANNEL_NAME

      public static final String CALLS_CHANNEL_NAME
      The Constant CALLS_CHANNEL_NAME.
      See Also:
    • LOGS_CHANNEL_NAME

      public static final String LOGS_CHANNEL_NAME
      The Constant LOGS_CHANNEL_NAME.
      See Also:
    • CALL_SUBSCRIPTION_CHANNEL_NAME

      public static final String CALL_SUBSCRIPTION_CHANNEL_NAME
      The Constant CALL_SUBSCRIPTION_CHANNEL_NAME.
      See Also:
    • CALL_SUBSCRIPTION_CHANNEL_NAME_ALL

      public static final String CALL_SUBSCRIPTION_CHANNEL_NAME_ALL
      The Constant CALL_SUBSCRIPTION_CHANNEL_NAME_ALL.
      See Also:
    • CALL_SUBSCRIPTION_CHANNEL_NAME_PATTERN

      public static final String CALL_SUBSCRIPTION_CHANNEL_NAME_PATTERN
      The Constant CALL_SUBSCRIPTION_CHANNEL_NAME_PATTERN.
      See Also:
    • USER_SUBSCRIPTION_CHANNEL_NAME

      public static final String USER_SUBSCRIPTION_CHANNEL_NAME
      The Constant USER_SUBSCRIPTION_CHANNEL_NAME.
      See Also:
    • USER_SUBSCRIPTION_CHANNEL_PATTERN

      public static final String USER_SUBSCRIPTION_CHANNEL_PATTERN
      The Constant USER_SUBSCRIPTION_CHANNEL_PATTERN.
      See Also:
    • USER_CACHE_NAME

      public static final String USER_CACHE_NAME
      The Constant USER_CACHE_NAME.
    • COMMAND_GET

      public static final String COMMAND_GET
      The Constant COMMAND_GET.
      See Also:
    • COMMAND_CREATE

      public static final String COMMAND_CREATE
      The Constant COMMAND_CREATE.
      See Also:
    • COMMAND_CREATE_ORIGINS

      public static final String COMMAND_CREATE_ORIGINS
      The Constant COMMAND_CREATE_ORIGINS.
      See Also:
    • COMMAND_UPDATE

      public static final String COMMAND_UPDATE
      The Constant COMMAND_UPDATE.
      See Also:
    • COMMAND_DELETE

      public static final String COMMAND_DELETE
      The Constant COMMAND_DELETE.
      See Also:
    • COMMAND_ADD_GUEST

      public static final String COMMAND_ADD_GUEST
      The Constant COMMAND_ADD_GUEST.
      See Also:
    • COMMAND_UPDATE_INVITES

      public static final String COMMAND_UPDATE_INVITES
      The Constant COMMAND_UPDATE_INVITES.
      See Also:
    • COMMAND_CHECK_INVITE

      public static final String COMMAND_CHECK_INVITE
      The Constant COMMAND_CHECK_INVITE.
      See Also:
    • COMMAND_GET_CALLS_STATE

      public static final String COMMAND_GET_CALLS_STATE
      The Constant COMMAND_GET_CALLS_STATE.
      See Also:
    • COMMAND_GET_ORG_IDENTITIES

      public static final String COMMAND_GET_ORG_IDENTITIES
      The Constant COMMAND_GET_ORG_IDENTITIES.
      See Also:
    • EVENT_CALL_LEAVED

      public static final String EVENT_CALL_LEAVED
      The Constant EVENT_CALL_LEAVED.
      See Also:
    • EVENT_CALL_JOINED

      public static final String EVENT_CALL_JOINED
      The Constant EVENT_CALL_JOINED.
      See Also:
    • EVENT_CALL_STATE

      public static final String EVENT_CALL_STATE
      The Constant EVENT_CALL_STATE.
      See Also:
    • LOG_OK

      public static final String LOG_OK
      The Constant LOG_OK.
      See Also:
    • MIN_THREADS

      public static final int MIN_THREADS
      Base minimum number of threads for remote calls' thread executors.
      See Also:
    • MIN_MAX_THREADS

      public static final int MIN_MAX_THREADS
      Minimal number of threads maximum possible for remote calls' thread executors.
      See Also:
    • THREAD_IDLE_TIME

      public static final int THREAD_IDLE_TIME
      Thread idle time for thread executors (in seconds).
      See Also:
    • CALL_MAX_FACTOR

      public static final int CALL_MAX_FACTOR
      Maximum threads per CPU for thread executors of user call channel.
      See Also:
    • CALL_QUEUE_FACTOR

      public static final int CALL_QUEUE_FACTOR
      Queue size per CPU for thread executors of user call channel.
      See Also:
    • CALL_THREAD_PREFIX

      public static final String CALL_THREAD_PREFIX
      Thread name used for calls executor.
      See Also:
    • webConferencing

      protected final WebConferencingService webConferencing
      The web conferencing.
    • exoBayeux

      protected final org.mortbay.cometd.continuation.EXoContinuationBayeux exoBayeux
      The exo bayeux.
    • service

      The service.
    • organization

      protected final org.exoplatform.services.organization.OrganizationService organization
      The organization.
    • identityRegistry

      protected final org.exoplatform.services.security.IdentityRegistry identityRegistry
      The identity registry.
    • callLogs

      protected final CallLogService callLogs
      The call logs.
    • callHandlers

      protected final ExecutorService callHandlers
      The call handlers.
    • leaveGraceTimer

      protected final ScheduledExecutorService leaveGraceTimer
      The timer delaying what follows the end of a call window's connection by the leave grace time.
    • usersCache

      protected final org.exoplatform.services.cache.ExoCache<String, CometdWebConferencingService.UserCallProxy> usersCache
      Cache of connected users.
  • Constructor Details

    • CometdWebConferencingService

      public CometdWebConferencingService(org.exoplatform.services.security.IdentityRegistry identityRegistry, org.exoplatform.services.organization.OrganizationService organization, WebConferencingService webConferencing, org.mortbay.cometd.continuation.EXoContinuationBayeux exoBayeux, org.exoplatform.services.cache.CacheService cacheService, CallLogService callLogs)
      Instantiates a new CometD interaction service for WebConferencing.
      Parameters:
      identityRegistry - the identity registry
      organization - the organization
      webConferencing - the web conferencing
      exoBayeux - the exo bayeux
      cacheService - the cache service
      callLogs - the call logs
  • Method Details

    • afterLeaveGrace

      protected void afterLeaveGrace(Runnable task)
      Runs a task once the leave grace time passed (see WebConferencingService.getLeaveGraceTime()): a call window whose connection ended, reloaded or reconnected, joins the call again meanwhile, which keeps its user in the call.
      Parameters:
      task - the task
    • isUpdatableState

      protected static boolean isUpdatableState(String state)
      Tells if a client can set this state on a call through the update command.
      Parameters:
      state - the state sent by the client
      Returns:
      true if the state is a call or a participant state the update command applies
    • stopCallOfRemovedChannel

      protected void stopCallOfRemovedChannel(String callId, long removedAt) throws WebConferencingException
      Stops a call whose channel has no subscriber left: its parties are assumed gone. A call read as stopped, as the leave of its last party leaves it, is not stopped again, nor a call started again since the channel was removed, its start read within WebConferencingService.LAST_DATE_PRECISION. The read takes no lock: a leave still running on another handler thread can stop the call after this read.
      Parameters:
      callId - the call id
      removedAt - when the channel was removed, in milliseconds
      Throws:
      WebConferencingException - if the call cannot be read or stopped
    • updateCallState

      protected CallInfo updateCallState(String id, String state, String currentUserId, String clientId, String sessionId) throws WebConferencingException
      Applies a state sent by a client to a call: a participant state applies to currentUserId, which is the exoId of the client's message. A decline applies only to the user the Cometd session was opened for.
      Parameters:
      id - the call id
      state - the state, one of isUpdatableState(String)
      currentUserId - the exoId of the client's message
      clientId - the client id
      sessionId - the id of the Cometd session the message came from
      Returns:
      the call info, null if the call was not found
      Throws:
      ParticipantNotFoundException - if a decline names a user the session was not opened for
      WebConferencingException - if the call cannot be updated
    • start

      public void start()
      Specified by:
      start in interface org.picocontainer.Startable
    • stop

      public void stop()
      Ends the leave grace timer, then the call commands: no new command starts, and the stop waits up to CALL_STOP_WAIT_SECONDS seconds for the commands already submitted, a leave or a stop of a call among them, so that they reach the store before the node goes down. A command still running past that wait is not waited for: its thread is a daemon and ends with the JVM. A command submitted after the stop is dropped.
      Specified by:
      stop in interface org.picocontainer.Startable
    • getCometdServerPath

      public String getCometdServerPath()
      Gets the cometd server path.
      Returns:
      the cometd server path
    • getUserToken

      public String getUserToken(String userId)
      Gets the user token.
      Parameters:
      userId - the user id
      Returns:
      the user token
    • isSessionUser

      protected boolean isSessionUser(String userId, org.cometd.bayeux.server.ServerSession session)
      Tells whether a user is the one the CometD session was opened for, as the handshake recorded it after checking the user's token.
      Parameters:
      userId - the user a client message names
      session - the server session the message came from
      Returns:
      true if the session was opened for that user, false otherwise
    • currentUserId

      protected String currentUserId(org.cometd.bayeux.server.ServerMessage message)
      Current user id.
      Parameters:
      message - the message
      Returns:
      the string, if user cannot be defined it will be IdentityConstants.ANONIM
    • channelUserId

      protected String channelUserId(String channelId) throws IndexOutOfBoundsException
      Channel user id. It's assumed an user channel USER_SUBSCRIPTION_CHANNEL_NAME.
      Parameters:
      channelId - the channel id
      Returns:
      the string
      Throws:
      IndexOutOfBoundsException - if channel id doesn't look like an user channel
    • channelsAsString

      protected String channelsAsString(Set<org.cometd.bayeux.server.ServerChannel> channels)
      Channels as string.
      Parameters:
      channels - the channels
      Returns:
      the string
    • callId

      protected String callId(String type, String info)
      Call id.
      Parameters:
      type - the type
      info - the id
      Returns:
      the string
    • asString

      protected String asString(Object obj)
      Return object if it's String instance or null if it is not.
      Parameters:
      obj - the obj
      Returns:
      the string or null
    • asBoolean

      protected boolean asBoolean(Object obj)
      Return true if it's Boolean instance of TRUE or false if it is not.
      Parameters:
      obj - the obj
      Returns:
      the boolean
    • asList

      protected <T> List<T> asList(Object obj, Class<T> type)
      As list.
      Type Parameters:
      T - the generic type
      Parameters:
      obj - the obj
      type - the type
      Returns:
      the list
    • invitedIdentitiesFromJson

      protected List<InvitedIdentity> invitedIdentitiesFromJson(Object obj)
      Invited identities list.
      Parameters:
      obj - the obj
      Returns:
      the list
    • createThreadExecutor

      protected ExecutorService createThreadExecutor(String threadNamePrefix, int maxFactor, int queueFactor)
      Create a new thread executor service.
      Parameters:
      threadNamePrefix - the thread name prefix
      maxFactor - - max processes per CPU core
      queueFactor - - queue size per CPU core
      Returns:
      the executor service