Xodus-Queue

Persistent java.util.Queue implementation with Xodus

License

License

Categories

Categories

Xodus Data Databases
GroupId

GroupId

ch.rasc
ArtifactId

ArtifactId

xodus-queue
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Xodus-Queue
Persistent java.util.Queue implementation with Xodus
Project URL

Project URL

https://github.com/ralscha/xodus-queue/
Source Code Management

Source Code Management

https://github.com/ralscha/xodus-queue.git

Download xodus-queue

How to add to project

<!-- https://jarcasting.com/artifacts/ch.rasc/xodus-queue/ -->
<dependency>
    <groupId>ch.rasc</groupId>
    <artifactId>xodus-queue</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/ch.rasc/xodus-queue/
implementation 'ch.rasc:xodus-queue:1.0.2'
// https://jarcasting.com/artifacts/ch.rasc/xodus-queue/
implementation ("ch.rasc:xodus-queue:1.0.2")
'ch.rasc:xodus-queue:jar:1.0.2'
<dependency org="ch.rasc" name="xodus-queue" rev="1.0.2">
  <artifact name="xodus-queue" type="jar" />
</dependency>
@Grapes(
@Grab(group='ch.rasc', module='xodus-queue', version='1.0.2')
)
libraryDependencies += "ch.rasc" % "xodus-queue" % "1.0.2"
[ch.rasc/xodus-queue "1.0.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.xodus : xodus-environment jar 1.3.124
com.esotericsoftware : kryo jar 4.0.2

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar 5.6.0
org.junit.platform : junit-platform-launcher jar 1.6.0

Project Modules

There are no modules declared in this project.

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.

Versions

Version
1.0.2
1.0.1
1.0.0