Class AbstractCommitter
- All Implemented Interfaces:
ICommitter,IXMLConfigurable,AutoCloseable
- Direct Known Subclasses:
AbstractBatchCommitter,AbstractFSCommitter,LogCommitter,MemoryCommitter
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccept(ICommitterRequest request) Determines whether a request should be committed.voidaddRestriction(PropertyMatcher... restrictions) Adds one or more restrictions this committer should be restricted to.voidaddRestrictions(List<PropertyMatcher> restrictions) Adds restrictions this committer should be restricted to.protected voidApplies configured field mappings to a request metadata.final voidclean()Cleans any persisted information (e.g. queue) to ensure next run will start fresh.voidRemoves all field mappings.voidClears all restrictions.final voidclose()Closes this committer and releases resources.final voiddelete(DeleteRequest deleteRequest) Deletes a document from the target repository.protected abstract voiddoClean()Performs concrete clean-up of persisted committer state.protected abstract voiddoClose()Subclasses can perform additional closing logic by overriding this method.protected abstract voiddoDelete(DeleteRequest deleteRequest) Performs the concrete delete operation.protected abstract voiddoInit()Subclasses can perform additional initialization by overriding this method.protected abstract voiddoUpsert(UpsertRequest upsertRequest) Performs the concrete upsert operation.booleanprotected final voidFires a debug-level event not tied to a specific request.protected final voidfireDebug(String name, ICommitterRequest req) Fires a debug-level event for a given request.protected final voidfireError(String name, ICommitterRequest req, Exception e) Fires an error-level event for a given request.protected final voidFires an error-level event not tied to a specific request.protected final voidFires an info-level event not tied to a specific request.protected final voidfireInfo(String name, ICommitterRequest req) Fires an info-level event for a given request.Gets the current committer context.Gets an unmodifiable copy of the metadata mappings.Gets all restrictionsinthashCode()final voidinit(CommitterContext committerContext) Initializes this committer with execution context.abstract voidloadCommitterFromXML(XML xml) Loads committer-specific configuration.final voidloadFromXML(XML xml) removeFieldMapping(String fromField) Removes a field mapping by source field name.booleanremoveRestriction(PropertyMatcher restriction) Removes a restriction.intremoveRestriction(String field) Removes all restrictions on a given field.abstract voidsaveCommitterToXML(XML xml) Saves committer-specific configuration.final voidvoidsetFieldMapping(String fromField, String toField) Sets a metadata field mapping.voidsetFieldMappings(Map<String, String> mappings) Sets a metadata field mappings, where the key is the source field and the value is the target field.toString()final voidupsert(UpsertRequest upsertRequest) Creates or updates a document in the target repository.
-
Constructor Details
-
AbstractCommitter
public AbstractCommitter()
-
-
Method Details
-
addRestriction
Adds one or more restrictions this committer should be restricted to.- Parameters:
restrictions- the restrictions
-
addRestrictions
Adds restrictions this committer should be restricted to.- Parameters:
restrictions- the restrictions
-
removeRestriction
Removes all restrictions on a given field.- Parameters:
field- the field to remove restrictions on- Returns:
- how many elements were removed
-
removeRestriction
Removes a restriction.- Parameters:
restriction- the restriction to remove- Returns:
trueif this committer contained the restriction
-
clearRestrictions
public void clearRestrictions()Clears all restrictions. -
getRestrictions
Gets all restrictions- Returns:
- the restrictions
- Since:
- 2.4.0
-
getFieldMappings
Gets an unmodifiable copy of the metadata mappings.- Returns:
- metadata mappings
-
setFieldMapping
Sets a metadata field mapping.- Parameters:
fromField- source fieldtoField- target field
-
setFieldMappings
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
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
Description copied from interface:ICommitterInitializes this committer with execution context.- Specified by:
initin interfaceICommitter- Parameters:
committerContext- committer execution context- Throws:
CommitterException- initialization failure
-
accept
Description copied from interface:ICommitterDetermines whether a request should be committed.- Specified by:
acceptin interfaceICommitter- Parameters:
request- request to evaluate- Returns:
trueif the request is accepted- Throws:
CommitterException- acceptance check failure
-
upsert
Description copied from interface:ICommitterCreates or updates a document in the target repository.- Specified by:
upsertin interfaceICommitter- Parameters:
upsertRequest- request to upsert- Throws:
CommitterException- upsert failure
-
delete
Description copied from interface:ICommitterDeletes a document from the target repository.- Specified by:
deletein interfaceICommitter- Parameters:
deleteRequest- request to delete- Throws:
CommitterException- delete failure
-
applyFieldMappings
Applies configured field mappings to a request metadata.- Parameters:
req- committer request to mutate
-
close
Description copied from interface:ICommitterCloses this committer and releases resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceICommitter- Throws:
CommitterException- close failure
-
clean
Description copied from interface:ICommitterCleans 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:
cleanin interfaceICommitter- Throws:
CommitterException- something went wrong cleaning the committer.
-
getCommitterContext
Gets the current committer context.- Returns:
- committer context
-
doInit
Subclasses can perform additional initialization by overriding this method. Default implementation does nothing. TheCommitterContextwill be initialized when invokinggetCommitterContext()- Throws:
CommitterException- error initializing
-
doUpsert
Performs the concrete upsert operation.- Parameters:
upsertRequest- upsert request- Throws:
CommitterException- commit failure
-
doDelete
Performs the concrete delete operation.- Parameters:
deleteRequest- delete request- Throws:
CommitterException- commit failure
-
doClose
Subclasses can perform additional closing logic by overriding this method. Default implementation does nothing.- Throws:
CommitterException- error closing committer
-
doClean
Performs concrete clean-up of persisted committer state.- Throws:
CommitterException- clean-up failure
-
fireDebug
Fires a debug-level event not tied to a specific request.- Parameters:
name- event name
-
fireDebug
Fires a debug-level event for a given request.- Parameters:
name- event namereq- associated request
-
fireInfo
Fires an info-level event not tied to a specific request.- Parameters:
name- event name
-
fireInfo
Fires an info-level event for a given request.- Parameters:
name- event namereq- associated request
-
fireError
Fires an error-level event not tied to a specific request.- Parameters:
name- event namee- exception to attach
-
fireError
Fires an error-level event for a given request.- Parameters:
name- event namereq- associated requeste- exception to attach
-
loadFromXML
- Specified by:
loadFromXMLin interfaceIXMLConfigurable
-
saveToXML
- Specified by:
saveToXMLin interfaceIXMLConfigurable
-
loadCommitterFromXML
Loads committer-specific configuration.- Parameters:
xml- XML to read from
-
saveCommitterToXML
Saves committer-specific configuration.- Parameters:
xml- XML to write to
-
equals
-
hashCode
public int hashCode() -
toString
-