Package io.antmedia.datastore.db
Class MongoStore
java.lang.Object
io.antmedia.datastore.db.DataStore
io.antmedia.datastore.db.MongoStore
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final intstatic final intprivate Objectprivate dev.morphia.Datastoreprivate static final Stringprivate static final Stringprivate static final Stringprivate dev.morphia.Datastoreprivate Objectprivate dev.morphia.Datastoreprivate static final Stringprivate static final Stringstatic final Stringprotected static org.slf4j.Loggerprivate static final Stringprivate static final Stringprivate com.mongodb.client.MongoClientstatic final Stringprivate static final Stringprivate static final Stringprivate Objectprivate static final Stringprivate static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intstatic final intstatic final Stringprivate dev.morphia.Datastoreprivate Objectprivate static final Stringprivate dev.morphia.Datastoreprivate Objectprivate static final Stringprivate static final Stringstatic final Stringprivate dev.morphia.Datastoreprivate Objectprivate static final StringFields inherited from class io.antmedia.datastore.db.DataStore
appSettings, available, MAX_ITEM_IN_ONE_LIST, REPLACE_CHARS_REGEX, TOTAL_WEBRTC_VIEWER_COUNT_CACHE_TIME, totalWebRTCViewerCount, totalWebRTCViewerCountLastUpdateTime -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanaddEndpoint(String id, Endpoint endpoint) booleanaddSubscriber(String streamId, Subscriber subscriber) adds subscriber to the datastore for this streamAdd VoD record to the datastorebooleanblockSubscriber(String streamId, String subscriberId, String blockedType, int seconds) blocks subscribe from playing or publishingprivate booleancheckIfRegexValid(String regex) voidclearStreamInfoList(String streamId) Remove the stream info list from dbvoidclose(boolean deleteDB) Closes the databasebooleanCreates new P2PConnectionbooleanvoiddeleteDuplicateStreamIds(com.mongodb.client.MongoCollection<Broadcast> collection) booleandeleteP2PConnection(String streamId) Deletes a P2PConnectionbooleandeleteSubscriber(String streamId, String subscriberId) deletes subscriber from the datastore for this streambooleandeleteToken(String tokenId) Delete specific tokenbooleanintfetchUserVodList(File userfile) Gets the video files under thefileDirdirectory parameter and saves them to the datastore as USER_VOD inVodclassReturn the broadcast in data storelongReturn the number of active broadcasts in the servergetActiveSubtracks(String mainTrackId, int offset, int size, String role) Get active subtracks with pagination.getActiveSubtracks(String mainTrackId, String role) Get of active subtracks.longgetActiveSubtracksCount(String mainTrackId, String role) Get the count of active subtracks.getBroadcastCacheKey(String streamId) getBroadcastList(int offset, int size, String type, String sortBy, String orderBy, String search) Returns the Broadcast List in orderdev.morphia.DatastorelonggetConnectedSubscriberCount(String streamId) Returns the number of the subscribers of requested streamgetConnectedSubscribers(String streamId, int offset, int size) Lists connected subscribers of requested streamgetConnectionEvents(String streamId, String subscriberId, int offset, int size) Get connection events for a specific streamId and subscriberId ConnectionEvents are recorded ifAppSettings.isWriteSubscriberEventsToDatastore()is truedev.morphia.Datastoreprivate dev.morphia.query.filters.LogicalFiltergetFilterForSubtracks(String mainTrackId, String role, String status) longgetLocalLiveBroadcastCount(String hostAddress) getLocalLiveBroadcasts(String hostAddress) static StringgetP2PConnection(String streamId) Get the P2PConnection by streamIdlonggetPartialBroadcastNumber(String search) Returns the number of broadcasts which contains searched stringlonggetPartialVodNumber(String search) Returns the number of vods which contains searched stringgetStreamInfoList(String streamId) Returns stream info list added to dbgetSubscriber(String streamId, String subscriberId) gets subscriber from the datastoregetSubscriberCacheKey(String streamId, String subscriberId) dev.morphia.DatastoregetSubscriberMetaData(String subscriberId) Get subscriber metadatalonggetSubtrackCount(String mainTrackId, String role, String status) Get the count of subtracksgetSubtracks(String mainTrackId, int offset, int size, String role) Get the subtracks of the main trackgetSubtracks(String mainTrackId, int offset, int size, String role, String status, String sortBy, String orderBy, String search) Get the subtracks of the main trackretrieve specific tokenlonglongintThis is used to get total number of WebRTC viewersReturn the vod by iddev.morphia.DatastoregetVodList(int offset, int size, String sortBy, String orderBy, String filterStreamId, String search) Returns the VoD List in orderbooleanhasSubtracks(String streamId) listAllSubscribers(String streamId, int offset, int size) Lists all subscribers of requested streamlistAllTokens(String streamId, int offset, int size) Lists all tokens of requested streamprivate voidprepareFields(BroadcastUpdate broadcast, List<dev.morphia.query.updates.UpdateOperator> updates, Broadcast cachedBroadcast) voidputSubscriberMetaData(String subscriberId, SubscriberMetadata metadata) Put subscriber metadata.private voidrecordQueryDuration(long startTime, String operationName) booleanbooleanremoveEndpoint(String id, Endpoint endpoint, boolean checkRTMPUrl) intresetBroadcasts(String hostAddress) Resets the broadcasts in the database.booleansets the connection status of all the subscribers false in the datastore called after an ungraceful shutdownbooleanrevokeSubscribers(String streamId) deletes all subscriber from the datastore for this streambooleanrevokeTokens(String streamId) Delete all tokens of the streamvoidsaveStreamInfo(StreamInfo streamInfo) Saves the stream info to the dbbooleansaves token to storebooleansetMp4Muxing(String streamId, int enabled) enables or disables mp4 muxing for the streamprivate booleansetRecordMuxing(String streamId, int enabled, String field) voidsetVodDatastore(dev.morphia.Datastore vodDatastore) booleansetWebMMuxing(String streamId, int enabled) enables or disables WebM muxing for the streambooleanupdateBroadcastFields(String streamId, BroadcastUpdate broadcast) Updates the Broadcast objects fields if it's not null.booleanupdateDASHViewerCountLocal(String streamId, int diffCount) booleanupdateHLSViewerCountLocal(String streamId, int diffCount) booleanupdateRtmpViewerCountLocal(String streamId, boolean increment) booleanupdateStatus(String id, String status) booleanupdateStreamMetaData(String streamId, String metaData) This is used to update meta data for a bradcastprivate booleanupdateViewerField(String streamId, boolean increment, String fieldName) booleanupdateVoDProcessStatus(String id, String status) booleanupdateWebRTCViewerCountLocal(String streamId, boolean increment) validateToken(Token token) Validates tokenMethods inherited from class io.antmedia.datastore.db.DataStore
addQueryTime, addSubscriberConnectionEvent, get, getActiveBroadcastCount, getActiveBroadcastList, getAverageQueryTimeMs, getBroadcastCount, getConnectionEventListFromCollection, getExecutedQueryCount, getSubscriber, getToken, getTotalBroadcastNumber, getTotalVodNumber, getTotalWebRTCViewersCount, getVoD, getVodListV2, handleConnectionEvent, isAvailable, isSubscriberConnected, listAllSubscribers, listAllTokens, saveBroadcast, searchOnServer, searchOnServerVod, setAppSettings, showWarningIfElapsedTimeIsMoreThanThreshold, sortAndCropBroadcastList, sortAndCropVodList, updateDASHViewerCount, updateHLSViewerCount, updateRtmpViewerCount, updateStreamInfo, updateSubscriberBitrateEvent, updateWebRTCViewerCount
-
Field Details
-
VOD_ID
- See Also:
-
VIEWER_ID
- See Also:
-
TOKEN_ID
- See Also:
-
STREAM_ID
- See Also:
-
SUBSCRIBER_ID
- See Also:
-
MAIN_TRACK_STREAM_ID
- See Also:
-
ROLE
- See Also:
-
datastore
private dev.morphia.Datastore datastore -
vodDatastore
private dev.morphia.Datastore vodDatastore -
tokenDatastore
private dev.morphia.Datastore tokenDatastore -
subscriberDatastore
private dev.morphia.Datastore subscriberDatastore -
detectionMap
private dev.morphia.Datastore detectionMap -
conferenceRoomDatastore
private dev.morphia.Datastore conferenceRoomDatastore -
mongoClient
private com.mongodb.client.MongoClient mongoClient -
cacheManager
-
broadcastCacheManager
-
subscriberCache
-
broadcastCache
-
logger
protected static org.slf4j.Logger logger -
IMAGE_ID
- See Also:
-
STATUS
- See Also:
-
ORIGIN_ADDRESS
- See Also:
-
START_TIME
- See Also:
-
DURATION
- See Also:
-
CREATION_DATE
- See Also:
-
RTMP_VIEWER_COUNT
- See Also:
-
HLS_VIEWER_COUNT
- See Also:
-
DASH_VIEWER_COUNT
- See Also:
-
WEBRTC_VIEWER_COUNT
- See Also:
-
META_DATA
- See Also:
-
UPDATE_TIME_FIELD
- See Also:
-
OLD_STREAM_ID_INDEX_NAME
- See Also:
-
SUBSCRIBER_CACHE
- See Also:
-
BROADCAST_CACHE
- See Also:
-
SUBSCRIBER_CACHE_SIZE
public static final int SUBSCRIBER_CACHE_SIZE- See Also:
-
SUBSCRIBER_CACHE_EXPIRE_SECONDS
public static final int SUBSCRIBER_CACHE_EXPIRE_SECONDS- See Also:
-
BROADCAST_CACHE_SIZE
public static final int BROADCAST_CACHE_SIZE- See Also:
-
BROADCAST_CACHE_EXPIRE_SECONDS
public static final int BROADCAST_CACHE_EXPIRE_SECONDS- See Also:
-
CONNECTED
- See Also:
-
broadcastLock
-
vodLock
-
tokenLock
-
subscriberLock
-
detectionLock
-
roomLock
-
-
Constructor Details
-
MongoStore
-
-
Method Details
-
deleteDuplicateStreamIds
-
getMongoConnectionUri
-
save
-
get
Description copied from class:DataStoreReturn the broadcast in data store -
getVoD
Description copied from class:DataStoreReturn the vod by id -
updateStatus
- Specified by:
updateStatusin classDataStore
-
updateVoDProcessStatus
- Specified by:
updateVoDProcessStatusin classDataStore
-
addEndpoint
- Specified by:
addEndpointin classDataStore
-
removeEndpoint
- Specified by:
removeEndpointin classDataStore
-
removeAllEndpoints
- Specified by:
removeAllEndpointsin classDataStore
-
delete
-
checkIfRegexValid
-
getConnectionEvents
public List<ConnectionEvent> getConnectionEvents(String streamId, String subscriberId, int offset, int size) Description copied from class:DataStoreGet connection events for a specific streamId and subscriberId ConnectionEvents are recorded ifAppSettings.isWriteSubscriberEventsToDatastore()is true- Specified by:
getConnectionEventsin classDataStore- Returns:
-
getBroadcastList
public List<Broadcast> getBroadcastList(int offset, int size, String type, String sortBy, String orderBy, String search) Description copied from class:DataStoreReturns the Broadcast List in order- Specified by:
getBroadcastListin classDataStore- Parameters:
offset- the number of items to skipsize- batch sizetype- can get "liveStream" or "ipCamera" or "streamSource" or "VoD" values. Default is getting all broadcast types.sortBy- can get "name" or "date" or "status" valuesorderBy- 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
- Specified by:
getExternalStreamsListin classDataStore
-
close
public void close(boolean deleteDB) Description copied from class:DataStoreCloses the database -
addVod
Description copied from class:DataStoreAdd VoD record to the datastore -
getVodList
public List<VoD> getVodList(int offset, int size, String sortBy, String orderBy, String filterStreamId, String search) Description copied from class:DataStoreReturns the VoD List in order- Specified by:
getVodListin classDataStore- Parameters:
offset- : the number of items to skipsize- : batch sizesortBy- can get "name" or "date" valuesorderBy- can get "desc" or "asc"filterStreamId- is used for filtering the vod by stream id. If it's null or empty, it's not usedsearch- is used for searching in vodIds and names of the vods.- Returns:
-
deleteVod
-
getTotalVodNumber
public long getTotalVodNumber()- Specified by:
getTotalVodNumberin classDataStore
-
fetchUserVodList
Description copied from class:DataStoreGets the video files under thefileDirdirectory parameter and saves them to the datastore as USER_VOD inVodclass- Specified by:
fetchUserVodListin classDataStore- Returns:
- number of files that are saved to datastore
-
getTotalBroadcastNumber
public long getTotalBroadcastNumber()- Specified by:
getTotalBroadcastNumberin classDataStore
-
getPartialBroadcastNumber
Description copied from class:DataStoreReturns the number of broadcasts which contains searched string- Specified by:
getPartialBroadcastNumberin classDataStore- Parameters:
search- is used for searching in streamIds and names of the stream- Returns:
-
getPartialVodNumber
Description copied from class:DataStoreReturns the number of vods which contains searched string- Specified by:
getPartialVodNumberin classDataStore- 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:DataStoreReturn the number of active broadcasts in the server- Specified by:
getActiveBroadcastCountin classDataStore- Returns:
-
updateBroadcastFields
Description copied from class:DataStoreUpdates the Broadcast objects fields if it's not null. The updated fields are as follows name, description, userName, password, IP address, streamUrl- Specified by:
updateBroadcastFieldsin classDataStore- Returns:
-
prepareFields
private void prepareFields(BroadcastUpdate broadcast, List<dev.morphia.query.updates.UpdateOperator> updates, Broadcast cachedBroadcast) -
updateHLSViewerCountLocal
- Specified by:
updateHLSViewerCountLocalin classDataStore
-
updateDASHViewerCountLocal
- Specified by:
updateDASHViewerCountLocalin classDataStore
-
updateWebRTCViewerCountLocal
- Specified by:
updateWebRTCViewerCountLocalin classDataStore
-
updateRtmpViewerCountLocal
- Specified by:
updateRtmpViewerCountLocalin classDataStore
-
updateViewerField
-
saveStreamInfo
Description copied from class:DataStoreSaves the stream info to the db- Specified by:
saveStreamInfoin classDataStore
-
getStreamInfoList
Description copied from class:DataStoreReturns stream info list added to db- Specified by:
getStreamInfoListin classDataStore- Returns:
-
clearStreamInfoList
Description copied from class:DataStoreRemove the stream info list from db- Specified by:
clearStreamInfoListin classDataStore
-
saveToken
Description copied from class:DataStoresaves token to store -
validateToken
Description copied from class:DataStoreValidates token- Specified by:
validateTokenin classDataStore- Returns:
- token if validated, null if not
-
revokeTokens
Description copied from class:DataStoreDelete all tokens of the stream- Specified by:
revokeTokensin classDataStore
-
listAllTokens
Description copied from class:DataStoreLists all tokens of requested stream- Specified by:
listAllTokensin classDataStore- Returns:
- lists of tokens
-
getConnectedSubscriberCount
Description copied from class:DataStoreReturns the number of the subscribers of requested stream- Specified by:
getConnectedSubscriberCountin classDataStore- Returns:
- number of the subscribers of requested stream
-
getConnectedSubscribers
Description copied from class:DataStoreLists connected subscribers of requested stream- Specified by:
getConnectedSubscribersin classDataStore- Returns:
- lists of subscribers
-
listAllSubscribers
Description copied from class:DataStoreLists all subscribers of requested stream- Specified by:
listAllSubscribersin classDataStore- Returns:
- lists of subscribers
-
addSubscriber
Description copied from class:DataStoreadds subscriber to the datastore for this stream- Specified by:
addSubscriberin classDataStoresubscriber- - subscriber to be added
-
addConnectionEvent
- Specified by:
addConnectionEventin classDataStore
-
deleteSubscriber
Description copied from class:DataStoredeletes subscriber from the datastore for this stream- Specified by:
deleteSubscriberin classDataStoresubscriberId- - id of the subsciber to be deleted
-
blockSubscriber
public boolean blockSubscriber(String streamId, String subscriberId, String blockedType, int seconds) Description copied from class:DataStoreblocks subscribe from playing or publishing- Specified by:
blockSubscriberin classDataStoresubscriberId- - id of the subsciber to be blockedblockedType- - it can be the value of the static fieldSubscriber.PLAY_TYPE,Subscriber.PUBLISH_TYPE,Subscriber.PUBLISH_AND_PLAY_TYPEpublish, play, publish_playseconds- - duration of seconds to block the user
-
revokeSubscribers
Description copied from class:DataStoredeletes all subscriber from the datastore for this stream- Specified by:
revokeSubscribersin classDataStore
-
getSubscriberCacheKey
-
getBroadcastCacheKey
-
getSubscriber
Description copied from class:DataStoregets subscriber from the datastore- Specified by:
getSubscriberin classDataStoresubscriberId- - id of the subsciber to be deleted
-
resetSubscribersConnectedStatus
public boolean resetSubscribersConnectedStatus()Description copied from class:DataStoresets the connection status of all the subscribers false in the datastore called after an ungraceful shutdown- Specified by:
resetSubscribersConnectedStatusin classDataStore
-
setMp4Muxing
Description copied from class:DataStoreenables or disables mp4 muxing for the stream- Specified by:
setMp4Muxingin classDataStore- Parameters:
streamId- - id of the streamenabled- 1 means enabled, -1 means disabled, 0 means no setting for the stream
-
setWebMMuxing
Description copied from class:DataStoreenables or disables WebM muxing for the stream- Specified by:
setWebMMuxingin classDataStore- Parameters:
streamId- - id of the streamenabled- 1 means enabled, -1 means disabled, 0 means no setting for the stream
-
setRecordMuxing
-
deleteToken
Description copied from class:DataStoreDelete specific token- Specified by:
deleteTokenin classDataStore- Parameters:
tokenId- id of the token
-
getToken
Description copied from class:DataStoreretrieve specific token -
getLocalLiveBroadcastCount
- Specified by:
getLocalLiveBroadcastCountin classDataStore
-
getLocalLiveBroadcasts
- Specified by:
getLocalLiveBroadcastsin classDataStore
-
createP2PConnection
Description copied from class:DataStoreCreates new P2PConnection- Specified by:
createP2PConnectionin classDataStore- Parameters:
conn- - P2PConnection object- Returns:
- boolean - success
-
deleteP2PConnection
Description copied from class:DataStoreDeletes a P2PConnection- Specified by:
deleteP2PConnectionin classDataStore- Returns:
- boolean - success
-
getP2PConnection
Description copied from class:DataStoreGet the P2PConnection by streamId- Specified by:
getP2PConnectionin classDataStore- Parameters:
streamId- - stream id for P2PConnection- Returns:
- P2PConnection - if exist else null
-
resetBroadcasts
Description copied from class:DataStoreResets the broadcasts in the database. It sets number of viewers to zero. It also delete the stream if it's zombi stream- Specified by:
resetBroadcastsin classDataStore
-
getTotalWebRTCViewersCount
public int getTotalWebRTCViewersCount()Description copied from class:DataStoreThis is used to get total number of WebRTC viewers- Specified by:
getTotalWebRTCViewersCountin classDataStore
-
updateStreamMetaData
This is used to update meta data for a bradcast- Specified by:
updateStreamMetaDatain classDataStore- Parameters:
streamId- id for the broadcastmetaData- new meta data
-
getSubscriberDatastore
public dev.morphia.Datastore getSubscriberDatastore() -
getSubscriberMetaData
Description copied from class:DataStoreGet subscriber metadata- Specified by:
getSubscriberMetaDatain classDataStore- Returns:
-
putSubscriberMetaData
Description copied from class:DataStorePut subscriber metadata. It overwrites the metadata, if you need to update something, first get theDataStore.getSubscriberMetaData(String), update it and put it- Specified by:
putSubscriberMetaDatain classDataStore
-
getConferenceRoomDatastore
public dev.morphia.Datastore getConferenceRoomDatastore() -
getSubtracks
Description copied from class:DataStoreGet the subtracks of the main track- Specified by:
getSubtracksin classDataStore- Parameters:
mainTrackId- the main track to get the subtracksoffset- the offset to get the subtrackssize- number of items to getrole- 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, String sortBy, String orderBy, String search) Description copied from class:DataStoreGet the subtracks of the main track- Specified by:
getSubtracksin classDataStore- Parameters:
mainTrackId- the main track to get the subtracksoffset- the offset to get the subtrackssize- number of items to getrole- the role of the subtracks for role based streaming especially in conferences. It can be nullstatus- the status of the stream broadcasting, finished etc. It can be nullsortBy- can get "name" or "date" or "status" valuesorderBy- can get "desc" or "asc"search- is used for searching in streamIds and names of the stream- Returns:
-
getFilterForSubtracks
-
getSubtrackCount
Description copied from class:DataStoreGet the count of subtracks- Specified by:
getSubtrackCountin classDataStore- Parameters:
mainTrackId- the main track to get the subtracksrole- the role of the subtracks for role based streaming especially in conferences- Returns:
- number of subtracks
-
getActiveSubtracks
Description copied from class:DataStoreGet 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:
getActiveSubtracksin classDataStore- Returns:
-
getActiveSubtracks
Description copied from class:DataStoreGet active subtracks with pagination. If subtrack is stucked in broadcasting or preparing, it will not return it.- Specified by:
getActiveSubtracksin classDataStore- Parameters:
mainTrackId- the main track to get the active subtracksoffset- the offset to get the active subtrackssize- number of items to getrole- the role of the subtracks for role based streaming especially in conferences. It can be null- Returns:
- list of active subtracks
-
getActiveSubtracksCount
Description copied from class:DataStoreGet the count of active subtracks. If subtrack is stucked in broadcasting or preparing, it will not count it.- Specified by:
getActiveSubtracksCountin classDataStore- Returns:
-
hasSubtracks
- Specified by:
hasSubtracksin classDataStore- Returns:
- If the stream has subtracks, it return true. If not, it returns false
-
getCacheManager
-
getSubscriberCache
-
getBroadcastCache
-
recordQueryDuration
-