Class AbstractCommitter

java.lang.Object
com.norconex.committer.core3.AbstractCommitter
All Implemented Interfaces:
ICommitter, IXMLConfigurable, AutoCloseable
Direct Known Subclasses:
AbstractBatchCommitter, AbstractFSCommitter, LogCommitter, MemoryCommitter

public abstract class AbstractCommitter extends Object implements ICommitter, IXMLConfigurable

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.

XML configuration usage:


<!-- multiple "restrictTo" tags allowed (only one needs to match) -->
<restrictTo>
  <fieldMatcher>(field-matching expression)</fieldMatcher>
  <valueMatcher>(value-matching expression)</valueMatcher>
</restrictTo>
<fieldMappings>
  <!-- Add as many field mappings as needed -->
  <mapping
      fromField="(source field name)"
      toField="(target field name)"/>
</fieldMappings>

Implementing classes inherit the above XML configuration.

Since:
3.0.0
Author:
Pascal Essiembre
  • Constructor Details

    • AbstractCommitter

      public AbstractCommitter()
  • Method Details

    • addRestriction

      public void addRestriction(PropertyMatcher... restrictions)
      Adds one or more restrictions this committer should be restricted to.
      Parameters:
      restrictions - the restrictions
    • addRestrictions

      public void addRestrictions(List<PropertyMatcher> restrictions)
      Adds restrictions this committer should be restricted to.
      Parameters:
      restrictions - the restrictions
    • removeRestriction

      public int removeRestriction(String field)
      Removes all restrictions on a given field.
      Parameters:
      field - the field to remove restrictions on
      Returns:
      how many elements were removed
    • removeRestriction

      public boolean removeRestriction(PropertyMatcher restriction)
      Removes a restriction.
      Parameters:
      restriction - the restriction to remove
      Returns:
      true if this committer contained the restriction
    • clearRestrictions

      public void clearRestrictions()
      Clears all restrictions.
    • getRestrictions

      public PropertyMatchers getRestrictions()
      Gets all restrictions
      Returns:
      the restrictions
      Since:
      2.4.0
    • getFieldMappings

      public Map<String,String> getFieldMappings()
      Gets an unmodifiable copy of the metadata mappings.
      Returns:
      metadata mappings
    • setFieldMapping

      public void setFieldMapping(String fromField, String toField)
      Sets a metadata field mapping.
      Parameters:
      fromField - source field
      toField - target field
    • setFieldMappings

      public void setFieldMappings(Map<String,String> mappings)
      Sets a metadata field mappings, where the key is the source field and the value is the target field.
      Parameters:
      mappings - metadata field mappings
    • removeFieldMapping

      public String removeFieldMapping(String fromField)
      Removes a field mapping by source field name.
      Parameters:
      fromField - source field name
      Returns:
      mapped target field that was removed, or null
    • clearFieldMappings

      public void clearFieldMappings()
      Removes all field mappings.
    • init

      public final void init(CommitterContext committerContext) throws CommitterException
      Description copied from interface: ICommitter
      Initializes this committer with execution context.
      Specified by:
      init in interface ICommitter
      Parameters:
      committerContext - committer execution context
      Throws:
      CommitterException - initialization failure
    • accept

      public boolean accept(ICommitterRequest request) throws CommitterException
      Description copied from interface: ICommitter
      Determines whether a request should be committed.
      Specified by:
      accept in interface ICommitter
      Parameters:
      request - request to evaluate
      Returns:
      true if the request is accepted
      Throws:
      CommitterException - acceptance check failure
    • upsert

      public final void upsert(UpsertRequest upsertRequest) throws CommitterException
      Description copied from interface: ICommitter
      Creates or updates a document in the target repository.
      Specified by:
      upsert in interface ICommitter
      Parameters:
      upsertRequest - request to upsert
      Throws:
      CommitterException - upsert failure
    • delete

      public final void delete(DeleteRequest deleteRequest) throws CommitterException
      Description copied from interface: ICommitter
      Deletes a document from the target repository.
      Specified by:
      delete in interface ICommitter
      Parameters:
      deleteRequest - request to delete
      Throws:
      CommitterException - delete failure
    • applyFieldMappings

      protected void applyFieldMappings(ICommitterRequest req)
      Applies configured field mappings to a request metadata.
      Parameters:
      req - committer request to mutate
    • close

      public final void close() throws CommitterException
      Description copied from interface: ICommitter
      Closes this committer and releases resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ICommitter
      Throws:
      CommitterException - close failure
    • clean

      public final void clean() throws CommitterException
      Description copied from interface: ICommitter
      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 ICommitter
      Throws:
      CommitterException - something went wrong cleaning the committer.
    • getCommitterContext

      public CommitterContext getCommitterContext()
      Gets the current committer context.
      Returns:
      committer context
    • 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
      Performs the concrete upsert operation.
      Parameters:
      upsertRequest - upsert request
      Throws:
      CommitterException - commit failure
    • doDelete

      protected abstract void doDelete(DeleteRequest deleteRequest) throws CommitterException
      Performs the concrete delete operation.
      Parameters:
      deleteRequest - delete request
      Throws:
      CommitterException - commit failure
    • 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
      Performs concrete clean-up of persisted committer state.
      Throws:
      CommitterException - clean-up failure
    • fireDebug

      protected final void fireDebug(String name)
      Fires a debug-level event not tied to a specific request.
      Parameters:
      name - event name
    • fireDebug

      protected final void fireDebug(String name, ICommitterRequest req)
      Fires a debug-level event for a given request.
      Parameters:
      name - event name
      req - associated request
    • fireInfo

      protected final void fireInfo(String name)
      Fires an info-level event not tied to a specific request.
      Parameters:
      name - event name
    • fireInfo

      protected final void fireInfo(String name, ICommitterRequest req)
      Fires an info-level event for a given request.
      Parameters:
      name - event name
      req - associated request
    • fireError

      protected final void fireError(String name, Exception e)
      Fires an error-level event not tied to a specific request.
      Parameters:
      name - event name
      e - exception to attach
    • fireError

      protected final void fireError(String name, ICommitterRequest req, Exception e)
      Fires an error-level event for a given request.
      Parameters:
      name - event name
      req - associated request
      e - exception to attach
    • loadFromXML

      public final void loadFromXML(XML xml)
      Specified by:
      loadFromXML in interface IXMLConfigurable
    • saveToXML

      public final void saveToXML(XML xml)
      Specified by:
      saveToXML in interface IXMLConfigurable
    • loadCommitterFromXML

      public abstract void loadCommitterFromXML(XML xml)
      Loads committer-specific configuration.
      Parameters:
      xml - XML to read from
    • saveCommitterToXML

      public abstract void saveCommitterToXML(XML xml)
      Saves committer-specific configuration.
      Parameters:
      xml - XML to write to
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class Object