public abstract class SingleThreadedWriter extends QueueBackedScheduledService<RunnableFuture<?>> implements Neo4jWriter
Neo4jWriter that maintains a queue of tasks and writes to the database in a single thread by constantly
pulling the tasks from the head of the queue.
If the queue capacity is full, tasks are dropped and a warning is logged.
Note that start() must be called in order to start processing the queue and stop() should be called
before the application is shut down.| Modifier and Type | Field and Description |
|---|---|
protected org.neo4j.graphdb.GraphDatabaseService |
database |
DEFAULT_QUEUE_CAPACITY, queue| Modifier | Constructor and Description |
|---|---|
protected |
SingleThreadedWriter(org.neo4j.graphdb.GraphDatabaseService database)
Construct a new writer with a default queue capacity of
QueueBackedScheduledService.DEFAULT_QUEUE_CAPACITY. |
protected |
SingleThreadedWriter(org.neo4j.graphdb.GraphDatabaseService database,
int queueCapacity)
Construct a new writer.
|
| Modifier and Type | Method and Description |
|---|---|
protected <T> T |
block(RunnableFuture<T> futureTask,
String id,
int waitMillis)
Block until the given task is executed, or until a timeout occurs.
|
protected abstract <T> RunnableFuture<T> |
createTask(Callable<T> task)
Create a runnable future from the given task.
|
protected <T> T |
offer(Callable<T> task,
String id,
int waitMillis)
Offer a task to the queue for processing.
|
void |
start()
Start the processing of tasks.
|
void |
stop()
Stop the processing of tasks.
|
<T> T |
write(Callable<T> task,
String id,
int waitMillis) |
void |
write(Runnable task) |
void |
write(Runnable task,
String id) |
equals, hashCode, logEmptyQueue, loggingFrequencyMs, offer, scheduler, shutDownprotected SingleThreadedWriter(org.neo4j.graphdb.GraphDatabaseService database)
QueueBackedScheduledService.DEFAULT_QUEUE_CAPACITY.database - to write to.protected SingleThreadedWriter(org.neo4j.graphdb.GraphDatabaseService database,
int queueCapacity)
database - to write to.queueCapacity - capacity of the queue.@PostConstruct public void start()
start in interface Writerstart in class QueueBackedScheduledService<RunnableFuture<?>>@PreDestroy public void stop()
stop in interface Writerstop in class QueueBackedScheduledService<RunnableFuture<?>>public void write(Runnable task)
write in interface Neo4jWriterpublic void write(Runnable task, String id)
write in interface Neo4jWriterpublic <T> T write(Callable<T> task, String id, int waitMillis)
write in interface Neo4jWriterprotected final <T> T offer(Callable<T> task, String id, int waitMillis)
T - type of the processing result.task - to process.id - of the task for logging purposes.waitMillis - how many milliseconds to block and wait for the task to be executed. Use 0 (or less) for no blocking,
i.e. for situations where the caller isn't interested in the result.null if the caller decided not to wait, or if the processing took
longer than the waitMillis argument, or if the queue is too full and the #offer(RunnableFuture) has
not been overridden to block in such situations.protected abstract <T> RunnableFuture<T> createTask(Callable<T> task)
task - task.protected final <T> T block(RunnableFuture<T> futureTask, String id, int waitMillis)
T - type of the task's result.futureTask - to wait for.id - of the task for logging.waitMillis - how long to wait before giving up.null if timed out.Copyright © 2013-2016–2020 Graph Aware Limited. All rights reserved.