Git Product home page Git Product logo

xodus-queue's Introduction

Test Status

This project provides a persistent java.util.Queue and java.util.concurrent.BlockingQueue implementation. It is using Xodus as the underlying storage engine. For persisting POJOs, it relies on Kryo.

xodus-queue is not a high-performance queue, and it only works within a single JVM. The primary motivation was to write a queue that survives a server restart and does not introduce a lot of external dependencies to my projects. Because I often use Xodus already in my projects, this library only adds Kryo as an additional dependency.

Any contributions are welcome if something is missing or could be implemented better, submit a pull request, or create an issue.

Usage

Create an instance of XodusQueue or XodusBlockingQueue and specify the database directory and the class of the entries you want to put into the queue. These can be either built-in Java types like String, Integer, Long, or a more complex POJO.

It is recommended to open the queue in an automatic resource management block because the underlying Xodus database should be closed when you no longer access the queue.

try (XodusQueue<String> queue = new XodusQueue<>("./test", String.class)) {

}

After the instantiation, you can call any of the methods from the java.util.Queue<E> and java.util.concurrent.BlockingQueue<E> interface. See the JavaDoc (Queue, BlockingQueue) for a list of all available methods.

Currently iterator() is not implemented. The underlying storage engine requires that read and write operations have to run inside transactions, and I don't know how to implement that in an iterator.

try (XodusQueue<String> queue = new XodusQueue<>("./queue", String.class)) {
  queue.add("one");

  String head = queue.poll(); // "one"
}

The blocking queue supports a capacity limit. The following example limits the number of elements in the queue to 3. put blocks the current thread when the queue is full and take blocks when the queue is empty.

try (XodusBlockingQueue<String> queue = new XodusBlockingQueue<>("./blocking_queue", String.class, 3)) {
  queue.put("one");
  queue.put("two");

  String head = queue.take(); // "one"
}

Maven

The library is hosted on the Central Maven Repository

  <dependency>
    <groupId>ch.rasc</groupId>
    <artifactId>xodus-queue</artifactId>
    <version>1.0.1</version>
  </dependency>

Changelog

1.0.1 - May 19, 2018

  • Fix key management in XodusQueue
  • Add java.util.concurrent.BlockingQueue implementation: XodusBlockingQueue

1.0.0 - May 15, 2018

  • Initial release

License

Code released under the Apache license.

xodus-queue's People

Contributors

ralscha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

cgb-ralscha

xodus-queue's Issues

Can the xodus-queue be configured?

I've been experimenting with the xodus-queue and really like the way it is light-weight and uses the same interface as Java Queue.

One question I had was if a large number of items are sent to the queue then I can see that files are persisted to disk containing the queue items and on restart, the application correctly processes the persisted items. However, if only a small number of items are sent to the queue, they are correctly persisted to disk and I can see the items in the persisted queue, but for some reason they are not reread when the service is restarted if I interrupt the processing of the queue.

Is this due to some configuration option that needs to be set (was trying to understand why this works correctly for large batches and not smaller ones)?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.