MCPcopy Index your code
hub / github.com/bhargavms/sqlite-persistent-queue

github.com/bhargavms/sqlite-persistent-queue @1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.0.0 ↗ · + Follow
134 symbols 423 edges 17 files 16 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

SQLite based Persistent Queue.

Build Status Coverage Status Release

A Java Queue interface implementation that stores directly to SqliteDb

How it works

  • Implement the QueueObjectConverter<T> interface do decide how you want to serialize and deserialize the objects that you want to push to the Queue.

  • The SQLitePersistentQueue class uses the above implementation to serialize objects before storing it the Database.

  • Upon calling poll() or remove() on the SQLitePersistentQueue the item with the lowest primary key value (since the primary key is auto-incrementing) is removed from the Queue and returned. This co-incidentally is the HEAD of the queue (as queue is FIFO based).

  • Please remember each instance of SQLitePersistentQueue creates a new connection to the Database. I have kept the freedom of how many connections to be made to DB to the developer. The ideal usage for new developers would be to hold only a single instance of the SQLitePersistentQueue class in your Application class, and retrieve this wherever you want. Also DO NOT forget to call close() to close the connection to the Database once you are finished using the Queue.

How to use

You need to implement the QueueObjectConverter<T> class (T is the type of the object you are storing in the Queue) to decide how you want to serialize/deserialize objects as objects are converted to strings before being saved in the database.

A Sample implementation of the QueueObjectConverter interface:

Here I use Gson to convert objects to/from json strings

public class GsonPayloadConverter implements QueueObjectConverter<Payload> {
    private final Gson gson;

    public GsonPayloadConverter(Gson gson) {
        this.gson = gson;
    }

    @Override
    public Payload deserialize(String value) {
        return gson.fromJson(value, Payload.class);
    }

    @Override
    public String serialize(Payload queueObject) {
        return gson.toJson(queueObject);
    }
}

This implementation you should pass to the constructor of SQLitePersistentQueue class. The SQLitePersistentQueue uses this implementation to convert objects to/from strings before returning storing/retreiving from the SqliteDb.

Example:

Gson gson = new Gson()
queue = new SQLitePersistentQueue<>(c, new GsonPayloadConverter(gson));

This instantiated queue you can use it like any other java queue as it implements the java.util.Queue interface.

Important

Call queue.close() when you are done using the queue to close the connection to the Database.

TODO:

  • Make Sqlite writes in chunks by providing save() api?

Extension points exported contracts — how you extend this code

SQLiteBusSubscriber (Interface)
A subscriber contract for the sqlite change bus. [3 implementers]
library/src/main/java/com/talview/sqlitepersistentqueue/SQLiteBusSubscriber.java
QueueObjectConverter (Interface)
Created by talview23 on 10/10/16. [2 implementers]
library/src/main/java/com/talview/sqlitepersistentqueue/QueueObjectConverter.java

Core symbols most depended-on inside this repo

contains
called by 20
library/src/main/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueue.java
insert
called by 14
library/src/main/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueTableManager.java
offer
called by 13
library/src/main/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueue.java
getCount
called by 11
library/src/main/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueTableManager.java
add
called by 10
library/src/main/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueue.java
removeHead
called by 10
library/src/main/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueTableManager.java
addAll
called by 9
library/src/main/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueue.java
close
called by 9
library/src/main/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueTableManager.java

Shape

Method 117
Class 15
Interface 2

Languages

Java100%

Modules by API surface

library/src/androidTest/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueueTest.java37 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueue.java23 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueTableManager.java14 symbols
library/src/androidTest/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueTableManagerTest.java12 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/SQLitePersistentQueueBus.java8 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/SQLiteBusPublisher.java6 symbols
library/src/androidTest/java/com/talview/sqlitepersistentqueue/SQLiteBusPublisherTest.java6 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/db/SQLiteQueueDbHelper.java4 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/SQLiteQueueIterator.java4 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/SQLiteBusSubscriber.java4 symbols
library/src/androidTest/java/com/talview/sqlitepersistentqueue/SQLiteQueueIteratorTest.java4 symbols
library/src/main/java/com/talview/sqlitepersistentqueue/QueueObjectConverter.java3 symbols

For agents

$ claude mcp add sqlite-persistent-queue \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact