Class CommitterService<T>

java.lang.Object
com.norconex.committer.core.service.CommitterService<T>
Type Parameters:
T - type of committed objects
All Implemented Interfaces:
Closeable, AutoCloseable

public class CommitterService<T> extends Object implements Closeable
Wrapper around multiple Committers so they can all be handled as one and facilitating integration with various clients.
  • Method Details

    • isOperative

      public boolean isOperative()
    • init

      public void init(CommitterContext baseContext) throws CommitterServiceException
      Throws:
      CommitterServiceException
    • upsert

      public List<Committer> upsert(T object) throws CommitterServiceException
      Updates or inserts an object using all accepting committers.
      Parameters:
      object - the object to upsert
      Returns:
      committers having accepted and upserted the object
      Throws:
      CommitterServiceException - wrapper around operation failure one or more of the registered committers (wraps last exception captured)
    • upsert

      public List<Committer> upsert(T object, @NonNull @NonNull BiConsumer<Committer,String> onWithheld) throws CommitterServiceException
      Updates or inserts an object using all accepting committers, telling the caller about each committer that withheld it (see the request's withheldReason), so the caller can try it again later.
      Parameters:
      object - the object to upsert
      onWithheld - called with the committer and its reason, for each committer that accepted the object but withheld it
      Returns:
      committers having accepted the object, whether they upserted it or withheld it
      Throws:
      CommitterServiceException - wrapper around operation failure one or more of the registered committers (wraps last exception captured)
    • delete

      public List<Committer> delete(T object) throws CommitterServiceException
      Deletes an object using all accepting committers.
      Parameters:
      object - the object to delete
      Returns:
      committers having accepted and deleted the object
      Throws:
      CommitterServiceException - wrapper around operation failure one or more of the registered committers (wraps last exception captured)
    • close

      public void close() throws CommitterServiceException
      Closes all registered committers.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      CommitterServiceException - wrapper around operation failure one or more of the registered committers (wraps last exception captured)
    • clean

      public void clean() throws CommitterServiceException
      Cleans all registered committers.
      Throws:
      CommitterServiceException - wrapper around operation failure one or more of the registered committers (wraps last exception captured)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • builder

      public static <T> CommitterService.CommitterServiceBuilder<T> builder()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getCommitters

      public List<Committer> getCommitters()
    • getEventManager

      public EventManager getEventManager()
    • getUpsertRequestBuilder

      @NonNull public @NonNull Function<T,UpsertRequest> getUpsertRequestBuilder()
    • getDeleteRequestBuilder

      @NonNull public @NonNull Function<T,DeleteRequest> getDeleteRequestBuilder()
    • getSendCondition

      public Predicate<T> getSendCondition()
      Decides, before each upsert or delete, whether the object may be sent to committers. When it says no, the object is not sent, no event is fired, and an empty list is returned. Everything is sent by default.