Package org.jesterj.ingest.model.impl
Class StepImpl
- java.lang.Object
-
- org.jesterj.ingest.model.impl.StepImpl
-
- All Implemented Interfaces:
java.lang.Iterable<Document>,java.lang.Runnable,java.util.Collection<Document>,java.util.concurrent.BlockingQueue<Document>,java.util.Queue<Document>,Active,Configurable,DeferredBuilding,Step
- Direct Known Subclasses:
ScannerImpl
public class StepImpl extends java.lang.Object implements Step
The class that is used to runDocumentProcessors. This class takes care of the handling of the document ensures it is properly received and passed on. This class is not normally overridden, to implement custom processing logic write a class that implementsDocumentProcessorand then build a stepImpl that uses an instance of your processor. Also note that one does not normally call build on a StepImpl or any of its subclasses. The builder for this class is provided to aPlanImpl.Builderso that the plan can validate the ordering of the steps and assemble the entire plan as an immutable DAG.
IMPORTANT: no field in this class or it's subclasses should be mutated after the builder has been built unless it is sufficiently synchronized. Once built this class and all sub-classes should be thread safe.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStepImpl.Builder
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringVIA-
Fields inherited from interface org.jesterj.ingest.model.Configurable
VALID_NAME
-
Fields inherited from interface org.jesterj.ingest.model.Step
JJ_PLAN_NAME, JJ_PLAN_VERSION
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate()Begin processing.booleanadd(Document document)booleanaddAll(java.util.Collection<? extends Document> c)voidaddDeferred(java.lang.Runnable builderAction)voidaddPredecessor(StepImpl obj)Register a step as a predecessor of this step (one that might send documents to this step).voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)voiddeactivate()Stop processing.intdrainTo(java.util.Collection<? super Document> c)intdrainTo(java.util.Collection<? super Document> c, int maxElements)Documentelement()voidexecuteDeferred()voidforEach(java.util.function.Consumer<? super Document> action)intgetBatchSize()Set the number of items to process concurrently.java.util.Set<Step>getDownstreamOutputSteps()Identify the downstream steps that must only be executed once per document.java.util.LinkedHashMap<java.lang.String,Step>getEligibleNextSteps(Document d)The steps that are reachable from this step and lead to at least one destination valid for the document.protected org.apache.logging.log4j.LoggergetLogger()java.lang.StringgetName()A name for this object to distinguish it from other objects.java.util.LinkedHashMap<java.lang.String,Step>getNextSteps()The steps that are reachable from this step.NextStepsgetNextSteps(Document doc)Get the next step in the plan for the given documentjava.util.Set<java.lang.String>getOutputDestinationNames()static java.util.regex.PatterngetPatternForStep(java.lang.String name)PlangetPlan()Get the plan instance to which this step belongs.java.util.List<Step>getPriorSteps()DocumentProcessorgetProcessor()RoutergetRouter()booleanisActive()Test if the step is active and should be processing.booleanisActivePriorSteps()Determine if any upstream steps are still active.booleanisEmpty()booleanisOutputStep()java.util.Iterator<Document>iterator()booleanoffer(Document document)booleanoffer(Document document, long timeout, java.util.concurrent.TimeUnit unit)java.util.stream.Stream<Document>parallelStream()Documentpeek()Documentpoll()Documentpoll(long timeout, java.util.concurrent.TimeUnit unit)voidput(Document document)Attempt to send the document to this step blocking if the queue for this step is full.intremainingCapacity()Documentremove()booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanremoveIf(java.util.function.Predicate<? super Document> filter)protected voidreportException(java.util.Map.Entry<Step,NextSteps.StepStatusHolder> entry, java.lang.String message, java.lang.Object... params)booleanretainAll(java.util.Collection<?> c)voidrun()voidsendToNext(Document doc)After processing is complete, send it on to any subsequent steps if appropriate.intsize()java.util.Spliterator<Document>spliterator()java.util.stream.Stream<Document>stream()Documenttake()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jesterj.ingest.model.Configurable
isValidName
-
Methods inherited from interface org.jesterj.ingest.model.Step
isOutputDestinationThisStep
-
-
-
-
Field Detail
-
VIA
public static final java.lang.String VIA
- See Also:
- Constant Field Values
-
-
Method Detail
-
getPatternForStep
public static java.util.regex.Pattern getPatternForStep(java.lang.String name)
-
spliterator
public java.util.Spliterator<Document> spliterator()
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<Document>
-
poll
public Document poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
pollin interfacejava.util.concurrent.BlockingQueue<Document>- Throws:
java.lang.InterruptedException
-
parallelStream
public java.util.stream.Stream<Document> parallelStream()
- Specified by:
parallelStreamin interfacejava.util.Collection<Document>
-
take
public Document take() throws java.lang.InterruptedException
- Specified by:
takein interfacejava.util.concurrent.BlockingQueue<Document>- Throws:
java.lang.InterruptedException
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<Document>
-
iterator
public java.util.Iterator<Document> iterator()
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<Document>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<Document>
-
addAll
public boolean addAll(java.util.Collection<? extends Document> c)
- Specified by:
addAllin interfacejava.util.Collection<Document>
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfacejava.util.concurrent.BlockingQueue<Document>
-
stream
public java.util.stream.Stream<Document> stream()
- Specified by:
streamin interfacejava.util.Collection<Document>
-
offer
public boolean offer(Document document, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue<Document>- Throws:
java.lang.InterruptedException
-
offer
public boolean offer(Document document)
-
drainTo
public int drainTo(java.util.Collection<? super Document> c, int maxElements)
- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue<Document>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<Document>
-
put
public void put(Document document) throws java.lang.InterruptedException
Attempt to send the document to this step blocking if the queue for this step is full. This method does NOT guarantee delivery however, and will return immediately if the destination step is shutting down.- Specified by:
putin interfacejava.util.concurrent.BlockingQueue<Document>- Parameters:
document- the element to add- Throws:
java.lang.InterruptedException- if interrupted while waiting
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<Document>
-
contains
public boolean contains(java.lang.Object o)
-
remove
public boolean remove(java.lang.Object o)
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<Document>
-
add
public boolean add(Document document)
-
forEach
public void forEach(java.util.function.Consumer<? super Document> action)
- Specified by:
forEachin interfacejava.lang.Iterable<Document>
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<Document>
-
removeIf
public boolean removeIf(java.util.function.Predicate<? super Document> filter)
- Specified by:
removeIfin interfacejava.util.Collection<Document>
-
drainTo
public int drainTo(java.util.Collection<? super Document> c)
- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue<Document>
-
getBatchSize
public int getBatchSize()
Description copied from interface:StepSet the number of items to process concurrently.- Specified by:
getBatchSizein interfaceStep- Returns:
- the batch size.
-
getNextSteps
public NextSteps getNextSteps(Document doc)
Description copied from interface:StepGet the next step in the plan for the given document- Specified by:
getNextStepsin interfaceStep- Parameters:
doc- the document for which a next step should be determined.- Returns:
- the getNext step
-
getPlan
public Plan getPlan()
Description copied from interface:StepGet the plan instance to which this step belongs.
-
activate
public void activate()
Description copied from interface:ActiveBegin processing. This is the on switch.
-
deactivate
public void deactivate()
Description copied from interface:ActiveStop processing. This is the stop switch.- Specified by:
deactivatein interfaceActive
-
isActive
public boolean isActive()
Test if the step is active and should be processing. It is a good idea for operations running in the worker thread to check this method in loops and before operations that could block or take a long time. Doing so promotes timely shutdown.
-
sendToNext
public void sendToNext(Document doc)
Description copied from interface:StepAfter processing is complete, send it on to any subsequent steps if appropriate. This method may inspect the document status and if the document is not dropped, errored, etc. and there are multiple possible destination steps it should invoke the router to determine the appropriate destinations and conduct the submission of the results to the indicated steps.- Specified by:
sendToNextin interfaceStep- Parameters:
doc- The document for which processing is complete.
-
getOutputDestinationNames
public java.util.Set<java.lang.String> getOutputDestinationNames()
- Specified by:
getOutputDestinationNamesin interfaceStep
-
getDownstreamOutputSteps
public java.util.Set<Step> getDownstreamOutputSteps()
Description copied from interface:StepIdentify the downstream steps that must only be executed once per document.- Specified by:
getDownstreamOutputStepsin interfaceStep- Returns:
- The steps downstream from this one that are neither safe nor idempotent.
-
isOutputStep
public boolean isOutputStep()
- Specified by:
isOutputStepin interfaceStep
-
getNextSteps
public java.util.LinkedHashMap<java.lang.String,Step> getNextSteps()
Description copied from interface:StepThe steps that are reachable from this step.- Specified by:
getNextStepsin interfaceStep- Returns:
- A map of steps keyed by their names.
-
getEligibleNextSteps
public java.util.LinkedHashMap<java.lang.String,Step> getEligibleNextSteps(Document d)
Description copied from interface:StepThe steps that are reachable from this step and lead to at least one destination valid for the document.- Specified by:
getEligibleNextStepsin interfaceStep- Returns:
- A map of steps keyed by their names.
-
isActivePriorSteps
public boolean isActivePriorSteps()
Description copied from interface:StepDetermine if any upstream steps are still active. A true result implies that documents may yet be received for processing, and it is not safe to shut down the processing thread for this step.- Specified by:
isActivePriorStepsin interfaceStep- Returns:
- true if any immediately prior steps are still active
-
getPriorSteps
public java.util.List<Step> getPriorSteps()
- Specified by:
getPriorStepsin interfaceStep
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
getName
public java.lang.String getName()
Description copied from interface:ConfigurableA name for this object to distinguish it from other objects. This value is generally supplied by the plan author. Every object in a plan must have a unique name, begin with a letter and only contain letters, digits, underscores and periods.- Specified by:
getNamein interfaceConfigurable- Returns:
- The user supplied name for this step
-
getLogger
protected org.apache.logging.log4j.Logger getLogger()
-
reportException
protected void reportException(java.util.Map.Entry<Step,NextSteps.StepStatusHolder> entry, java.lang.String message, java.lang.Object... params)
-
executeDeferred
public void executeDeferred()
- Specified by:
executeDeferredin interfaceDeferredBuilding
-
addDeferred
public void addDeferred(java.lang.Runnable builderAction)
- Specified by:
addDeferredin interfaceDeferredBuilding
-
getProcessor
public DocumentProcessor getProcessor()
-
addPredecessor
public void addPredecessor(StepImpl obj)
Description copied from interface:StepRegister a step as a predecessor of this step (one that might send documents to this step).- Specified by:
addPredecessorin interfaceStep- Parameters:
obj- The step to register as a potential upstream source of documents.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-