Interface Submitter

All Known Implementing Classes:
ExecutorSubmitter

public interface Submitter
Called by TransactionOutbox to submit work for background processing.
  • Method Details

    • withExecutor

      static Submitter withExecutor(Executor executor)
      Schedules background work using a local Executor implementation.

      Shortcut for ExecutorSubmitter.builder().executor(executor).build().

      Parameters:
      executor - The executor.
      Returns:
      The submitter.
    • withDefaultExecutor

      static Submitter withDefaultExecutor()
      Schedules background worh with a ThreadPoolExecutor, sized to match ForkJoinPool.commonPool() (or one thread, whichever is the larger), with a maximum queue size of 16384 before work is discarded.
      Returns:
      The submitter.
    • submit

      void submit(TransactionOutboxEntry entry, Consumer<TransactionOutboxEntry> localExecutor)
      Submits a transaction outbox task for processing. The TransactionOutboxEntry is provided, along with a localExecutor which can run the work immediately. An implementation may validly do any of the following:
      • Submit a call to localExecutor in a local thread, e.g. using an Executor. This is what implementations returned by withExecutor(Executor) or withDefaultExecutor() will do, and is recommended in almost all cases.
      • Serialize the TransactionOutboxEntry, send it to another instance (e.g. via a queue) and have the handler code call TransactionOutbox.processNow(TransactionOutboxEntry). Such an approach should not generally be necessary since TransactionOutbox.flush() is designed to be called repeatedly on multiple instances. This means there is a degree of load balancing built into the system, but when dealing with very high load, very low run-time tasks, this can get overwhelmed and direct multi-instance queuing can help balance the load at source. Note: it is recommended that the invocation property of the TransactionOutboxEntry be serialized using InvocationSerializer.createDefaultJsonSerializer()
      • Pass the entry directly to the localExecutor. This will run the work immediately in the calling thread and is therefore generally not recommended; the calling thread will be either the thread calling TransactionOutbox.schedule(Class) (effectively making the work synchronous) or the background poll thread (limiting work in progress to one). It can, however, be useful for test cases.
      Parameters:
      entry - The entry to process.
      localExecutor - Provides a means of running the work directly locally (it is effectively just a call to TransactionOutbox.processNow(TransactionOutboxEntry)).