Package opennlp.tools.stemmer
Class DelegatingStemmer<P>
java.lang.Object
opennlp.tools.stemmer.DelegatingStemmer<P>
- Type Parameters:
P- the per-thread payload: a bare delegate stemmer, or a delegate paired with per-thread working state such as a cache.
- All Implemented Interfaces:
Stemmer
- Direct Known Subclasses:
CachingStemmer,SharingStemmer
Shared plumbing for
Stemmer wrappers that route each call to a per-thread payload minted
from a StemmerFactory, following the OwnerOrPerThreadState pattern of the
thread-safe *ME components. Subclasses differ only in the payload they carry per thread
and in what Stemmer.stem(CharSequence) does with it.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OwnerOrPerThreadState<P> The per-thread payload holder. -
Constructor Summary
ConstructorsConstructorDescriptionDelegatingStemmer(Supplier<P> init, Consumer<P> cleanup) Creates the payload holder and the owner payload. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the calling thread's state to prevent classloader leaks in container environments: a per-thread payload is removed, and the owner payload is reset but stays referenced by this instance.(package private) static StemmerFactoryrequireFactory(StemmerFactory factory) Validates a factory argument before it is captured by a subclass supplier, so anullfactory fails at construction rather than on first use.
-
Field Details
-
state
The per-thread payload holder.
-
-
Constructor Details
-
DelegatingStemmer
Creates the payload holder and the owner payload.- Parameters:
init- Creates a payload: once for the owner during construction, and once for each other thread on its first call.cleanup- Resets the owner payload when the owner thread clears its state.
-
-
Method Details
-
requireFactory
Validates a factory argument before it is captured by a subclass supplier, so anullfactory fails at construction rather than on first use.- Parameters:
factory- The factory to validate. Must not benull.- Returns:
factory.- Throws:
IllegalArgumentException- Thrown iffactoryisnull.
-
clearThreadLocalState
public void clearThreadLocalState()Clears the calling thread's state to prevent classloader leaks in container environments: a per-thread payload is removed, and the owner payload is reset but stays referenced by this instance. Call when the thread is returned to a pool or the stemmer is no longer needed, mirroringclearThreadLocalState()on the thread-safe*MEcomponents.
-