Class CrawlerConfig
- Direct Known Subclasses:
WebCrawlerConfig
Base Crawler configuration. Crawlers usually read this configuration upon starting up. While not always enforced, once execution has started, it should be considered immutable to avoid unexpected behaviors.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines how changes are discovered during a crawl run.static final classstatic enum -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCommitter(Committer committer) Adds a Committer responsible for persisting information to a target location/repository.addEventListener(EventListener<?> eventListener) Adds an event listener.addEventListeners(List<EventListener<?>> eventListeners) Adds event listeners.protected booleanClears all event listeners.booleanChange discovery strategy.@NonNull ClusterConfigThe Importer module configuration.Gets Committers responsible for persisting information to a target location/repository.The amount of time to defer the crawler shutdown when it is done executing.The document checksummer.Gets the document filters.List<EventListener<?>> Gets event listeners.One or more fetchers responsible for pulling documents and document metadata associated with a reference from a source.intThe maximum number of times a fetcher will re-attempt fetching a resource in case of failures.How long to wait before a failing fetcher re-attempts fetching a resource in case of failures (in milliseconds).getId()The crawler unique identifier.The maximum amount of time to wait before shutting down an idle crawler.The Importer module configuration.The maximum amount of time a crawler is allowed to run.intThe maximum depth the crawler should go.intThe maximum number of documents that can be processed in a single crawler run before stopping.intThe maximum number of references a node will read at once from the queue, to process locally.longMaximum number of bytes used for memory caching of all reusable streams combined, at any given time, for faster processing.longMaximum number of bytes used for memory caching of a single reusable stream, for faster processing.The metadata checksummer.Gets metadata filters.Minimum amount of time to wait between each logging of crawling progress.intThe maximum number of threads a crawler can use.The strategy to adopt when there are orphans.Gets post-import consumers.Gets pre-import consumers.Gets reference filtersThe spoiled state strategy resolver.Gets the references to initiate crawling from.Gets the file paths of seed files containing references to be used as start references.Gets the providers of references used as starting points for crawling.The exceptions we want to stop the crawler on.The base directory location where files generated during execution will reside.inthashCode()booleanWhether to turn ON deduplication based on document checksum.booleanWhether to turn ON deduplication based on metadata checksum.booleanWhether the start references should be loaded asynchronously.booleanremoveEventListener(EventListener<?> eventListener) Removes a single event listener from the list of registered listeners if present.setChangeDiscovery(CrawlerConfig.ChangeDiscovery changeDiscovery) Change discovery strategy.setClusterConfig(@NonNull ClusterConfig clusterConfig) The Importer module configuration.setCommitters(List<Committer> committers) Sets Committers responsible for persisting information to a target location/repository.setDeferredShutdownDuration(Duration deferredShutdownDuration) The amount of time to defer the crawler shutdown when it is done executing.setDocumentChecksummer(DocumentChecksummer documentChecksummer) The document checksummer.setDocumentDeduplicate(boolean documentDeduplicate) Whether to turn ON deduplication based on document checksum.setDocumentFetchSupport(FetchDirectiveSupport documentFetchSupport) setDocumentFilters(List<DocumentFilter> documentFilters) Sets document filters.setEventListeners(List<EventListener<?>> eventListeners) Sets event listeners.setFetchers(List<Fetcher> fetchers) One or more fetchers responsible for pulling documents and document metadata associated with a reference from a source.setFetchersMaxRetries(int fetchersMaxRetries) The maximum number of times a fetcher will re-attempt fetching a resource in case of failures.setFetchersRetryDelay(Duration fetchersRetryDelay) How long to wait before a failing fetcher re-attempts fetching a resource in case of failures (in milliseconds).The crawler unique identifier.setIdleTimeout(Duration idleTimeout) The maximum amount of time to wait before shutting down an idle crawler.setImporterConfig(ImporterConfig importerConfig) The Importer module configuration.setMaxCrawlDuration(Duration maxCrawlDuration) The maximum amount of time a crawler is allowed to run.setMaxDepth(int maxDepth) The maximum depth the crawler should go.setMaxDocuments(int maxDocuments) The maximum number of documents that can be processed in a single crawler run before stopping.setMaxQueueBatchSize(int maxQueueBatchSize) The maximum number of references a node will read at once from the queue, to process locally.setMaxStreamCachePoolSize(long maxStreamCachePoolSize) Maximum number of bytes used for memory caching of all reusable streams combined, at any given time, for faster processing.setMaxStreamCacheSize(long maxStreamCacheSize) Maximum number of bytes used for memory caching of a single reusable stream, for faster processing.setMetadataChecksummer(MetadataChecksummer metadataChecksummer) The metadata checksummer.setMetadataDeduplicate(boolean metadataDeduplicate) Whether to turn ON deduplication based on metadata checksum.setMetadataFetchSupport(FetchDirectiveSupport metadataFetchSupport) setMetadataFilters(List<MetadataFilter> metadataFilters) Sets metadata filters.setMinProgressLoggingInterval(Duration minProgressLoggingInterval) Minimum amount of time to wait between each logging of crawling progress.setNumThreads(int numThreads) The maximum number of threads a crawler can use.setOrphansStrategy(CrawlerConfig.OrphansStrategy orphansStrategy) The strategy to adopt when there are orphans.setPostImportConsumers(List<DocumentConsumer> postImportConsumers) Sets post-import consumers.setPreImportConsumers(List<DocumentConsumer> preImportConsumers) Sets pre-import consumers.setReferenceFilters(List<ReferenceFilter> referenceFilters) Sets reference filters.setSpoiledReferenceStrategizer(SpoiledReferenceStrategizer spoiledReferenceStrategizer) The spoiled state strategy resolver.setStartReferences(List<String> startReferences) Sets the references to initiate crawling from.setStartReferencesAsync(boolean startReferencesAsync) Whether the start references should be loaded asynchronously.setStartReferencesFiles(List<Path> startReferencesFiles) Sets the file paths of seed files containing references to be used as start references.setStartReferencesProviders(List<ReferencesProvider> startReferencesProviders) Sets the providers of references used as starting points for crawling.setStopOnExceptions(List<Class<? extends Exception>> stopOnExceptions) Sets the exceptions we want to stop the crawler on.setWorkDir(Path workDir) The base directory location where files generated during execution will reside.toString()
-
Field Details
-
DEFAULT_WORKDIR
Default relative directory where generated files are written. -
DEFAULT_IDLE_TIMEOUT
-
DEFAULT_MIN_PROGRESS_LOGGING_INTERVAL
-
-
Constructor Details
-
CrawlerConfig
public CrawlerConfig()
-
-
Method Details
-
getStartReferences
Gets the references to initiate crawling from.- Returns:
- start references (never
null)
-
setStartReferences
Sets the references to initiate crawling from.- Parameters:
startReferences- start references- Returns:
- this
-
getStartReferencesFiles
Gets the file paths of seed files containing references to be used as start references. Files are expected to have one reference per line. Blank lines and lines starting with # (comment) are ignored.- Returns:
- file paths of seed files containing references
(never
null)
-
setStartReferencesFiles
Sets the file paths of seed files containing references to be used as start references. Files are expected to have one reference per line. Blank lines and lines starting with # (comment) are ignored.- Parameters:
startReferencesFiles- file paths of seed files containing references- Returns:
- this
-
getStartReferencesProviders
Gets the providers of references used as starting points for crawling. Use this approach when references need to be provided dynamically at launch time.- Returns:
- start references providers (never
null)
-
setStartReferencesProviders
Sets the providers of references used as starting points for crawling. Use this approach when references need to be provided dynamically at launch time.- Parameters:
startReferencesProviders- start references provider- Returns:
- this
-
getStopOnExceptions
The exceptions we want to stop the crawler on. By default the crawler will log exceptions from processing a document and try to move on to the next without stopping. Even if no exceptions are returned by this method, the crawler can sometimes stop regardless if it cannot recover safely from an exception. To capture more exceptions, use a parent class (e.g., Exception should catch them all).- Returns:
- exceptions that will stop the crawler when encountered
-
setStopOnExceptions
Sets the exceptions we want to stop the crawler on. By default the crawler will log exceptions from processing a document and try to move on to the next without stopping. Even if no exceptions are returned by this method, the crawler can sometimes stop regardless if it cannot recover safely from an exception. To capture more exceptions, use a parent class (e.g., Exception should catch them all).- Parameters:
stopOnExceptions- exceptions that will stop the crawler when encountered- Returns:
- this
-
getReferenceFilters
Gets reference filters- Returns:
- reference filters
-
setReferenceFilters
Sets reference filters.- Parameters:
referenceFilters- the referenceFilters to set- Returns:
- this
-
getDocumentFilters
Gets the document filters.- Returns:
- document filters
-
setDocumentFilters
Sets document filters.- Parameters:
documentFilters- document filters- Returns:
- this
-
getMetadataFilters
Gets metadata filters.- Returns:
- metadata filters
-
setMetadataFilters
Sets metadata filters.- Parameters:
metadataFilters- metadata filters- Returns:
- this
-
getCommitters
Gets Committers responsible for persisting information to a target location/repository.- Returns:
- list of Committers (never
null)
-
setCommitters
Sets Committers responsible for persisting information to a target location/repository.- Parameters:
committers- list of Committers- Returns:
- this
-
addCommitter
Adds a Committer responsible for persisting information to a target location/repository.- Parameters:
committer- a Committer- Returns:
- this
-
getEventListeners
Gets event listeners. Those are considered additions to automatically detected configuration objects implementingEventListener.- Returns:
- event listeners.
-
setEventListeners
Sets event listeners. Those are considered additions to automatically detected configuration objects implementingEventListener.- Parameters:
eventListeners- event listeners.- Returns:
- this
-
addEventListeners
Adds event listeners. Those are considered additions to automatically detected configuration objects implementingEventListener.- Parameters:
eventListeners- event listeners.- Returns:
- this
-
addEventListener
Adds an event listener. Those are considered additions to automatically detected configuration objects implementingEventListener.- Parameters:
eventListener- event listener.- Returns:
- this
-
removeEventListener
Removes a single event listener from the list of registered listeners if present.- Parameters:
eventListener- event listener- Returns:
trueif the entity listener existed
-
clearEventListeners
Clears all event listeners. The automatically detected configuration objects implementingEventListenerare not cleared.- Returns:
- this
-
getPreImportConsumers
Gets pre-import consumers.- Returns:
- pre-import consumers
-
setPreImportConsumers
Sets pre-import consumers.- Parameters:
preImportConsumers- pre-import consumers- Returns:
- this
-
getPostImportConsumers
Gets post-import consumers.- Returns:
- post-import consumers
-
setPostImportConsumers
Sets post-import consumers.- Parameters:
postImportConsumers- post-import consumers- Returns:
- this
-
getFetchers
One or more fetchers responsible for pulling documents and document metadata associated with a reference from a source. When more than one are configured and for each documents, fetchers will be invoked in their defined order, until the first one that accepts and successfully process a reference (others are not invoked).- Returns:
- one or more fetchers
-
setFetchers
One or more fetchers responsible for pulling documents and document metadata associated with a reference from a source. When more than one are configured and for each documents, fetchers will be invoked in their defined order, until the first one that accepts and successfully process a reference (others are not invoked).- Parameters:
fetchers- one or more fetchers- Returns:
- this
-
getId
The crawler unique identifier. Using usual names is perfectly fine (non-alphanumeric characters are OK). It is important for this crawler ID to be unique amongst your crawlers in the same crawl session. On top of avoiding conflicts, it facilitates integration with different systems and facilitates tracking. -
getWorkDir
The base directory location where files generated during execution will reside. Whennullthe collector will use./work, relative to the execution "current" directory. -
getMaxStreamCachePoolSize
public long getMaxStreamCachePoolSize()Maximum number of bytes used for memory caching of all reusable streams combined, at any given time, for faster processing. Defaults to 1 GB. File-caching is used when the maximum is reached. -
getMaxStreamCacheSize
public long getMaxStreamCacheSize()Maximum number of bytes used for memory caching of a single reusable stream, for faster processing. Defaults to 100 MB. File-caching is used when this maximum is reached for a single file, or when the pool maximum size has been reached. -
getDeferredShutdownDuration
The amount of time to defer the crawler shutdown when it is done executing. This is useful for giving external processes with polling intervals enough time to grab the latest state of the collector before it shuts down. Default is zero (does not wait to shutdown after completion). -
getMaxCrawlDuration
The maximum amount of time a crawler is allowed to run. Zero or a negative value means unlimited. Default is zero (unlimited). -
getClusterConfig
The Importer module configuration. -
isStartReferencesAsync
public boolean isStartReferencesAsync()Whether the start references should be loaded asynchronously. Whentrue, the crawler will start processing the start references in one or more separate threads as they are added to the queue (as opposed to wait for queue initialization to be complete). While this may speed up crawling, it may have an unexpected effect on accuracy ofCrawlerDocMetaConstants.DEPTH. Use of this option is only recommended when start references take a significant time to load. -
getNumThreads
public int getNumThreads()The maximum number of threads a crawler can use. Default is 2.When running in a cluster, this value applies per node. For example, setting
numThreadsto 4 on a 3-node cluster results in up to 12 concurrent processing threads across the cluster. -
getMaxDocuments
public int getMaxDocuments()The maximum number of documents that can be processed in a single crawler run before stopping. Not all processed documents make it to your Committers as some can be rejected.
In multi-threaded or clustered environments, the actual number of documents processed may be a bit higher than the specified maximum due to concurrency. Upon reaching the configured maximum, the crawler will finish with its documents actively being processed before stopping.
Reaching the maximum value stops the current run, but it does not otherwise consider the crawler session "complete". If there are still queued documents left to process, the session is effectively paused and the next run resumes it, processing an additional number of documents up to the same maximum. This maximum therefore allows crawling one or more sources in chunks, processing a bounded number of documents on each run. When the session fully completes, the next run starts a new crawl session. To prevent resuming a partial crawl session, explicitly clean the crawl store first.
For more control on what events may stop the crawler, consider using configuring a
StopCrawlerOnMaxEventListener.Default is -1 (unlimited).
-
getMaxQueueBatchSize
public int getMaxQueueBatchSize()The maximum number of references a node will read at once from the queue, to process locally. -
getMaxDepth
public int getMaxDepth()The maximum depth the crawler should go. The exact definition of depth is crawler-specific. Examples: levels of sub-directories, number of URL clicks to reach a page, etc. Refer to specific crawler implementation for details. Default is -1 (unlimited). -
getIdleTimeout
The maximum amount of time to wait before shutting down an idle crawler. A crawler is considered idle when its queue is empty and there are no reference being actively processed. Differs fromdeferredShutdownDurationin that additions to the crawler queue will resume the normal processing. A non-zero value can be useful if the crawler queue can be populated by an external process. Defaults toDEFAULT_IDLE_TIMEOUT(5 seconds). Anullor zero value disables the wait. The smallest considered unit is seconds (milliseconds are rounded up). -
getMinProgressLoggingInterval
Minimum amount of time to wait between each logging of crawling progress. Minimum value is 1 second. Defaults toDEFAULT_MIN_PROGRESS_LOGGING_INTERVAL(30 seconds). Anullvalue or a value below 1 second disables progress logging. -
getOrphansStrategy
The strategy to adopt when there are orphans. Orphans are references that were processed in a previous run, but were not in the current run. In other words, they are leftovers from a previous run that were not re-encountered in the current.
Unless explicitly stated otherwise by a crawler implementation, the default strategy is to
PROCESSorphans. Setting anullvalue is the same as settingIGNORE.Be careful: Setting the orphan strategy to
DELETEis NOT recommended in most cases. There are times when a temporary failure such as a network outage or a web page timing out, may cause some documents not to be crawled. When this happens, unreachable documents would be considered "orphans" and be deleted while under normal circumstances, they should be kept. Re-processing them (default), is usually the safest approach to confirm they still exist before deleting or updating them. -
getChangeDiscovery
Change discovery strategy. Defaults to crawler-driven inventory scan. -
getMetadataChecksummer
The metadata checksummer. Metadata checksum generation is disabled whennull. -
getImporterConfig
The Importer module configuration. -
isMetadataDeduplicate
public boolean isMetadataDeduplicate()Whether to turn ON deduplication based on metadata checksum. To enable,getMetadataChecksummer()must not returnnull. Not recommended unless you know for sure your metadata checksum is acceptably unique. -
isDocumentDeduplicate
public boolean isDocumentDeduplicate()Whether to turn ON deduplication based on document checksum. To enable,getDocumentChecksummer()must not returnnull. Not recommended unless you know for sure your document checksum is acceptably unique. -
getDocumentChecksummer
The document checksummer. Document checksum generation is disabled whennull. -
getSpoiledReferenceStrategizer
The spoiled state strategy resolver. A spoiled document is one that was crawled properly before but on a subsequent crawl, it can no longer be crawled for whatever reason (not found, bad status, server error, etc.). -
getMetadataFetchSupport
-
getDocumentFetchSupport
-
getFetchersMaxRetries
public int getFetchersMaxRetries()The maximum number of times a fetcher will re-attempt fetching a resource in case of failures. Default is zero (won't retry). -
getFetchersRetryDelay
How long to wait before a failing fetcher re-attempts fetching a resource in case of failures (in milliseconds). Default is zero (no delay). -
setId
The crawler unique identifier. Using usual names is perfectly fine (non-alphanumeric characters are OK). It is important for this crawler ID to be unique amongst your crawlers in the same crawl session. On top of avoiding conflicts, it facilitates integration with different systems and facilitates tracking.- Returns:
this.
-
setWorkDir
The base directory location where files generated during execution will reside. Whennullthe collector will use./work, relative to the execution "current" directory.- Returns:
this.
-
setMaxStreamCachePoolSize
Maximum number of bytes used for memory caching of all reusable streams combined, at any given time, for faster processing. Defaults to 1 GB. File-caching is used when the maximum is reached.- Returns:
this.
-
setMaxStreamCacheSize
Maximum number of bytes used for memory caching of a single reusable stream, for faster processing. Defaults to 100 MB. File-caching is used when this maximum is reached for a single file, or when the pool maximum size has been reached.- Returns:
this.
-
setDeferredShutdownDuration
The amount of time to defer the crawler shutdown when it is done executing. This is useful for giving external processes with polling intervals enough time to grab the latest state of the collector before it shuts down. Default is zero (does not wait to shutdown after completion).- Returns:
this.
-
setMaxCrawlDuration
The maximum amount of time a crawler is allowed to run. Zero or a negative value means unlimited. Default is zero (unlimited).- Returns:
this.
-
setClusterConfig
The Importer module configuration.- Returns:
this.
-
setStartReferencesAsync
Whether the start references should be loaded asynchronously. Whentrue, the crawler will start processing the start references in one or more separate threads as they are added to the queue (as opposed to wait for queue initialization to be complete). While this may speed up crawling, it may have an unexpected effect on accuracy ofCrawlerDocMetaConstants.DEPTH. Use of this option is only recommended when start references take a significant time to load.- Returns:
this.
-
setNumThreads
The maximum number of threads a crawler can use. Default is 2.When running in a cluster, this value applies per node. For example, setting
numThreadsto 4 on a 3-node cluster results in up to 12 concurrent processing threads across the cluster.- Returns:
this.
-
setMaxDocuments
The maximum number of documents that can be processed in a single crawler run before stopping. Not all processed documents make it to your Committers as some can be rejected.
In multi-threaded or clustered environments, the actual number of documents processed may be a bit higher than the specified maximum due to concurrency. Upon reaching the configured maximum, the crawler will finish with its documents actively being processed before stopping.
Reaching the maximum value stops the current run, but it does not otherwise consider the crawler session "complete". If there are still queued documents left to process, the session is effectively paused and the next run resumes it, processing an additional number of documents up to the same maximum. This maximum therefore allows crawling one or more sources in chunks, processing a bounded number of documents on each run. When the session fully completes, the next run starts a new crawl session. To prevent resuming a partial crawl session, explicitly clean the crawl store first.
For more control on what events may stop the crawler, consider using configuring a
StopCrawlerOnMaxEventListener.Default is -1 (unlimited).
- Returns:
this.
-
setMaxQueueBatchSize
The maximum number of references a node will read at once from the queue, to process locally.- Returns:
this.
-
setMaxDepth
The maximum depth the crawler should go. The exact definition of depth is crawler-specific. Examples: levels of sub-directories, number of URL clicks to reach a page, etc. Refer to specific crawler implementation for details. Default is -1 (unlimited).- Returns:
this.
-
setIdleTimeout
The maximum amount of time to wait before shutting down an idle crawler. A crawler is considered idle when its queue is empty and there are no reference being actively processed. Differs fromdeferredShutdownDurationin that additions to the crawler queue will resume the normal processing. A non-zero value can be useful if the crawler queue can be populated by an external process. Defaults toDEFAULT_IDLE_TIMEOUT(5 seconds). Anullor zero value disables the wait. The smallest considered unit is seconds (milliseconds are rounded up).- Returns:
this.
-
setMinProgressLoggingInterval
Minimum amount of time to wait between each logging of crawling progress. Minimum value is 1 second. Defaults toDEFAULT_MIN_PROGRESS_LOGGING_INTERVAL(30 seconds). Anullvalue or a value below 1 second disables progress logging.- Returns:
this.
-
setOrphansStrategy
The strategy to adopt when there are orphans. Orphans are references that were processed in a previous run, but were not in the current run. In other words, they are leftovers from a previous run that were not re-encountered in the current.
Unless explicitly stated otherwise by a crawler implementation, the default strategy is to
PROCESSorphans. Setting anullvalue is the same as settingIGNORE.Be careful: Setting the orphan strategy to
DELETEis NOT recommended in most cases. There are times when a temporary failure such as a network outage or a web page timing out, may cause some documents not to be crawled. When this happens, unreachable documents would be considered "orphans" and be deleted while under normal circumstances, they should be kept. Re-processing them (default), is usually the safest approach to confirm they still exist before deleting or updating them.- Returns:
this.
-
setChangeDiscovery
Change discovery strategy. Defaults to crawler-driven inventory scan.- Returns:
this.
-
setMetadataChecksummer
The metadata checksummer. Metadata checksum generation is disabled whennull.- Returns:
this.
-
setImporterConfig
The Importer module configuration.- Returns:
this.
-
setMetadataDeduplicate
Whether to turn ON deduplication based on metadata checksum. To enable,getMetadataChecksummer()must not returnnull. Not recommended unless you know for sure your metadata checksum is acceptably unique.- Returns:
this.
-
setDocumentDeduplicate
Whether to turn ON deduplication based on document checksum. To enable,getDocumentChecksummer()must not returnnull. Not recommended unless you know for sure your document checksum is acceptably unique.- Returns:
this.
-
setDocumentChecksummer
The document checksummer. Document checksum generation is disabled whennull.- Returns:
this.
-
setSpoiledReferenceStrategizer
public CrawlerConfig setSpoiledReferenceStrategizer(SpoiledReferenceStrategizer spoiledReferenceStrategizer) The spoiled state strategy resolver. A spoiled document is one that was crawled properly before but on a subsequent crawl, it can no longer be crawled for whatever reason (not found, bad status, server error, etc.).- Returns:
this.
-
setMetadataFetchSupport
- Returns:
this.
-
setDocumentFetchSupport
- Returns:
this.
-
setFetchersMaxRetries
The maximum number of times a fetcher will re-attempt fetching a resource in case of failures. Default is zero (won't retry).- Returns:
this.
-
setFetchersRetryDelay
How long to wait before a failing fetcher re-attempts fetching a resource in case of failures (in milliseconds). Default is zero (no delay).- Returns:
this.
-
equals
-
canEqual
-
hashCode
public int hashCode() -
toString
-