2. Loaders - aegisql/conveyor GitHub Wiki

Table of Contents

Loaders

Loaders is a collection of immutable classes that help to create and load different types of Carts. Immutability of loaders guarantees absence of side effects. Loaders also allows to hide conveyor instance from the client, providing just enough functionality for main conveyor tasks, which are, sending building parts wrapped into messages.

Loaders Code

Although Loaders have public constructors, in most cases you will not use them directly. Instead, Conveyor provides a family of convenient accessors.

public interface Conveyor<K, L, OUT> {
    public <X> PartLoader<K, L, X, OUT, Boolean> part();
    public <X> StaticPartLoader<L, X, OUT, Boolean> staticPart();
    public BuilderLoader<K, OUT, Boolean> build();
    public FutureLoader<K, OUT> future();
    public CommandLoader<K, OUT> command();
    public ResultConsumerLoader<K, OUT> resultConsumer();
    public ResultConsumerLoader<K, OUT> resultConsumer(ResultConsumer<K,OUT> consumer);
    public ScrapConsumerLoader<K> scrapConsumer();
    public ScrapConsumerLoader<K> scrapConsumer(ScrapConsumer<K,?> scrapConsumer);
}

PartLoader

PartLoader is the main vehicle that sends data to conveyors. It's API includes methods:

  • id(K id) - Sets ID for the build. Call of the id method cancels any predicates set by foreach methods
  • foreach() - Tells conveyor to apply values to all active builds. Call of the foreach method removes value of key set by the id call
  • foreach(Predicate<K> f) - Tells conveyor to apply values to all active builds, with keys matching provided filter. Call of the foreach method removes value of key set by the id call
  • label(L l) - Sets label.
  • value(X v) - Sets value of the part.
  • expirationTime - Sets expiration time. Expiration time can be a long epoch timestamp in milliseconds, or Instant object
  • ttl - Sets TTL. TTL can be passed as a TimeUnit or as a Duration
  • priority(long priority) - Sets priority. This parameter only affects conveyors created with Priority Queues and ignored by others.
  • place() - data will not be sent, until this method is called. Unlike previous methods it returns a Future of the building part.

Example

conveyor.part().id(123).label("FirstName").value("John").ttl(1,TimeUnit.SECONDS).place();

StaticPartLoader

StaticPartLoader - loads data, that will be stored on the conveyor level, and applied to all newly created builds in undefined order. Note that static parts have no expiration time. If you would like to delete static value, you should call the delete() method explicitly. The API includes methods:

  • label(L l) - Sets label.
  • value(X v) - Sets value of the part.
  • priority(long priority) - Sets priority. This parameter only affects conveyors created with Priority Queues and ignored by others.
  • delete() - Tells the conveyor to delete static value with specified label
  • place() - data will not be sent, until this method is called. Unlike previous methods it returns a Future of the building part.

BuilderLoader

BuilderLoader - It's API includes methods:

  • id(K id) - Sets ID for the build.
  • supplier(BuilderSupplier<OUT> v) - Supplier that will be used to create an instance of the Builder. If missing, default supplier will be used.
  • expirationTime - Sets expiration time. Expiration time can be a long epoch timestamp in milliseconds, or Instant object
  • ttl - Sets TTL. TTL can be passed as a TimeUnit or as a Duration
  • priority(long priority) - Sets priority. This parameter only affects conveyors created with Priority Queues and ignored by others.
  • create() - sends the message to create the build. Returns Future of the message.
  • createFuture() - sends the message to create the build. Returns Future of the Product.

FutureLoader

FutureLoader - It's API includes methods:

  • id(K id) - Sets ID for the buildю
  • expirationTime - Sets expiration time. Expiration time can be a long epoch timestamp in milliseconds, or Instant object
  • ttl - Sets TTL. TTL can be passed as a TimeUnit or as a Duration
  • priority(long priority) - Sets priority. This parameter only affects conveyors created with Priority Queues and ignored by others.
  • get() - Returns Future of the Product. If conveyor has a default Builder Supplier, and build with provided ID does not exist, then the new build is created. If default Builder Supplier is absent, then future will be immediately completed with exception.

CommandLoader

CommandLoader - CommandLoader and MultiKeyCommandLoader send messaged to the command queue, which has higher priority and bypasses the main input queue for Building parts. It's API includes methods:

  • id(K id) - Sets ID for the build.
  • foreach() - Tells conveyor to apply command to all active builds. Call of the foreach method removes value of key set by the id call. Foreach methods cannot be applied to commands like create or check.
  • foreach(Predicate<K> f) - Tells conveyor to apply command to all active builds, with keys matching provided filter. Call of the foreach method removes value of key set by the id call. Foreach methods cannot be applied to commands like create or check.
  • expirationTime - Sets expiration time. Expiration time can be a long epoch timestamp in milliseconds, or Instant object
  • ttl - Sets TTL. TTL can be passed as a TimeUnit or as a Duration
  • cancel() - cancels the build. Canceled build is always treated as failed.
  • timeout() - same as cancel, but calls onTimeout method before completing the build. Depending on its result, build can be completed successfully, or fail.
  • reschedule() - sets new expiration time from parameters provided by the cart.
  • check() - Future returns true, if build is running, otherwise returns false.
  • create - Sends command to create new Build, using default or provided supplier.

ResultConsumerLoader

ResultConsumerLoader - Sets Result Consumer for conveyor, individual builds or family of builds. It's API includes methods:

  • id(K id) - Sets ID for the build.
  • foreach() - Tells conveyor to apply ResultConsumer to all active builds. Call of the foreach method removes value of key set by the id call
  • foreach(Predicate<K> f) - Tells conveyor to apply ResultConsumer to all active builds, with keys matching provided filter. Call of the foreach method removes value of key set by the id call
  • expirationTime - Sets expiration time. Expiration time can be a long epoch timestamp in milliseconds, or Instant object
  • ttl - Sets TTL. TTL can be passed as a TimeUnit or as a Duration
  • priority(long priority) - Sets priority. This parameter only affects conveyors created with Priority Queues and ignored by others.
  • first(ResultConsumer <K,OUT> consumer) - When created with the resultConsumer() method, ResultConsumerLoader is seeded with current value of the ResultConsumer. This method replaces the head in the consumers chain.
  • andThen(ResultConsumer <K,OUT> consumer) - links new ResultConsumer to the chain of consumers.
  • set() - If neither id, nor foreach methods were called, sets new default ResultConsumer for the conveyor. If id method were called, sets new ResultConsumer for the Build. If foreach methods were called, sets ResultConsumer for all Builds with ids matching the filter.

ScrapConsumerLoader

ScrapConsumerLoader - Sets scrap consumer for the conveyor. It's API includes methods:

  • first(ScrapConsumer <K,?> consumer) - When created with the scrapConsumer() method, ScrapConsumerLoader is seeded with current value of the ScrapConsumer. This method replaces the head in the consumers chain.
  • andThen(ScrapConsumer <K,?> consumer) - links new ScrapConsumer to the chain of consumers.
  • set() - Sets new default ScrapConsumer for the conveyor.

Detailed information about Consumers can be found in this article.

Get Loaders by Conveyor name

If the only thing you need in some module - is a Loader, you can retrieve it directly by conveyor's name. Loaders have simple interfaces and you cannot break conveyor configuration by using it.

PartLoader.byConveyorName("name");
StaticPartLoader.byConveyorName("name");
BuilderLoader.byConveyorName("name");
CommandLoader.byConveyorName("name");
FutureLoader.byConveyorName("name");
ResultConsumerLoader.byConveyorName("name");
ScrapConsumerLoader.byConveyorName("name");

Lazy Loader suppliers

Lazy supplier will keep a reference to the Conveyor for you. You can retrieve lazy Supplier before conveyor is created.

PartLoader.lazySupplier("name");
PartLoader.lazySupplier("name").get();

StaticPartLoader.lazySupplier("name");
StaticPartLoader.lazySupplier("name").get();

BuilderLoader.lazySupplier("name");
BuilderLoader.lazySupplier("name").get();

CommandLoader.lazySupplier("name");
CommandLoader.lazySupplier("name").get();

FutureLoader.lazySupplier("name");
FutureLoader.lazySupplier("name").get();

ResultConsumerLoader.lazySupplier("name");
ResultConsumerLoader.lazySupplier("name").get();

ScrapConsumerLoader.lazySupplier("name");
ScrapConsumerLoader.lazySupplier("name").get();
⚠️ **GitHub.com Fallback** ⚠️