Class MongoStore

java.lang.Object
io.antmedia.datastore.db.DataStore
io.antmedia.datastore.db.MongoStore

public class MongoStore extends DataStore
  • Field Details

  • Constructor Details

  • Method Details

    • deleteOldStreamIdIndex

      @Deprecated(since="2.12.0", forRemoval=true) public void deleteOldStreamIdIndex()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • deleteDuplicateStreamIds

      public void deleteDuplicateStreamIds(com.mongodb.client.MongoCollection<Broadcast> collection)
    • migrateConferenceRoomsToBroadcasts

      public void migrateConferenceRoomsToBroadcasts()
      Description copied from class: DataStore
      Move ConferenceRoom to Broadcast
      Specified by:
      migrateConferenceRoomsToBroadcasts in class DataStore
    • getMongoConnectionUri

      public static String getMongoConnectionUri(String host, String username, String password)
    • save

      public String save(Broadcast broadcast)
      Specified by:
      save in class DataStore
    • get

      public Broadcast get(String id)
      Description copied from class: DataStore
      Return the broadcast in data store
      Specified by:
      get in class DataStore
      Returns:
      broadcast
    • getVoD

      public VoD getVoD(String id)
      Description copied from class: DataStore
      Return the vod by id
      Specified by:
      getVoD in class DataStore
      Returns:
      Vod object
    • updateStatus

      public boolean updateStatus(String id, String status)
      Specified by:
      updateStatus in class DataStore
    • updateVoDProcessStatus

      public boolean updateVoDProcessStatus(String id, String status)
      Specified by:
      updateVoDProcessStatus in class DataStore
    • addEndpoint

      public boolean addEndpoint(String id, Endpoint endpoint)
      Specified by:
      addEndpoint in class DataStore
    • removeEndpoint

      public boolean removeEndpoint(String id, Endpoint endpoint, boolean checkRTMPUrl)
      Specified by:
      removeEndpoint in class DataStore
    • removeAllEndpoints

      public boolean removeAllEndpoints(String id)
      Specified by:
      removeAllEndpoints in class DataStore
    • getBroadcastCount

      public long getBroadcastCount()
      Description copied from class: DataStore
      Use getTotalBroadcastNumber
      Specified by:
      getBroadcastCount in class DataStore
    • delete

      public boolean delete(String id)
      Specified by:
      delete in class DataStore
    • checkIfRegexValid

      private boolean checkIfRegexValid(String regex)
    • getConnectionEvents

      public List<ConnectionEvent> getConnectionEvents(String streamId, String subscriberId, int offset, int size)
      Description copied from class: DataStore
      Get connection events for a specific streamId and subscriberId ConnectionEvents are recorded if AppSettings.isWriteSubscriberEventsToDatastore() is true
      Specified by:
      getConnectionEvents in class DataStore
      Returns:
    • getBroadcastList

      public List<Broadcast> getBroadcastList(int offset, int size, String type, String sortBy, String orderBy, String search)
      Description copied from class: DataStore
      Returns the Broadcast List in order
      Specified by:
      getBroadcastList in class DataStore
      Parameters:
      offset - the number of items to skip
      size - batch size
      type - can get "liveStream" or "ipCamera" or "streamSource" or "VoD" values. Default is getting all broadcast types.
      sortBy - can get "name" or "date" or "status" values
      orderBy - can get "desc" or "asc"
      search - is used for searching in streamIds and names of the stream
      Returns:
    • getDataStore

      public dev.morphia.Datastore getDataStore()
    • getExternalStreamsList

      public List<Broadcast> getExternalStreamsList()
      Specified by:
      getExternalStreamsList in class DataStore
    • close

      public void close(boolean deleteDB)
      Description copied from class: DataStore
      Closes the database
      Specified by:
      close in class DataStore
      Parameters:
      deleteDB - if it's true, it also deletes the db and closes
    • addVod

      public String addVod(VoD vod)
      Description copied from class: DataStore
      Add VoD record to the datastore
      Specified by:
      addVod in class DataStore
      Returns:
      the id of the VoD if it's successful or it returns null if it's failed
    • getVodList

      public List<VoD> getVodList(int offset, int size, String sortBy, String orderBy, String filterStreamId, String search)
      Description copied from class: DataStore
      Returns the VoD List in order
      Specified by:
      getVodList in class DataStore
      Parameters:
      offset - : the number of items to skip
      size - : batch size
      sortBy - can get "name" or "date" values
      orderBy - can get "desc" or "asc"
      filterStreamId - is used for filtering the vod by stream id. If it's null or empty, it's not used
      search - is used for searching in vodIds and names of the vods.
      Returns:
    • deleteVod

      public boolean deleteVod(String id)
      Specified by:
      deleteVod in class DataStore
    • getTotalVodNumber

      public long getTotalVodNumber()
      Specified by:
      getTotalVodNumber in class DataStore
    • fetchUserVodList

      public int fetchUserVodList(File userfile)
      Description copied from class: DataStore
      Gets the video files under the fileDir directory parameter and saves them to the datastore as USER_VOD in Vod class
      Specified by:
      fetchUserVodList in class DataStore
      Returns:
      number of files that are saved to datastore
    • getTotalBroadcastNumber

      public long getTotalBroadcastNumber()
      Specified by:
      getTotalBroadcastNumber in class DataStore
    • getPartialBroadcastNumber

      public long getPartialBroadcastNumber(String search)
      Description copied from class: DataStore
      Returns the number of broadcasts which contains searched string
      Specified by:
      getPartialBroadcastNumber in class DataStore
      Parameters:
      search - is used for searching in streamIds and names of the stream
      Returns:
    • getPartialVodNumber

      public long getPartialVodNumber(String search)
      Description copied from class: DataStore
      Returns the number of vods which contains searched string
      Specified by:
      getPartialVodNumber in class DataStore
      Parameters:
      search - is used for searching in vodIds and names of the vods
      Returns:
    • getVodDatastore

      public dev.morphia.Datastore getVodDatastore()
    • setVodDatastore

      public void setVodDatastore(dev.morphia.Datastore vodDatastore)
    • getActiveBroadcastCount

      public long getActiveBroadcastCount()
      Description copied from class: DataStore
      Return the number of active broadcasts in the server
      Specified by:
      getActiveBroadcastCount in class DataStore
      Returns:
    • saveDetection

      public void saveDetection(String id, long timeElapsed, List<TensorFlowObject> detectedObjects)
      Specified by:
      saveDetection in class DataStore
    • getDetectionList

      public List<TensorFlowObject> getDetectionList(String idFilter, int offsetSize, int batchSize)
      Specified by:
      getDetectionList in class DataStore
    • getDetection

      public List<TensorFlowObject> getDetection(String id)
      Specified by:
      getDetection in class DataStore
    • getObjectDetectedTotal

      public long getObjectDetectedTotal(String id)
      Description copied from class: DataStore
      Returns the total number of detected objects in the stream
      Specified by:
      getObjectDetectedTotal in class DataStore
      Returns:
      total number of detected objects
    • updateBroadcastFields

      public boolean updateBroadcastFields(String streamId, BroadcastUpdate broadcast)
      Description copied from class: DataStore
      Updates the Broadcast objects fields if it's not null. The updated fields are as follows name, description, userName, password, IP address, streamUrl
      Specified by:
      updateBroadcastFields in class DataStore
      Returns:
    • prepareFields

      private void prepareFields(BroadcastUpdate broadcast, List<dev.morphia.query.updates.UpdateOperator> updates)
    • updateHLSViewerCountLocal

      public boolean updateHLSViewerCountLocal(String streamId, int diffCount)
      Specified by:
      updateHLSViewerCountLocal in class DataStore
    • updateDASHViewerCountLocal

      public boolean updateDASHViewerCountLocal(String streamId, int diffCount)
      Specified by:
      updateDASHViewerCountLocal in class DataStore
    • updateWebRTCViewerCountLocal

      public boolean updateWebRTCViewerCountLocal(String streamId, boolean increment)
      Specified by:
      updateWebRTCViewerCountLocal in class DataStore
    • updateRtmpViewerCountLocal

      public boolean updateRtmpViewerCountLocal(String streamId, boolean increment)
      Specified by:
      updateRtmpViewerCountLocal in class DataStore
    • updateViewerField

      private boolean updateViewerField(String streamId, boolean increment, String fieldName)
    • saveStreamInfo

      public void saveStreamInfo(StreamInfo streamInfo)
      Description copied from class: DataStore
      Saves the stream info to the db
      Specified by:
      saveStreamInfo in class DataStore
    • getStreamInfoList

      public List<StreamInfo> getStreamInfoList(String streamId)
      Description copied from class: DataStore
      Returns stream info list added to db
      Specified by:
      getStreamInfoList in class DataStore
      Returns:
    • clearStreamInfoList

      public void clearStreamInfoList(String streamId)
      Description copied from class: DataStore
      Remove the stream info list from db
      Specified by:
      clearStreamInfoList in class DataStore
    • saveToken

      public boolean saveToken(Token token)
      Description copied from class: DataStore
      saves token to store
      Specified by:
      saveToken in class DataStore
      Parameters:
      token - - created token
      Returns:
      true/false
    • validateToken

      public Token validateToken(Token token)
      Description copied from class: DataStore
      Validates token
      Specified by:
      validateToken in class DataStore
      Returns:
      token if validated, null if not
    • revokeTokens

      public boolean revokeTokens(String streamId)
      Description copied from class: DataStore
      Delete all tokens of the stream
      Specified by:
      revokeTokens in class DataStore
    • listAllTokens

      public List<Token> listAllTokens(String streamId, int offset, int size)
      Description copied from class: DataStore
      Lists all tokens of requested stream
      Specified by:
      listAllTokens in class DataStore
      Returns:
      lists of tokens
    • listAllSubscribers

      public List<Subscriber> listAllSubscribers(String streamId, int offset, int size)
      Description copied from class: DataStore
      Lists all subscribers of requested stream
      Specified by:
      listAllSubscribers in class DataStore
      Returns:
      lists of subscribers
    • addSubscriber

      public boolean addSubscriber(String streamId, Subscriber subscriber)
      Description copied from class: DataStore
      adds subscriber to the datastore for this stream
      Specified by:
      addSubscriber in class DataStore
      subscriber - - subscriber to be added
    • addConnectionEvent

      protected boolean addConnectionEvent(ConnectionEvent event)
      Specified by:
      addConnectionEvent in class DataStore
    • deleteSubscriber

      public boolean deleteSubscriber(String streamId, String subscriberId)
      Description copied from class: DataStore
      deletes subscriber from the datastore for this stream
      Specified by:
      deleteSubscriber in class DataStore
      subscriberId - - id of the subsciber to be deleted
    • blockSubscriber

      public boolean blockSubscriber(String streamId, String subscriberId, String blockedType, int seconds)
      Description copied from class: DataStore
      blocks subscribe from playing or publishing
      Specified by:
      blockSubscriber in class DataStore
      subscriberId - - id of the subsciber to be blocked
      blockedType - - it can be the value of the static field Subscriber.PLAY_TYPE, Subscriber.PUBLISH_TYPE, Subscriber.PUBLISH_AND_PLAY_TYPE publish, play, publish_play
      seconds - - duration of seconds to block the user
    • revokeSubscribers

      public boolean revokeSubscribers(String streamId)
      Description copied from class: DataStore
      deletes all subscriber from the datastore for this stream
      Specified by:
      revokeSubscribers in class DataStore
    • getSubscriberCacheKey

      public String getSubscriberCacheKey(String streamId, String subscriberId)
    • getSubscriber

      public Subscriber getSubscriber(String streamId, String subscriberId)
      Description copied from class: DataStore
      gets subscriber from the datastore
      Specified by:
      getSubscriber in class DataStore
      subscriberId - - id of the subsciber to be deleted
    • resetSubscribersConnectedStatus

      public boolean resetSubscribersConnectedStatus()
      Description copied from class: DataStore
      sets the connection status of all the subscribers false in the datastore called after an ungraceful shutdown
      Specified by:
      resetSubscribersConnectedStatus in class DataStore
    • setMp4Muxing

      public boolean setMp4Muxing(String streamId, int enabled)
      Description copied from class: DataStore
      enables or disables mp4 muxing for the stream
      Specified by:
      setMp4Muxing in class DataStore
      Parameters:
      streamId - - id of the stream
      enabled - 1 means enabled, -1 means disabled, 0 means no setting for the stream
    • setWebMMuxing

      public boolean setWebMMuxing(String streamId, int enabled)
      Description copied from class: DataStore
      enables or disables WebM muxing for the stream
      Specified by:
      setWebMMuxing in class DataStore
      Parameters:
      streamId - - id of the stream
      enabled - 1 means enabled, -1 means disabled, 0 means no setting for the stream
    • setRecordMuxing

      private boolean setRecordMuxing(String streamId, int enabled, String field)
    • deleteToken

      public boolean deleteToken(String tokenId)
      Description copied from class: DataStore
      Delete specific token
      Specified by:
      deleteToken in class DataStore
      Parameters:
      tokenId - id of the token
    • getToken

      public Token getToken(String tokenId)
      Description copied from class: DataStore
      retrieve specific token
      Specified by:
      getToken in class DataStore
      Parameters:
      tokenId - id of the token
    • getLocalLiveBroadcastCount

      public long getLocalLiveBroadcastCount(String hostAddress)
      Specified by:
      getLocalLiveBroadcastCount in class DataStore
    • getLocalLiveBroadcasts

      public List<Broadcast> getLocalLiveBroadcasts(String hostAddress)
      Specified by:
      getLocalLiveBroadcasts in class DataStore
    • createP2PConnection

      public boolean createP2PConnection(P2PConnection conn)
      Description copied from class: DataStore
      Creates new P2PConnection
      Specified by:
      createP2PConnection in class DataStore
      Parameters:
      conn - - P2PConnection object
      Returns:
      boolean - success
    • deleteP2PConnection

      public boolean deleteP2PConnection(String streamId)
      Description copied from class: DataStore
      Deletes a P2PConnection
      Specified by:
      deleteP2PConnection in class DataStore
      Returns:
      boolean - success
    • getP2PConnection

      public P2PConnection getP2PConnection(String streamId)
      Description copied from class: DataStore
      Get the P2PConnection by streamId
      Specified by:
      getP2PConnection in class DataStore
      Parameters:
      streamId - - stream id for P2PConnection
      Returns:
      P2PConnection - if exist else null
    • addSubTrack

      public boolean addSubTrack(String mainTrackId, String subTrackId)
      Specified by:
      addSubTrack in class DataStore
      Parameters:
      mainTrackId - - main track id
      subTrackId - - main track id
      Returns:
      boolean - success
    • removeSubTrack

      public boolean removeSubTrack(String mainTrackId, String subTrackId)
      Specified by:
      removeSubTrack in class DataStore
      Parameters:
      mainTrackId - - main track id
      subTrackId - - main track id
      Returns:
      boolean - success
    • resetBroadcasts

      public int resetBroadcasts(String hostAddress)
      Description copied from class: DataStore
      Resets the broadcasts in the database. It sets number of viewers to zero. It also delete the stream if it's zombi stream
      Specified by:
      resetBroadcasts in class DataStore
    • getTotalWebRTCViewersCount

      public int getTotalWebRTCViewersCount()
      Description copied from class: DataStore
      This is used to get total number of WebRTC viewers
      Specified by:
      getTotalWebRTCViewersCount in class DataStore
    • saveViewerInfo

      public void saveViewerInfo(WebRTCViewerInfo info)
      Description copied from class: DataStore
      This is used to save WebRTC Viewer Info to datastore
      Specified by:
      saveViewerInfo in class DataStore
      Parameters:
      info - information for the WebRTC Viewer
    • getWebRTCViewerList

      public List<WebRTCViewerInfo> getWebRTCViewerList(int offset, int size, String sortBy, String orderBy, String search)
      Description copied from class: DataStore
      Get list of webrtc viewers
      Specified by:
      getWebRTCViewerList in class DataStore
      Returns:
      list of webrtc viewers
    • deleteWebRTCViewerInfo

      public boolean deleteWebRTCViewerInfo(String viewerId)
      Description copied from class: DataStore
      This is used to delete a WebRTC Viewer Info from datastore
      Specified by:
      deleteWebRTCViewerInfo in class DataStore
      Parameters:
      viewerId - WebRTC Viewer Id
    • updateStreamMetaData

      public boolean updateStreamMetaData(String streamId, String metaData)
      This is used to update meta data for a bradcast
      Specified by:
      updateStreamMetaData in class DataStore
      Parameters:
      streamId - id for the broadcast
      metaData - new meta data
    • getSubscriberDatastore

      public dev.morphia.Datastore getSubscriberDatastore()
    • getSubscriberMetaData

      public SubscriberMetadata getSubscriberMetaData(String subscriberId)
      Description copied from class: DataStore
      Get subscriber metadata
      Specified by:
      getSubscriberMetaData in class DataStore
      Returns:
    • putSubscriberMetaData

      public void putSubscriberMetaData(String subscriberId, SubscriberMetadata metadata)
      Description copied from class: DataStore
      Put subscriber metadata. It overwrites the metadata, if you need to update something, first get the DataStore.getSubscriberMetaData(String) , update it and put it
      Specified by:
      putSubscriberMetaData in class DataStore
    • getConferenceRoomDatastore

      public dev.morphia.Datastore getConferenceRoomDatastore()
    • getSubtracks

      public List<Broadcast> getSubtracks(String mainTrackId, int offset, int size, String role)
      Description copied from class: DataStore
      Get the subtracks of the main track
      Specified by:
      getSubtracks in class DataStore
      Parameters:
      mainTrackId - the main track to get the subtracks
      offset - the offset to get the subtracks
      size - number of items to get
      role - the role of the subtracks for role based streaming especially in conferences. It can be null
      Returns:
    • getSubtracks

      public List<Broadcast> getSubtracks(String mainTrackId, int offset, int size, String role, String status)
      Description copied from class: DataStore
      Get the subtracks of the main track
      Specified by:
      getSubtracks in class DataStore
      Parameters:
      mainTrackId - the main track to get the subtracks
      offset - the offset to get the subtracks
      size - number of items to get
      role - the role of the subtracks for role based streaming especially in conferences. It can be null
      status - the status of the stream broadcasting, finished etc. It can be null
      Returns:
    • getFilterForSubtracks

      private dev.morphia.query.filters.LogicalFilter getFilterForSubtracks(String mainTrackId, String role, String status)
    • getSubtrackCount

      public long getSubtrackCount(String mainTrackId, String role, String status)
      Description copied from class: DataStore
      Get the count of subtracks
      Specified by:
      getSubtrackCount in class DataStore
      Parameters:
      mainTrackId - the main track to get the subtracks
      role - the role of the subtracks for role based streaming especially in conferences
      Returns:
      number of subtracks
    • getActiveSubtracks

      public List<Broadcast> getActiveSubtracks(String mainTrackId, String role)
      Description copied from class: DataStore
      Get of active subtracks. If subtrack is stucked in broadcasting or preparing, it will not return it. This method is generally not recommended to use because it can be very costly. It's implemented for the poll mechanism in Subtracks and poll mechanismi will be replaced with event mechanism
      Specified by:
      getActiveSubtracks in class DataStore
      Returns:
    • getActiveSubtracksCount

      public long getActiveSubtracksCount(String mainTrackId, String role)
      Description copied from class: DataStore
      Get the count of active subtracks. If subtrack is stucked in broadcasting or preparing, it will not count it.
      Specified by:
      getActiveSubtracksCount in class DataStore
      Returns:
    • hasSubtracks

      public boolean hasSubtracks(String streamId)
      Specified by:
      hasSubtracks in class DataStore
      Returns:
      If the stream has subtracks, it return true. If not, it returns false
    • getCacheManager

      public CaffeineCacheManager getCacheManager()
    • getSubscriberCache

      public CaffeineCache getSubscriberCache()