FlowFiles in an atomic unit.
A process session is always tied to a single Processor at any one time
and ensures no FlowFile can ever be accessed by any more than one processor at a given time.
The session also ensures that all FlowFiles are always accounted for.
The creator of a process session is always required to manage the session.
A session is not considered thread safe. The session supports a unit of work that is either committed or rolled back.
As noted on specific methods and for specific exceptions automated rollback will occur to ensure consistency of the repository. However, several situations can result in exceptions yet not cause automated rollback. In these cases the consistency of the repository will be retained but callers will be able to indicate whether it should result in rollback or continue on toward a commit.
A process session has two types of 'terminal' methods that will result in the session being in a 'fresh' state,
containing no knowledge or any FlowFile, as if the session were newly created.
After one of these methods is called, the instance may be used again.
The terminal methods for a process session are commitAsync() and rollback() (and their overloads).
Additionally, the migrate(ProcessSession, Collection) method transfers all knowledge of the provided FlowFiles
to the other process session, as if the FlowFiles never existed in this process session.
Note, however, that even if all FlowFiles are migrated via the migrate(ProcessSession, Collection) method,
the session is not necessarily entirely cleared, as it still may have knowledge of counter adjustments or state changes,
e.g. see methods adjustCounter(String, long, boolean) or setState(Map, Scope).
A commit or rollback will clear these changes as well.
-
Method Summary
Modifier and TypeMethodDescriptionvoidadjustCounter(String name, long delta, boolean immediate) Adjusts counter data for the given counter name and takes care of registering the counter if not already present.append(FlowFile source, OutputStreamCallback writer) Executes the given {code writer}OutputStreamCallbackagainst the content of the givenFlowFile, such that any data written to the OutputStream will be appended to the end of FlowFile's content.voidclearState(Scope scope) Clears all keys and values from the component's state.Creates a newFlowFilewith a parent linkage to theexampleFlowFile.Creates a newFlowFilewith a parent linkage to theparentFlowFile.voidcommit()Commits the current session ensuring all operations againstFlowFiles within this session are atomically persisted.voidCommits the current session ensuring all operations againstFlowFiles within this session are atomically persisted.default voidcommitAsync(Runnable onSuccess) Commits the current session ensuring all operations againstFlowFiles within this session are atomically persisted.voidcommitAsync(Runnable onSuccess, Consumer<Throwable> onFailure) Commits the current session ensuring all operations against FlowFiles within this session are atomically persisted.create()Creates a newFlowFilein the repository with no content and without any linkage to a parent FlowFile.create(Collection<FlowFile> parents) Creates a newFlowFilein the repository with no content but with a parent linkage to allparents.Creates a newFlowFilein the repository with no content but with a parent linkage to theparent.voidexportTo(FlowFile flowFile, OutputStream destination) voidget()Returns theFlowFilefrom the work queue that is next highest priority to process.get(int maxResults) Returns the next up tomaxResultsFlowFiles from the work queue that are the highest priority to process.get(FlowFileFilter filter) Returns allFlowFiles from all the incoming queues which the givenFlowFileFilteraccepts.Returns theQueueSizethat represents the number ofFlowFiles and their combined data size for all FlowFiles waiting to be processed by theProcessorthat ownsthisProcessSession, regardless of which connection the FlowFiles live on.Returns the current state for the component.importFrom(InputStream source, FlowFile destination) importFrom(Path source, boolean keepSourceFile, FlowFile destination) merge(Collection<FlowFile> sources, FlowFile destination) Combines the content of all givensourcesFlowFiles into a single given destination FlowFile.merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) Combines the content of all givensourcesFlowFiles into a single given destination FlowFile.voidmigrate(ProcessSession newOwner) voidmigrate(ProcessSession newOwner, Collection<FlowFile> flowFiles) Migrates ownership of the givenflowFilesFlowFiles fromthissession to the givennewOwnerProcessSession.Sets a penalty for the givenFlowFile, which will make it unavailable to be operated on any further during the penalty period.putAllAttributes(FlowFile flowFile, Map<String, String> attributes) putAttribute(FlowFile flowFile, String key, String value) Provides anInputStreamthat can be used to read the content of the givenFlowFile.voidread(FlowFile source, InputStreamCallback reader) Executes the given {code reader}InputStreamCallbackagainst the content of the givenFlowFile.voidremove(Collection<FlowFile> flowFiles) Ends the managed persistence for the givenFlowFiles.voidEnds the managed persistence for the givenFlowFile.removeAllAttributes(FlowFile flowFile, Pattern keyPattern) Removes all attributes from the givenFlowFilewhose key matches the given pattern.removeAllAttributes(FlowFile flowFile, Set<String> keys) Removes the attributes with the givenkeysfrom the givenFlowFile.removeAttribute(FlowFile flowFile, String key) Removes the attribute with the givenkeyfrom the givenFlowFile.booleanUpdates the value of the component's state, setting it to givennewValue, if and only if the current value is the same as the givenoldValue.voidrollback()Reverts any changes made during this session.voidrollback(boolean penalize) Reverts any changes made during this session.voidUpdates the value of the component's state, setting it to given value.voidtransfer(Collection<FlowFile> flowFiles) Transfers the givenFlowFiles back to the work queues from which the FlowFiles were pulled.voidtransfer(Collection<FlowFile> flowFiles, Relationship relationship) Transfers the givenFlowFiles to the appropriate destination processor work queue(s) based on the givenrelationship.voidTransfers the givenFlowFileback to the work queue from which it was pulled.voidtransfer(FlowFile flowFile, Relationship relationship) Transfers the givenFlowFileto the appropriate destination processor work queue(s) based on the givenrelationship.Provides anOutputStreamthat can be used to write the content of the givenFlowFile.write(FlowFile source, OutputStreamCallback writer) Executes the given {code writer}OutputStreamCallbackagainst the content of the givenFlowFile.write(FlowFile source, StreamCallback writer) Executes the given {code writer}StreamCallbackagainst the content of the givenFlowFile.
-
Method Details
-
commit
void commit()Commits the current session ensuring all operations againstFlowFiles within this session are atomically persisted. All FlowFiles operated on within this session must be accounted for by transfer or removal or the commit will fail.As soon as the commit completes the session is again ready to be used.
See
commitAsync(),commitAsync(Runnable), andcommitAsync(Runnable, Consumer). The asynchronous session commit methods are preferable to this commit call for most cases as it defers when the actual commit happens to the framework so that it can optimize when the commit call takes place.- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)).FlowFileHandlingException- if not allFlowFiles acted upon within this session are accounted for such that they have a transfer identified or where marked for removal. Automated rollback occurs.ProcessException- if some general fault occurs while persisting the session. Initiates automatic rollback. The root cause can be obtained viaThrowable.getCause().
-
commitAsync
void commitAsync()Commits the current session ensuring all operations againstFlowFiles within this session are atomically persisted. All FlowFiles operated on within this session must be accounted for by transfer or removal or the commit will fail.Unlike the
commit()method, the persistence of data to the repositories is not guaranteed to have occurred by the time that this method returns. Therefore, if any follow-on actions are necessary after the data has been persisted to the repository (for example, acknowledging receipt from a source system, removing a source file, etc.) that logic should be performed only by invokingcommitAsync(Runnable)orcommitAsync(Runnable, Consumer)and implementing that action in the provided callback.As a result, the following very common idiom:
Cannot be simply changed to:getDataFromSource(); session.commit(); acknowledgeReceiptOfData();
Doing so could result in acknowledging receipt of data from the source system before data has been committed to the repositories. If NiFi were to then be restarted, there is potential for data loss. Rather, the following idiom should take its place to ensure that there is no data loss:getDataFromSource(); session.commitAsync(); acknowledgeReceiptOfData();getDataFromSource(); session.commitAsync( () -> acknowledgeReceiptOfData() );If the session cannot be committed, an error will be logged and the session will be rolled back instead.
- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)).FlowFileHandlingException- if not allFlowFiles acted upon within this session are accounted for such that they have a transfer identified or where marked for removal. Automated rollback occurs.
-
commitAsync
Commits the current session ensuring all operations againstFlowFiles within this session are atomically persisted. All FlowFiles operated on within this session must be accounted for by transfer or removal or the commit will fail.If the session is successfully committed, the given
onSuccessRunnablewill be called. At the point that the session commit is completed, any calls torollback()/rollback(boolean)will not undo that session commit but instead roll back any changes that may have occurred since.If, for any reason, the session could not be committed, an error-level log message will be generated, but the caller will not have a chance to perform any cleanup logic. If such logic is necessary, use
commitAsync(Runnable, Consumer)instead.Unlike the
commit()method, the persistence of data to the repositories is not guaranteed to have occurred by the time that this method returns.- Parameters:
onSuccess-Runnablethat will be called if and when the session is successfully committed; may be null- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)).FlowFileHandlingException- if not allFlowFiles acted upon within this session are accounted for such that they have a transfer identified or where marked for removal. Automated rollback occurs.
-
commitAsync
Commits the current session ensuring all operations against FlowFiles within this session are atomically persisted. All FlowFiles operated on within this session must be accounted for by transfer or removal or the commit will fail.If the session is successfully committed, the given
onSuccessRunnablewill be called. At the point that the session commit is completed, any calls torollback()/rollback(boolean)will not undo that session commit but instead roll back any changes that may have occurred since.If, for any reason, the session could not be committed, the given
onFailureConsumerwill be called instead of theonSuccessRunnable. The Consumer will be provided the Throwable that prevented the session commit from completing.Unlike the
commit()method, the persistence of data to the repositories is not guaranteed to have occurred by the time that this method returns.- Parameters:
onSuccess-Runnablethat will be called if and when the session is successfully committed; may be nullonFailure-Consumerthat will be called if, for any reason, the session could not be committed; may be null- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)).FlowFileHandlingException- if not allFlowFiles acted upon within this session are accounted for such that they have a transfer identified or where marked for removal. Automated rollback occurs.
-
rollback
void rollback()Reverts any changes made during this session. AllFlowFiles are restored back to their initial session state and back to their original queues. If no changes were made since this session was last committed or rolled back, then this method has no effect. This method can be called any number of times. Calling this method is identical to callingrollback(boolean)passingfalseas the parameter. -
rollback
void rollback(boolean penalize) Reverts any changes made during this session. AllFlowFiles are restored back to their initial session state and back to their original queues, after optionally being penalized. If no changes were made since this session was last committed or rolled back, then this method has no effect. This method can be called any number of times.- Parameters:
penalize- whether theFlowFiles that are being restored back to their queues should be penalized
-
migrate
Migrates ownership of the givenflowFilesFlowFiles fromthissession to the givennewOwnerProcessSession.Note, that for any provided FlowFile, if the FlowFile has any child (e.g., by calling
create(FlowFile)and passing the FlowFile as the argument), then all children that were created must also be in the Collection of provided FlowFiles.Also note, that if any FlowFile given is not the most up-to-date version of that FlowFile, then the most up-to-date version of the FlowFile will be migrated to the new owner. For example, if a call to
putAttribute(FlowFile, String, String)is made, passingflowFile1as the FlowFile, and thenflowFile1is passed to this method, then the newest version (including the newly added attribute) will be migrated, not the outdated version of the FlowFile thatflowFile1points to.- Parameters:
newOwner- theProcessSessionthat is to become the new owner of the givenFlowFilesflowFiles- theFlowFiles to migrate- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for any of the affectedFlowFiles
-
migrate
Migrates ownership of allFlowFiles fromthissession to the givennewOwnerProcessSession. Calling this method is identical to callingmigrate(ProcessSession, Collection)passing all FlowFiles owned by this session as the parameter, this encompasses both FlowFiles retrieved from the work queue and newly created or cloned ones.- Parameters:
newOwner- theProcessSessionthat is to become the new owner of allFlowFiles- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for any of the affectedFlowFiles
-
adjustCounter
Adjusts counter data for the given counter name and takes care of registering the counter if not already present. The adjustment occurs only if and when the process session is committed.- Parameters:
name- the name of the counterdelta- the delta by which to modify the counter (+ or -)immediate- if true, the counter will be updated immediately, without regard to whether the session is committed or rolled back; otherwise, the counter will be incremented only if and when the session is committed.
-
get
FlowFile get()Returns theFlowFilefrom the work queue that is next highest priority to process. If no FlowFiles are available, returnsnull.- Returns:
- the
FlowFilefrom the work queue that is next highest priority to process ornull, if none available
-
get
Returns the next up tomaxResultsFlowFiles from the work queue that are the highest priority to process. If no FlowFiles are available, returns an empty list. Will not returnnull.If multiple incoming queues are present, the behavior is unspecified in terms of whether all queues or only a single queue will be polled in a single call.
- Parameters:
maxResults- the maximum number ofFlowFiles to return- Returns:
- up to
maxResultsFlowFiles from the work queue - Throws:
IllegalArgumentException- ifmaxResultsis less than 0
-
get
Returns allFlowFiles from all the incoming queues which the givenFlowFileFilteraccepts.Calls to this method provide exclusive access to the underlying queues. That is, no other thread will be permitted to pull FlowFiles from or add FlowFiles to this
Processor's incoming queues until this method call has returned.- Parameters:
filter- aFlowFileFilterto limit whichFlowFiles are returned- Returns:
- all
FlowFiles from all the incoming queues which the givenFlowFileFilterfilteraccepts.
-
getQueueSize
QueueSize getQueueSize()Returns theQueueSizethat represents the number ofFlowFiles and their combined data size for all FlowFiles waiting to be processed by theProcessorthat ownsthisProcessSession, regardless of which connection the FlowFiles live on.- Returns:
- the number of
FlowFiles and their combined data size in the work queue
-
create
FlowFile create()Creates a newFlowFilein the repository with no content and without any linkage to a parent FlowFile.This method is appropriate only when data is received or created from an external system. Otherwise, this method should be avoided and instead
create(FlowFile)orcreate(Collection)be used.When this method is used, a
ProvenanceEventType.CREATEorProvenanceEventType.RECEIVEevent should be generated. See thegetProvenanceReporter()method andProvenanceReporterclass for more information.- Returns:
- newly created FlowFile
-
create
Creates a newFlowFilein the repository with no content but with a parent linkage to theparent. The newly created FlowFile will inherit all the parent's attributes, except for the UUID.This method will automatically generate a
ProvenanceEventType.FORKor aProvenanceEventType.JOINevent, depending on whether other FlowFiles are generated from the same parent before the session is committed. -
create
Creates a newFlowFilein the repository with no content but with a parent linkage to allparents. The newly created FlowFile will inherit all the attributes that are in common to all parents, except for the UUID.This method will automatically generate a
ProvenanceEventType.JOINevent. -
clone
Creates a newFlowFilewith a parent linkage to theexampleFlowFile. It is a clone of the given FlowFile as of the time this is called, both in attributes and content.This method will automatically generate a
ProvenanceEventType.CLONEevent.- Parameters:
example-FlowFileto be the source of cloning - given FlowFile must be a part of the given session- Returns:
FlowFilethat is a clone of the givenexampleFlowFile- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theexampleFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent
-
clone
Creates a newFlowFilewith a parent linkage to theparentFlowFile. It is a clone of the given FlowFile as of the time this is called, both in attributes and a subset of the content. The content of the new FlowFile will be a subset of the byte sequence of the given FlowFile, starting at the specified offset and with the length specified.This method will automatically generate a
ProvenanceEventType.FORKor aProvenanceEventType.CLONEevent, if the offset is 0 and the size is exactly equal to the size of the example FlowFile.- Parameters:
parent-FlowFileto be the source of cloning - given FlowFile must be a part of the given sessionoffset- of the parentFlowFile's content to base the cloned FlowFile's content onsize- in bytes of the parentFlowFile's content to clone starting from theoffset- Returns:
FlowFilethat is a partial clone of the givenparentFlowFile whose content has the specifiedsize- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theparentFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Or if the specifiedoffset+sizeexceeds the size of theparentFlowFile's content. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent
-
penalize
Sets a penalty for the givenFlowFile, which will make it unavailable to be operated on any further during the penalty period.- Parameters:
flowFile- to penalize- Returns:
- the penalized
FlowFile - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
putAttribute
Updates the givenFlowFile's attributes with the givenkey/valuepair.If the
keyis nameduuid, this attribute will be ignored.- Parameters:
flowFile- to updatekey- of attribute to add or modifyvalue- of attribute to add or modify- Returns:
- the updated
FlowFilewith the attribute added or modified - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
putAllAttributes
Updates the givenFlowFile's attributes with the givenkey/valuepairs.If the map contains a key named
uuid, this attribute will be ignored.- Parameters:
flowFile- to updateattributes- the attributes to add or modify- Returns:
- the updated
FlowFilewith the attributes added or modified - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
removeAttribute
Removes the attribute with the givenkeyfrom the givenFlowFile.The attributes with the keys
uuid,path, andfilenamewill not be removed. If thekeyis one of those, this method will return the same FlowFile without removing any attribute.- Parameters:
flowFile- to updatekey- of attribute to remove- Returns:
- the updated
FlowFilewith the matching attribute removed - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
removeAllAttributes
Removes the attributes with the givenkeysfrom the givenFlowFile.The attributes with the keys
uuid,path, andfilenamewill not be removed.- Parameters:
flowFile- to updatekeys- of attributes to remove- Returns:
- the updated
FlowFilewith the matching attributes removed - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
removeAllAttributes
Removes all attributes from the givenFlowFilewhose key matches the given pattern.The attributes with the keys
uuid,path, andfilenamewill not be removed.- Parameters:
flowFile- to updatekeyPattern- pattern to match eachFlowFileattribute against; may be null, in which case no attribute is removed- Returns:
- the updated
FlowFilewith the matching attributes removed - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
transfer
Transfers the givenFlowFileback to the work queue from which it was pulled.The processor will not be able to operate on the given FlowFile until this session is committed. Any modifications that have been made to the FlowFile will be maintained. FlowFiles that are created by the processor cannot be transferred back to themselves via this method.
- Parameters:
flowFile- to transfer- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.IllegalArgumentException- if the givenFlowFilewas created by this processor
-
transfer
Transfers the givenFlowFiles back to the work queues from which the FlowFiles were pulled.The processor will not be able to operate on the given FlowFiles until this session is committed. Any modifications that have been made to the FlowFiles will be maintained. FlowFiles that are created by the processor cannot be transferred back to themselves via this method.
- Parameters:
flowFiles- to transfer- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if any of the givenFlowFiles is already transferred or removed or doesn't belong to this session. Automatic rollback will occur.IllegalArgumentException- if any of the givenFlowFiles was created by this processor
-
transfer
Transfers the givenFlowFileto the appropriate destination processor work queue(s) based on the givenrelationship.If the relationship leads to more than one destination the state of the FlowFile is replicated such that each destination receives an exact copy of the FlowFile though each will have its own unique identity. The destination processors will not be able to operate on the given FlowFile until this session is committed or until the ownership of the session is migrated to another processor. If ownership of the session is passed to a destination processor then that destination processor will have immediate visibility of the transferred FlowFiles within the session.
- Parameters:
flowFile- to transferrelationship- to transfer to- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for theflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.IllegalArgumentException- if given relationship is not a known or registered relationship
-
transfer
Transfers the givenFlowFiles to the appropriate destination processor work queue(s) based on the givenrelationship.If the relationship leads to more than one destination the state of each FlowFile is replicated such that each destination receives an exact copy of the FlowFile though each will have its own unique identity. The destination processors will not be able to operate on the given FlowFiles until this session is committed or until the ownership of the session is migrated to another processor. If ownership of the session is passed to a destination processor then that destination processor will have immediate visibility of the transferred FlowFiles within the session.
- Parameters:
flowFiles- to transferrelationship- to transfer to- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for any of theflowFilesFlowFilesFlowFileHandlingException- if any of the givenFlowFiles is already transferred or removed or doesn't belong to this session. Automatic rollback will occur.IllegalArgumentException- if given relationship is not a known or registered relationship
-
remove
Ends the managed persistence for the givenFlowFile.The persistent attributes for the FlowFile are deleted and so is the content assuming nothing else references it. This FlowFile will no longer be available for further operation.
- Parameters:
flowFile- to remove- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givenflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
remove
Ends the managed persistence for the givenFlowFiles.The persistent attributes for the FlowFiles are deleted and so is the content assuming nothing else references it. The FlowFiles will no longer be available for further operation.
- Parameters:
flowFiles- to remove- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for any of the givenflowFilesFlowFilesFlowFileHandlingException- if any of the givenFlowFiles is already transferred or removed or doesn't belong to this session. Automatic rollback will occur.
-
read
Executes the given {code reader}InputStreamCallbackagainst the content of the givenFlowFile.- Parameters:
source- theFlowFileto retrieve the content fromreader-InputStreamCallbackthat will be called to read theFlowFilecontent- Throws:
IllegalStateException- if detected that this method is being called from within a write callback (seewrite(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a write stream is open (seewrite(FlowFile)) for the givensourceFlowFile. Said another way, it is not permissible to call this method while writing to the same FlowFile.FlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; if an attempt is made to access theInputStreamprovided to the givenInputStreamCallbackafter this method completed its execution
-
read
Provides anInputStreamthat can be used to read the content of the givenFlowFile.This method differs from those that make use of callbacks in that this method returns an InputStream and expects the caller to properly handle the lifecycle of the InputStream (i.e., the caller is responsible for ensuring that the InputStream is closed appropriately). The session may or may not handle closing the stream when the session is commited or rolled back, but the responsibility of doing so belongs to the caller.
- Parameters:
flowFile- theFlowFileto retrieve the content from- Returns:
- an
InputStreamthat can be used to read the content of theFlowFile - Throws:
IllegalStateException- if detected that this method is being called from within a write callback (seewrite(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a write stream is open (seewrite(FlowFile)) for the givenflowFileFlowFile. Said another way, it is not permissible to call this method while writing to the same FlowFile.FlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; if an attempt is made to read from the stream after the session is committed or rolled back.
-
merge
Combines the content of all givensourcesFlowFiles into a single given destination FlowFile.- Parameters:
sources- theFlowFiles whose content to mergedestination- theFlowFileto use as the merged result- Returns:
- the updated
destinationdestinationFlowFilewith changed content - Throws:
IllegalArgumentException- if the given destination is contained within the sourcesIllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for any of the givensourcesanddestinationFlowFilesFlowFileHandlingException- if any of the givenFlowFiles is already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if any of the givenFlowFile's content cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; the state of thedestinationFlowFilewill be as it was prior to this call.
-
merge
FlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) Combines the content of all givensourcesFlowFiles into a single given destination FlowFile.- Parameters:
sources- theFlowFiles whose content to mergedestination- theFlowFileto use as the merged resultheader- bytes that will be added to the beginning of the merged output; may be null or emptyfooter- bytes that will be added to the end of the merged output; may be null or emptydemarcator- bytes that will be placed in between each object merged together; may be null or empty- Returns:
- the updated
destinationFlowFilewith changed content - Throws:
IllegalArgumentException- if the given destination is contained within the sourcesIllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for any of the givensourcesanddestinationFlowFilesFlowFileHandlingException- if any of the givenFlowFiles is already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if any of the givenFlowFile's content cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; the state of thedestinationFlowFilewill be as it was prior to this call.
-
write
Executes the given {code writer}OutputStreamCallbackagainst the content of the givenFlowFile.- Parameters:
source- theFlowFileto write the content ofwriter-InputStreamCallbackthat will be called to write theFlowFilecontent- Returns:
- the updated
sourceFlowFilewith changed content - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givensourceFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; if an attempt is made to access theOutputStreamprovided to the givenOutputStreamCallbackafter this method completed its execution
-
write
Provides anOutputStreamthat can be used to write the content of the givenFlowFile.This method differs from those that make use of callbacks in that this method returns an OutputStream and expects the caller to properly handle the lifecycle of the OutputStream (i.e., the caller is responsible for ensuring that the OutputStream is closed appropriately). The session may or may not handle closing the stream when the session is commited or rolled back, but the responsibility of doing so belongs to the caller.
- Parameters:
source- theFlowFileto write the content of- Returns:
- an
OutputStreamthat can be used to write the content of theFlowFile - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givensourceFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; if an attempt is made to write to the stream after the session is committed or rolled back.
-
write
Executes the given {code writer}StreamCallbackagainst the content of the givenFlowFile.- Parameters:
source- theFlowFileto read and write the content ofwriter-StreamCallbackthat will be called to read and write theFlowFilecontent- Returns:
- the updated
sourceFlowFilewith changed content - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givensourceFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; if an attempt is made to access theInputStreamorOutputStreamprovided to the givenStreamCallbackafter this method completed its execution
-
append
Executes the given {code writer}OutputStreamCallbackagainst the content of the givenFlowFile, such that any data written to the OutputStream will be appended to the end of FlowFile's content.- Parameters:
source- theFlowFileto extend the content ofwriter-OutputStreamCallbackthat will be called to append theFlowFile's content- Returns:
- the updated
sourceFlowFilewith changed content - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givensourceFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent; if an attempt is made to access theOutputStreamprovided to the givenOutputStreamCallbackafter this method completed its execution
-
importFrom
- Parameters:
source- thePathto the file from which content will be obtainedkeepSourceFile- if true the content is simply copied; if false the original content might be used in a destructive way for efficiency, such that the repository will have the data but the original data will be gone. If false the source object will be removed or gone once imported. It will not be restored if the session is rolled back so this must be used with caution. In some cases it can result in tremendous efficiency gains but is also dangerous.destination- theFlowFilewhose content will be updated- Returns:
- the updated
destinationFlowFilewith changed content - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givensourceFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent
-
importFrom
- Parameters:
source- theInputStreamfrom which content will be obtaineddestination- theFlowFilewhose content will be updated- Returns:
- the updated
destinationFlowFilewith changed content - Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givensourceFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent
-
exportTo
- Parameters:
flowFile- theFlowFileto export the content ofdestination- thePathto a file to export theFlowFile's content toappend- if true will append to the current content of the file at the given path; if false will replace any current content- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givenflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent
-
exportTo
- Parameters:
flowFile- theFlowFileto export the content ofdestination- theOutputStreamto export theFlowFile's content to- Throws:
IllegalStateException- if detected that this method is being called from within a read or write callback (seeread(FlowFile, InputStreamCallback),write(FlowFile, StreamCallback),write(FlowFile, OutputStreamCallback)) or while a read or write stream is open (seeread(FlowFile),write(FlowFile)) for the givenflowFileFlowFileFlowFileHandlingException- if the givenFlowFileis already transferred or removed or doesn't belong to this session. Automatic rollback will occur.MissingFlowFileException- if the givenFlowFilecontent cannot be found. The FlowFile should no longer be referenced, will be internally destroyed. The session is automatically rolled back.FlowFileAccessException- if some IO problem occurs accessingFlowFilecontent
-
getProvenanceReporter
ProvenanceReporter getProvenanceReporter()- Returns:
- the
ProvenanceReporterthat is tied tothisProcessSession
-
setState
Updates the value of the component's state, setting it to given value.This method does not update the remote State Provider immediately but rather caches the value until the session is committed. At that point, it will publish the state to the remote State Provider, if the state is the latest according to the remote State Provider.
- Parameters:
state- the value to change the state toscope- theScopeto use when storing the state- Throws:
IOException- if unable to communicate with the underlying storage mechanism
-
getState
Returns the current state for the component.This return value will never be
null. If the state has not yet been set, the StateMap's version will be -1, and the map of values will be empty.- Parameters:
scope- theScopeto use when fetching the state- Returns:
- the current state for the component
- Throws:
IOException- if unable to communicate with the underlying storage mechanism
-
replaceState
boolean replaceState(StateMap oldValue, Map<String, String> newValue, Scope scope) throws IOExceptionUpdates the value of the component's state, setting it to givennewValue, if and only if the current value is the same as the givenoldValue.The oldValue will be compared against the value of the state as it is known to
thisProcessSession. If the Process Session does not currently know the state, it will be fetched from the StateProvider.This method does not update the remote State Provider immediately but rather caches the value until the session is committed. At that point, it will publish the state to the remote State Provider, if the state is the latest according to the remote State Provider.
- Parameters:
oldValue- the value to compare the state's current value againstnewValue- the new value to use if and only if the state's current value is the same as the givenoldValuescope- theScopeto use for fetching the current and storing the new state- Returns:
trueif the state was updated to thenewValue,falseif the state's current value was not equal tooldValue- Throws:
IOException- if unable to communicate with the underlying storage mechanism
-
clearState
Clears all keys and values from the component's state.This method does not update the remote State Provider immediately but rather caches the value until the session is committed. At that point, it will publish the state to the remote State Provider, if the state is the latest according to the remote State Provider.
- Parameters:
scope- theScopeto use for clearing the state- Throws:
IOException- if unable to communicate with the underlying storage mechanism.
-