Class AbstractCommitter<T extends BaseCommitterConfig>

java.lang.Object
com.norconex.committer.core.AbstractCommitter<T>
Type Parameters:
T - The type of the committer configuration class
All Implemented Interfaces:
Committer, Configurable<T>, AutoCloseable
Direct Known Subclasses:
AbstractBatchCommitter, AbstractFsCommitter, LogCommitter, MemoryCommitter

public abstract class AbstractCommitter<T extends BaseCommitterConfig> extends Object implements Committer, Configurable<T>

A base implementation taking care of basic plumbing, such as firing main Committer events (including exceptions), storing the Committer context (available via getCommitterContext()), and adding support for filtering unwanted requests.

Restricting committer to specific documents

Optionally apply a committer only to certain type of documents. Documents are restricted based on their metadata field names and values. This option can be used to perform document routing when you have multiple committers defined.

Field mappings

By default, this abstract class applies field mappings for metadata fields, but leaves the document reference and content (input stream) for concrete implementations to handle. In other words, they only apply to a committer request metadata. Field mappings are performed on committer requests before upserts and deletes are actually performed.

  • Constructor Details

    • AbstractCommitter

      public AbstractCommitter()
  • Method Details

    • init

      public final void init(@NonNull @NonNull CommitterContext committerContext) throws CommitterException
      Description copied from interface: Committer
      Initializes this committer. Invoked once per crawl session.
      Specified by:
      init in interface Committer
      Parameters:
      committerContext - the committer context
      Throws:
      CommitterException - problem with initialization
    • accept

      public boolean accept(CommitterRequest request) throws CommitterException
      Description copied from interface: Committer
      Gets whether this committer accepts to commit the supplied request. Useful when routing between multiple committers. Invoked for every CommitterRequest. A request needs to be accepted for Committer.upsert(UpsertRequest) or Committer.delete(DeleteRequest) to be invoked.
      Specified by:
      accept in interface Committer
      Parameters:
      request - committer request
      Returns:
      true if accepted
      Throws:
      CommitterException - any error when accepting
    • upsert

      public final void upsert(UpsertRequest upsertRequest) throws CommitterException
      Description copied from interface: Committer
      Updates or inserts the entity represented by the supplied request into the target of this committer.
      Specified by:
      upsert in interface Committer
      Parameters:
      upsertRequest - request to update or insert
      Throws:
      CommitterException - could not process upsert request
    • delete

      public final void delete(DeleteRequest deleteRequest) throws CommitterException
      Description copied from interface: Committer
      Deletes the entity represented by the supplied request from the target of this committer.
      Specified by:
      delete in interface Committer
      Parameters:
      deleteRequest - request to delete
      Throws:
      CommitterException - could not process delete request
    • aclFormat

      protected final AclFormat aclFormat()
      The format documents' ACLs are sent in: the configured one, or this committer's default when none is.
      Returns:
      the ACL format
    • supportsNativeAcl

      protected boolean supportsNativeAcl()
      Whether this committer's destination has access control of its own, that this committer writes from a document's ACL (the AclFormat.NATIVE format). A committer that returns true reads the ACL with AclCodec.read(Properties), writes it its own way, and removes the "crawler.acl" field from what it sends. Default is false.
      Returns:
      true if the destination has its own access control
    • defaultAclFormat

      protected AclFormat defaultAclFormat()
      The ACL format used when none is configured, for a committer whose destination has no access control of its own. Default is AclFormat.JSON; a committer whose destination is searched by field values (rather than holding documents as JSON) overrides it with AclFormat.FLAT.
      Returns:
      the default ACL format
    • nativeAclProblem

      protected String nativeAclProblem(Acl acl)
      In the AclFormat.NATIVE format, why the destination cannot express a document's ACL (for example several levels, or a principal it has no equivalent for), so the document is withheld rather than sent with access it did not have. Default is null.
      Parameters:
      acl - the document's ACL
      Returns:
      the reason, or null if the destination can express it
    • applyFieldMappings

      protected void applyFieldMappings(CommitterRequest req)
    • close

      public final void close() throws CommitterException
      Description copied from interface: Committer
      Close or release any open resources used by this committer.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Committer
      Throws:
      CommitterException
    • clean

      public final void clean() throws CommitterException
      Description copied from interface: Committer
      Cleans any persisted information (e.g. queue) to ensure next run will start fresh. Calling this method on Committers not persisting anything between each execution will have no effect. This method does NOT delete anything previously committed on the target repository.
      Specified by:
      clean in interface Committer
      Throws:
      CommitterException - something went wrong cleaning the committer.
    • getCommitterContext

      public CommitterContext getCommitterContext()
    • doInit

      protected abstract void doInit() throws CommitterException
      Subclasses can perform additional initialization by overriding this method. Default implementation does nothing. The CommitterContext will be initialized when invoking getCommitterContext()
      Throws:
      CommitterException - error initializing
    • doUpsert

      protected abstract void doUpsert(UpsertRequest upsertRequest) throws CommitterException
      Throws:
      CommitterException
    • doDelete

      protected abstract void doDelete(DeleteRequest deleteRequest) throws CommitterException
      Throws:
      CommitterException
    • doClose

      protected abstract void doClose() throws CommitterException
      Subclasses can perform additional closing logic by overriding this method. Default implementation does nothing.
      Throws:
      CommitterException - error closing committer
    • doClean

      protected abstract void doClean() throws CommitterException
      Throws:
      CommitterException
    • fireDebug

      protected final void fireDebug(String name)
    • fireDebug

      protected final void fireDebug(String name, CommitterRequest req)
    • fireInfo

      protected final void fireInfo(String name)
    • fireInfo

      protected final void fireInfo(String name, CommitterRequest req)
    • fireError

      protected final void fireError(String name, Exception e)
    • fireError

      protected final void fireError(String name, CommitterRequest req, Exception e)
    • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object