public final class StandardProcessSession extends java.lang.Object implements ProcessSession, ProvenanceEventEnricher
Provides a ProcessSession that ensures all accesses, changes and transfers occur in an atomic manner for all FlowFiles including their contents and attributes
NOT THREAD SAFE
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_FLOWFILE_PATH |
static int |
VERBOSE_LOG_THRESHOLD |
Constructor and Description |
---|
StandardProcessSession(ProcessContext context) |
Modifier and Type | Method and Description |
---|---|
void |
adjustCounter(java.lang.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.
|
void |
checkpoint() |
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 example,
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(java.util.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 . |
StandardProvenanceEventRecord |
enrich(ProvenanceEventRecord rawEvent,
FlowFile flowFile)
Returns a new Provenance event that has been updated to contain the original and updated FlowFile attributes and content claim information.
|
void |
expireFlowFiles() |
void |
exportTo(FlowFile source,
java.io.OutputStream destination)
Writes the content of the given FlowFile to the given destination stream
|
void |
exportTo(FlowFile source,
java.nio.file.Path destination,
boolean append)
Writes the content of the given FlowFile to the given destination path.
|
protected void |
finalize() |
FlowFile |
get() |
java.util.List<FlowFile> |
get(FlowFileFilter filter)
Returns all FlowFiles from all of the incoming queues for which the given
FlowFileFilter indicates should be accepted. |
java.util.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(java.io.InputStream source,
FlowFile destination)
Writes to the given FlowFile all content from the given content path.
|
FlowFile |
importFrom(java.nio.file.Path source,
boolean keepSourceFile,
FlowFile destination)
Writes to the given FlowFile all content from the given content path.
|
FlowFile |
merge(java.util.Collection<FlowFile> sources,
FlowFile destination)
Combines the content of all given source FlowFiles into a single given
destination FlowFile.
|
FlowFile |
merge(java.util.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,
java.util.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,
java.util.Map<java.lang.String,java.lang.String> attributes)
Updates the given FlowFiles attributes with the given key/value pairs.
|
FlowFile |
putAttribute(FlowFile flowFile,
java.lang.String key,
java.lang.String value)
Updates the given FlowFiles attributes with the given key/value pair.
|
java.io.InputStream |
read(FlowFile source)
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(java.util.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,
java.util.regex.Pattern keyPattern)
Remove all attributes from the given FlowFile that have keys which match
the given pattern.
|
FlowFile |
removeAllAttributes(FlowFile flowFile,
java.util.Set<java.lang.String> keys)
Removes the attributes with the given keys from the given FlowFile.
|
FlowFile |
removeAttribute(FlowFile flowFile,
java.lang.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.
|
java.lang.String |
toString() |
void |
transfer(java.util.Collection<FlowFile> flowFiles)
Transfers the given FlowFiles back to the work queues from which the
FlowFiles were pulled.
|
void |
transfer(java.util.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.
|
java.io.OutputStream |
write(FlowFile source)
Provides an OutputStream that can be used to write to the contents of the
given FlowFile.
|
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.
|
public static final int VERBOSE_LOG_THRESHOLD
public static final java.lang.String DEFAULT_FLOWFILE_PATH
public StandardProcessSession(ProcessContext context)
public void checkpoint()
public void commit()
ProcessSession
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
commit
in interface ProcessSession
public StandardProvenanceEventRecord enrich(ProvenanceEventRecord rawEvent, FlowFile flowFile)
ProvenanceEventEnricher
enrich
in interface ProvenanceEventEnricher
rawEvent
- recordflowFile
- flowfilepublic void rollback()
ProcessSession
ProcessSession.rollback(boolean)
passing
false
as the parameter.rollback
in interface ProcessSession
public void rollback(boolean penalize)
ProcessSession
rollback
in interface ProcessSession
penalize
- whether or not the FlowFiles that are being restored back
to their queues should be penalizedpublic void migrate(ProcessSession newOwner, java.util.Collection<FlowFile> flowFiles)
ProcessSession
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:
ProcessSession.write(FlowFile, OutputStreamCallback)
, ProcessSession.write(FlowFile, StreamCallback)
,
ProcessSession.read(FlowFile, InputStreamCallback)
, ProcessSession.read(FlowFile, boolean, InputStreamCallback)
for any of
the given FlowFiles.ProcessSession.read(FlowFile)
).ProcessSession.write(FlowFile)
.ProcessSession.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 ProcessSession.putAttribute(FlowFile, String, String)
is made,
passing flowFile1
as the FlowFile, and then flowFile1
is passed to this method, then the newest version (including the
newly added attribute) will be migrated, not the outdated version of the FlowFile that flowFile1
points to.
migrate
in interface ProcessSession
newOwner
- the ProcessSession that is to become the new owner of all FlowFiles
that currently belong to this
.flowFiles
- the FlowFiles to migratepublic void adjustCounter(java.lang.String name, long delta, boolean immediate)
ProcessSession
adjustCounter
in interface ProcessSession
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.public FlowFile get()
get
in interface ProcessSession
public java.util.List<FlowFile> get(int maxResults)
ProcessSession
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.get
in interface ProcessSession
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.public java.util.List<FlowFile> get(FlowFileFilter filter)
ProcessSession
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.
get
in interface ProcessSession
filter
- to limit which flow files are returnedFlowFileFilter
indicates should be accepted.public QueueSize getQueueSize()
getQueueSize
in interface ProcessSession
public FlowFile create()
ProcessSession
ProcessSession.create(FlowFile)
or
ProcessSession.create(Collection)
.
When this method is used, a Provenance CREATE or RECEIVE Event should be
generated. See the ProcessSession.getProvenanceReporter()
method and
ProvenanceReporter
class for more informationcreate
in interface ProcessSession
public FlowFile clone(FlowFile example)
ProcessSession
clone
in interface ProcessSession
example
- FlowFile to be the source of cloning - given FlowFile must
be a part of the given sessionpublic FlowFile clone(FlowFile example, long offset, long size)
ProcessSession
clone
in interface ProcessSession
example
- to base the new flowfile attributes onoffset
- of the parent flowfile to base the child flowfile content onsize
- of the new flowfile from the offsetpublic FlowFile penalize(FlowFile flowFile)
ProcessSession
penalize
in interface ProcessSession
flowFile
- to penalizepublic FlowFile putAttribute(FlowFile flowFile, java.lang.String key, java.lang.String value)
ProcessSession
uuid
, this attribute will be ignored.putAttribute
in interface ProcessSession
flowFile
- to updatekey
- of attributevalue
- of attributepublic FlowFile putAllAttributes(FlowFile flowFile, java.util.Map<java.lang.String,java.lang.String> attributes)
ProcessSession
uuid
, this attribute will be
ignored.putAllAttributes
in interface ProcessSession
flowFile
- to updateattributes
- the attributes to add to the given FlowFilepublic FlowFile removeAttribute(FlowFile flowFile, java.lang.String key)
ProcessSession
uuid
, this method will return the same FlowFile without
removing any attribute.removeAttribute
in interface ProcessSession
flowFile
- to updatekey
- of attributepublic FlowFile removeAllAttributes(FlowFile flowFile, java.util.Set<java.lang.String> keys)
ProcessSession
uuid
, this key will be ignoredremoveAllAttributes
in interface ProcessSession
flowFile
- to updatekeys
- of attributepublic FlowFile removeAllAttributes(FlowFile flowFile, java.util.regex.Pattern keyPattern)
ProcessSession
uuid
, this key
will not be removed.removeAllAttributes
in interface ProcessSession
flowFile
- to updatekeyPattern
- may be null; if supplied is matched against each of the
FlowFile attribute keyspublic void transfer(FlowFile flowFile, Relationship relationship)
ProcessSession
transfer
in interface ProcessSession
flowFile
- to transferrelationship
- to transfer topublic void transfer(FlowFile flowFile)
ProcessSession
transfer
in interface ProcessSession
flowFile
- to transferpublic void transfer(java.util.Collection<FlowFile> flowFiles)
ProcessSession
transfer
in interface ProcessSession
flowFiles
- to transferpublic void transfer(java.util.Collection<FlowFile> flowFiles, Relationship relationship)
ProcessSession
transfer
in interface ProcessSession
flowFiles
- to transferrelationship
- to transfer topublic void remove(FlowFile flowFile)
ProcessSession
remove
in interface ProcessSession
flowFile
- to removepublic void remove(java.util.Collection<FlowFile> flowFiles)
ProcessSession
remove
in interface ProcessSession
flowFiles
- to removepublic void expireFlowFiles()
public void read(FlowFile source, InputStreamCallback reader)
ProcessSession
read
in interface ProcessSession
source
- flowfile to retrieve content ofreader
- that will be called to read the flowfile contentpublic void read(FlowFile source, boolean allowSessionStreamManagement, InputStreamCallback reader)
ProcessSession
read
in interface ProcessSession
source
- flowfile to retrieve content ofallowSessionStreamManagement
- allow session to hold the stream open for performance reasonsreader
- that will be called to read the flowfile contentpublic java.io.InputStream read(FlowFile source)
ProcessSession
ProcessSession.commit()
or ProcessSession.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.read
in interface ProcessSession
source
- the FlowFile to readpublic FlowFile merge(java.util.Collection<FlowFile> sources, FlowFile destination)
ProcessSession
merge
in interface ProcessSession
sources
- the flowfiles to mergedestination
- the flowfile to use as the merged resultpublic FlowFile merge(java.util.Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator)
ProcessSession
merge
in interface ProcessSession
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.public java.io.OutputStream write(FlowFile source)
ProcessSession
write
in interface ProcessSession
source
- to write topublic FlowFile write(FlowFile source, OutputStreamCallback writer)
ProcessSession
write
in interface ProcessSession
source
- to write towriter
- used to write new contentpublic FlowFile append(FlowFile source, OutputStreamCallback writer)
ProcessSession
append
in interface ProcessSession
source
- the flowfile for which content should be appendedwriter
- used to write new bytes to the flowfile contentpublic FlowFile write(FlowFile source, StreamCallback writer)
ProcessSession
write
in interface ProcessSession
source
- to read from and write towriter
- used to read the old content and write new contentpublic FlowFile importFrom(java.nio.file.Path source, boolean keepSourceFile, FlowFile destination)
ProcessSession
importFrom
in interface ProcessSession
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 updatedpublic FlowFile importFrom(java.io.InputStream source, FlowFile destination)
ProcessSession
importFrom
in interface ProcessSession
source
- the file from which content will be obtaineddestination
- the FlowFile whose content will be updatedpublic void exportTo(FlowFile source, java.nio.file.Path destination, boolean append)
ProcessSession
exportTo
in interface ProcessSession
source
- 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 contentpublic void exportTo(FlowFile source, java.io.OutputStream destination)
ProcessSession
exportTo
in interface ProcessSession
source
- to export the content ofdestination
- to export the content topublic FlowFile create(FlowFile parent)
ProcessSession
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.create
in interface ProcessSession
parent
- to base the new flowfile onpublic FlowFile create(java.util.Collection<FlowFile> parents)
ProcessSession
create
in interface ProcessSession
parents
- which the new flowfile should inherit shared attributes fromprotected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public ProvenanceReporter getProvenanceReporter()
ProcessSession
getProvenanceReporter
in interface ProcessSession
public java.lang.String toString()
toString
in class java.lang.Object