Class MongodbQueue<ID,​DATA>

    • Constructor Detail

      • MongodbQueue

        public MongodbQueue()
    • Method Detail

      • getConnectionString

        public String getConnectionString()
        MongoDB's connection string (see http://mongodb.github.io/mongo-java-driver/3.10/driver/getting-started/quick-start/).
        Returns:
      • setConnectionString

        public MongodbQueue<ID,​DATA> setConnectionString​(String connectionString)
        MongoDB's connection string (see http://mongodb.github.io/mongo-java-driver/3.10/driver/getting-started/quick-start/).
        Parameters:
        connectionString -
        Returns:
      • getDatabaseName

        public String getDatabaseName()
        Name of MongoDB database to store data.
        Returns:
      • setDatabaseName

        public MongodbQueue<ID,​DATA> setDatabaseName​(String databaseName)
        Name of MongoDB database to store data.
        Parameters:
        databaseName -
        Returns:
      • getCollectionName

        public String getCollectionName()
        Name of MongoDB collection to store queue messages.
        Returns:
      • setCollectionName

        public MongodbQueue<ID,​DATA> setCollectionName​(String collectionName)
        Name of MongoDB collection to store queue messages.
        Parameters:
        collectionName -
        Returns:
      • getMongoClient

        protected com.mongodb.client.MongoClient getMongoClient()
        Getter for mongoClient.
        Returns:
      • setMongoClient

        public MongodbQueue<ID,​DATA> setMongoClient​(com.mongodb.client.MongoClient mongoClient)
        Setter for mongoClient.
        Parameters:
        mongoClient -
        Returns:
      • setMongoClient

        protected MongodbQueue<ID,​DATA> setMongoClient​(com.mongodb.client.MongoClient mongoClient,
                                                             boolean setMyOwnMongoClient)
        Setter for mongoClient.
        Parameters:
        mongoClient -
        setMyOwnMongoClient -
        Returns:
      • getDatabase

        protected com.mongodb.client.MongoDatabase getDatabase()
      • getCollection

        protected com.mongodb.client.MongoCollection<org.bson.Document> getCollection()
      • initCollection

        protected void initCollection()
        Initialize collection:
        • Check if collection exists.
        • If collection does not exist, create collection and indexes.
      • buildMongoClient

        protected com.mongodb.client.MongoClient buildMongoClient()
        Build a new MongoClient instance.
        Returns:
      • upsertToCollection

        protected boolean upsertToCollection​(IQueueMessage<ID,​DATA> msg)
        Insert/Update the message to collection.
        Parameters:
        msg -
        Returns:
      • insertToCollection

        protected boolean insertToCollection​(IQueueMessage<ID,​DATA> msg)
        Insert a new message to collection.
        Parameters:
        msg -
        Returns:
      • finish

        public void finish​(IQueueMessage<ID,​DATA> msg)
        Called when finish processing the message to cleanup ephemeral storage.

        Implementation flow:

        • Remove message from ephemeral storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

      • take

        public IQueueMessage<ID,​DATA> take()
                                          throws QueueException.EphemeralIsFull
        Take a message out of queue.

        Implementation flow:

        • Read message from head of queue storage.
        • Write message to ephemeral storage.
        • Remove message from queue storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

        Returns:
        Throws:
        QueueException.EphemeralIsFull - if the ephemeral storage is full
      • getOrphanMessages

        public Collection<IQueueMessage<ID,​DATA>> getOrphanMessages​(long thresholdTimestampMs)
        Get all orphan messages (messages that were left in ephemeral storage for a long time).
        Parameters:
        thresholdTimestampMs - message is orphan if message's timestampMillis + thresholdTimestampMs < now . Which means getOrphanMessages(10000) will return orphan messages that have stayed in ephemeral storage for more than 10000 milliseconds.
        Returns:
        null or empty collection if there is no orphan message
      • queueSize

        public int queueSize()
        Get number of items currently in queue storage.
        Returns:
        negative number if queue size can not be queried
      • ephemeralSize

        public int ephemeralSize()
        Get number of items currently in ephemeral storage.

        Note: ephemeral storage implementation is optional, depends on implementation.

        Returns:
        negative number if ephemeral size can not be queried