public interface ProcessSession
A process session encompasses all the behaviors a processor can perform to obtain, clone, read, modify remove 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 ProcessSession 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 'terminal' methods that will result in the process session
being in a 'fresh', 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 the commit()
and rollback()
. Additionally,
the migrate(ProcessSession, Collection)
method results in this
containing
no knowledge of any of the FlowFiles that are provided, as if the FlowFiles never existed in
this ProcessSession. After each commit or rollback, the session can be used again. Note, however,
that even if all FlowFiles are migrated via the migrate(ProcessSession, Collection)
method,
this Process Session is not entirely cleared, as it still has knowledge of Counters that were adjusted
via the adjustCounter(String, long, boolean)
method. A commit or rollback will clear these
counters, as well.
Modifier and Type | Method and Description |
---|---|
void |
adjustCounter(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.
|
FlowFile |
append(FlowFile source,
OutputStreamCallback writer)
Executes the given callback against the content corresponding to the
given FlowFile, such that any data written to the OutputStream of the
content will be appended to the end of FlowFile.
|
FlowFile |
clone(FlowFile example)
Creates a new FlowFile that is a clone of the given FlowFile as of the
time this is called, both in content and attributes.
|
FlowFile |
clone(FlowFile parent,
long offset,
long size)
Creates a new FlowFile whose parent is the given FlowFile.
|
void |
commit()
Commits the current session ensuring all operations against FlowFiles
within this session are atomically persisted.
|
FlowFile |
create()
Creates a new FlowFile in the repository with no content and without any
linkage to a parent FlowFile.
|
FlowFile |
create(Collection<FlowFile> parents)
Creates a new FlowFile in the repository with no content but with a
parent linkage to the FlowFiles specified by the parents Collection.
|
FlowFile |
create(FlowFile parent)
Creates a new FlowFile in the repository with no content but with a
parent linkage to
parent . |
void |
exportTo(FlowFile flowFile,
OutputStream destination)
Writes the content of the given FlowFile to the given destination stream
|
void |
exportTo(FlowFile flowFile,
Path destination,
boolean append)
Writes the content of the given FlowFile to the given destination path.
|
FlowFile |
get() |
List<FlowFile> |
get(FlowFileFilter filter)
Returns all FlowFiles from all of the incoming queues for which the given
FlowFileFilter indicates should be accepted. |
List<FlowFile> |
get(int maxResults)
Returns up to
maxResults FlowFiles from the work queue. |
ProvenanceReporter |
getProvenanceReporter()
Returns a ProvenanceReporter that is tied to this ProcessSession.
|
QueueSize |
getQueueSize() |
FlowFile |
importFrom(InputStream source,
FlowFile destination)
Writes to the given FlowFile all content from the given content path.
|
FlowFile |
importFrom(Path source,
boolean keepSourceFile,
FlowFile destination)
Writes to the given FlowFile all content from the given content path.
|
FlowFile |
merge(Collection<FlowFile> sources,
FlowFile destination)
Combines the content of all given source FlowFiles into a single given
destination FlowFile.
|
FlowFile |
merge(Collection<FlowFile> sources,
FlowFile destination,
byte[] header,
byte[] footer,
byte[] demarcator)
Combines the content of all given source FlowFiles into a single given
destination FlowFile.
|
void |
migrate(ProcessSession newOwner,
Collection<FlowFile> flowFiles)
Migrates ownership of the given FlowFiles from
this to the given newOwner . |
FlowFile |
penalize(FlowFile flowFile)
Sets a penalty for the given FlowFile which will make it unavailable to
be operated on any further during the penalty period.
|
FlowFile |
putAllAttributes(FlowFile flowFile,
Map<String,String> attributes)
Updates the given FlowFiles attributes with the given key/value pairs.
|
FlowFile |
putAttribute(FlowFile flowFile,
String key,
String value)
Updates the given FlowFiles attributes with the given key/value pair.
|
InputStream |
read(FlowFile flowFile)
Provides an InputStream that can be used to read the contents of the given FlowFile.
|
void |
read(FlowFile source,
boolean allowSessionStreamManagement,
InputStreamCallback reader)
Executes the given callback against the contents corresponding to the
given FlowFile.
|
void |
read(FlowFile source,
InputStreamCallback reader)
Executes the given callback against the contents corresponding to the
given FlowFile.
|
void |
remove(Collection<FlowFile> flowFiles)
Ends the managed persistence for the given FlowFiles.
|
void |
remove(FlowFile flowFile)
Ends the managed persistence for the given FlowFile.
|
FlowFile |
removeAllAttributes(FlowFile flowFile,
Pattern keyPattern)
Remove all attributes from the given FlowFile that have keys which match
the given pattern.
|
FlowFile |
removeAllAttributes(FlowFile flowFile,
Set<String> keys)
Removes the attributes with the given keys from the given FlowFile.
|
FlowFile |
removeAttribute(FlowFile flowFile,
String key)
Removes the given FlowFile attribute with the given key.
|
void |
rollback()
Reverts any changes made during this session.
|
void |
rollback(boolean penalize)
Reverts any changes made during this session.
|
void |
transfer(Collection<FlowFile> flowFiles)
Transfers the given FlowFiles back to the work queues from which the
FlowFiles were pulled.
|
void |
transfer(Collection<FlowFile> flowFiles,
Relationship relationship)
Transfers the given FlowFile to the appropriate destination processor
work queue(s) based on the given relationship.
|
void |
transfer(FlowFile flowFile)
Transfers the given FlowFile back to the work queue from which it was
pulled.
|
void |
transfer(FlowFile flowFile,
Relationship relationship)
Transfers the given FlowFile to the appropriate destination processor
work queue(s) based on the given relationship.
|
FlowFile |
write(FlowFile source,
OutputStreamCallback writer)
Executes the given callback against the content corresponding to the
given FlowFile.
|
FlowFile |
write(FlowFile source,
StreamCallback writer)
Executes the given callback against the content corresponding to the
given flow file.
|
void commit()
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.
As soon as the commit completes the session is again ready to be used
IllegalStateException
- if detected that this method is being
called from within a callback of another method in this session.FlowFileHandlingException
- if not all FlowFiles acted upon within
this session are accounted for by user code 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
via Exception.getCause()
void rollback()
rollback(boolean)
passing
false
as the parameter.void rollback(boolean penalize)
penalize
- whether or not the FlowFiles that are being restored back
to their queues should be penalizedvoid migrate(ProcessSession newOwner, Collection<FlowFile> flowFiles)
Migrates ownership of the given FlowFiles from this
to the given newOwner
.
When calling this method, all of the following pre-conditions must be met:
write(FlowFile, OutputStreamCallback)
, write(FlowFile, StreamCallback)
,
read(FlowFile, InputStreamCallback)
, read(FlowFile, boolean, InputStreamCallback)
for any of
the given FlowFiles.read(FlowFile)
).create(FlowFile)
and passing the FlowFile
as the argument), then all children that were created must also be in the Collection of provided FlowFiles.newOwner
- the ProcessSession that is to become the new owner of all FlowFiles
that currently belong to this
.flowFiles
- the FlowFiles to migratevoid adjustCounter(String name, long delta, boolean immediate)
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 ProcessSession is commit or rolled back;
otherwise, the counter will be incremented only if and when the
ProcessSession is committed.FlowFile get()
List<FlowFile> get(int maxResults)
maxResults
FlowFiles from the work queue. If
no FlowFiles are available, returns an empty list. Will not return null.
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.maxResults
- the maximum number of FlowFiles to returnmaxResults
FlowFiles from the work queue. If
no FlowFiles are available, returns an empty list. Will not return null.IllegalArgumentException
- if maxResults
is less than
0List<FlowFile> get(FlowFileFilter filter)
Returns all FlowFiles from all of the incoming queues for which the given
FlowFileFilter
indicates should be accepted. Calls to this method
provide exclusive access to the underlying queues. I.e., no other thread
will be permitted to pull FlowFiles from this Processor's queues or add
FlowFiles to this Processor's incoming queues until this method call has
returned.
filter
- to limit which flow files are returnedFlowFileFilter
indicates should be accepted.QueueSize getQueueSize()
FlowFile create()
create(FlowFile)
or
create(Collection)
.
When this method is used, a Provenance CREATE or RECEIVE Event should be
generated. See the getProvenanceReporter()
method and
ProvenanceReporter
class for more informationFlowFile create(FlowFile parent)
parent
. The newly created FlowFile will
inherit all of the parent's attributes except for the UUID. This method
will automatically generate a Provenance FORK event or a Provenance JOIN
event, depending on whether or not other FlowFiles are generated from the
same parent before the ProcessSession is committed.parent
- to base the new flowfile onFlowFile create(Collection<FlowFile> parents)
parents
- which the new flowfile should inherit shared attributes fromFlowFile clone(FlowFile example)
example
- FlowFile to be the source of cloning - given FlowFile must
be a part of the given sessionIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile contentNullPointerException
- if the argument nullFlowFile clone(FlowFile parent, long offset, long size)
parent
- to base the new flowfile attributes onoffset
- of the parent flowfile to base the child flowfile content onsize
- of the new flowfile from the offsetIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFileFlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session, or if the
specified offset + size exceeds that of the size of the parent FlowFile.
Automatic rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFile penalize(FlowFile flowFile)
flowFile
- to penalizeIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if the argument nullFlowFile putAttribute(FlowFile flowFile, String key, String value)
uuid
, this attribute will be ignored.flowFile
- to updatekey
- of attributevalue
- of attributeFlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if an argument is nullFlowFile putAllAttributes(FlowFile flowFile, Map<String,String> attributes)
uuid
, this attribute will be
ignored.flowFile
- to updateattributes
- the attributes to add to the given FlowFileIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if an argument is nullFlowFile removeAttribute(FlowFile flowFile, String key)
uuid
, this method will return the same FlowFile without
removing any attribute.flowFile
- to updatekey
- of attributeIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if the argument nullFlowFile removeAllAttributes(FlowFile flowFile, Set<String> keys)
uuid
, this key will be ignoredflowFile
- to updatekeys
- of attributeIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if the argument nullFlowFile removeAllAttributes(FlowFile flowFile, Pattern keyPattern)
uuid
, this key
will not be removed.flowFile
- to updatekeyPattern
- may be null; if supplied is matched against each of the
FlowFile attribute keysvoid transfer(FlowFile flowFile, Relationship relationship)
flowFile
- to transferrelationship
- to transfer toIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if the argument nullIllegalArgumentException
- if given relationship is not a known or
registered relationshipvoid transfer(FlowFile flowFile)
flowFile
- to transferIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.IllegalArgumentException
- if the FlowFile was created by this
processorNullPointerException
- if the argument nullvoid transfer(Collection<FlowFile> flowFiles)
flowFiles
- to transferIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFiles are already
transferred or removed or don't belong to this session. Automatic
rollback will occur.IllegalArgumentException
- if the FlowFile was created by this
processorNullPointerException
- if the argument nullvoid transfer(Collection<FlowFile> flowFiles, Relationship relationship)
flowFiles
- to transferrelationship
- to transfer toIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.NullPointerException
- if the argument nullIllegalArgumentException
- if given relationship is not a known or
registered relationshipvoid remove(FlowFile flowFile)
flowFile
- to removeIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.void remove(Collection<FlowFile> flowFiles)
flowFiles
- to removeIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if any of the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.void read(FlowFile source, InputStreamCallback reader) throws FlowFileAccessException
source
- flowfile to retrieve content ofreader
- that will be called to read the flowfile contentIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be referenced, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile content; if an attempt is made to access the InputStream
provided to the given InputStreamCallback after this method completed its
executionInputStream read(FlowFile flowFile)
commit()
or rollback()
is called, but the responsibility of doing so belongs to the caller. The InputStream will throw
an IOException if an attempt is made to read from the stream after the session is committed or
rolled back.flowFile
- the FlowFile to readIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be referenced, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.void read(FlowFile source, boolean allowSessionStreamManagement, InputStreamCallback reader) throws FlowFileAccessException
source
- flowfile to retrieve content ofallowSessionStreamManagement
- allow session to hold the stream open for performance reasonsreader
- that will be called to read the flowfile contentIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile content; if an attempt is made to access the InputStream
provided to the given InputStreamCallback after this method completed its
executionFlowFile merge(Collection<FlowFile> sources, FlowFile destination)
sources
- the flowfiles to mergedestination
- the flowfile to use as the merged resultIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)IllegalArgumentException
- if the given destination is contained
within the sourcesFlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile content. The state of the destination will be as it was prior to
this call.FlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator)
sources
- to merge togetherdestination
- to merge toheader
- bytes that will be added to the beginning of the merged
output. May be null or empty.footer
- bytes that will be added to the end of the merged output.
May be null or empty.demarcator
- bytes that will be placed in between each object merged
together. May be null or empty.IllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)IllegalArgumentException
- if the given destination is contained
within the sourcesFlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile content. The state of the destination will be as it was prior to
this call.FlowFile write(FlowFile source, OutputStreamCallback writer) throws FlowFileAccessException
source
- to write towriter
- used to write new contentIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be referenced, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile content; if an attempt is made to access the OutputStream
provided to the given OutputStreamCallaback after this method completed
its executionFlowFile write(FlowFile source, StreamCallback writer) throws FlowFileAccessException
source
- to read from and write towriter
- used to read the old content and write new contentIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile content; if an attempt is made to access the InputStream or
OutputStream provided to the given StreamCallback after this method
completed its executionFlowFile append(FlowFile source, OutputStreamCallback writer) throws FlowFileAccessException
source
- the flowfile for which content should be appendedwriter
- used to write new bytes to the flowfile contentFlowFileAccessException
- if an attempt is made to access the
OutputStream provided to the given OutputStreamCallaback after this
method completed its executionFlowFile importFrom(Path source, boolean keepSourceFile, FlowFile destination)
source
- 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
- the FlowFile whose content will be updatedIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile contentFlowFile importFrom(InputStream source, FlowFile destination)
source
- the file from which content will be obtaineddestination
- the FlowFile whose content will be updatedIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile contentvoid exportTo(FlowFile flowFile, Path destination, boolean append)
flowFile
- to export the content ofdestination
- to export the content toappend
- if true will append to the current content at the given
path; if false will replace any current contentIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile contentvoid exportTo(FlowFile flowFile, OutputStream destination)
flowFile
- to export the content ofdestination
- to export the content toIllegalStateException
- if detected that this method is being
called from within a callback of another method in this session and for
the given FlowFile(s)FlowFileHandlingException
- if the given FlowFile is already
transferred or removed or doesn't belong to this session. Automatic
rollback will occur.MissingFlowFileException
- if the given FlowFile content cannot be
found. The FlowFile should no longer be reference, will be internally
destroyed, and the session is automatically rolled back and what is left
of the FlowFile is destroyed.FlowFileAccessException
- if some IO problem occurs accessing
FlowFile contentProvenanceReporter getProvenanceReporter()
Copyright © 2017 Apache NiFi Project. All rights reserved.