public class RuntimeContext extends Object implements IRuntimeContext
To execute a punchlet we must keep track of a few things:
- All the regexes (grok, named or plain), compiled of courses.
- Indicator for debugging/tracing or reporting errors
- The top level tuple given to the PunchPlatform program for transformation.
- Compiled Siddhi rules
An instance of this class is created when the PunchPlatform program is compiled, and used then at each invocation.
Modifier and Type | Field and Description |
---|---|
io.krakens.grok.api.Grok[] |
grokArray
The array of compiled grok/regexes expressions.
|
static String |
LOCAL_RESOURCES_DIRECTORY |
Constructor and Description |
---|
RuntimeContext() |
RuntimeContext(boolean isAsynchronous,
List<Map.Entry<String,Tuple>> resources,
List<Map.Entry<String,String>> siddhiRules,
Map<String,String> strings,
io.krakens.grok.api.Grok[] groks,
org.apache.commons.net.util.SubnetUtils[] subnets,
org.joda.time.format.DateTimeFormatter[] dateFormats,
org.logstash.dissect.Dissector[] dissectors,
String[] dateFormatStrings) |
RuntimeContext(io.krakens.grok.api.Grok[] groks,
org.apache.commons.net.util.SubnetUtils[] subnets,
org.joda.time.format.DateTimeFormatter[] dateFormats,
org.logstash.dissect.Dissector[] dissectors,
String[] dateFormatStrings)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
void |
addEvent(Tuple tuple)
Adds a new asynchronous event to the queue.
|
void |
addEventCallback(PunchletEventCallback callback)
Register a user callback to process asynchronous events.
|
void |
addRuntimeData(Object source,
int key,
Object o)
Add a new object as part of the runtime context of a punchlet.
|
CidrMatchOperator |
cidrmatch(int index)
Return a CidrMatch operator for the corresponding index.
|
CidrMatchOperator |
cidrmatch(Tuple cidr)
Return a CidrMatch operator for the corresponding index.
|
Object |
computeIfAbsent(String key,
Function<? super String,?> mappingFunction) |
DateOperator |
date() |
DateOperator |
date(int index) |
DateOperator |
date(int dstIndex,
int srcIndex) |
void |
debug() |
DissectOperator |
dissect(int index) |
void |
fireEvents(Punchlet punchlet)
Notify the caller from the firing of some events.
|
Object |
getAttachment(String key) |
Tuple |
getJsonResource(String name)
Return a the content of a Json resource file, loaded as an in memory tuple
|
int |
getLeadingLineNumber() |
org.thales.punch.libraries.metrics.api.IMetricContext |
getMetricsContext() |
Tuple |
getRootTuple() |
String |
getRule(String name)
Return a siddhi rule defined as part of resource attached to this punchlet
|
Object |
getRuntimeData(Object source,
int key)
Return a runtime object attached to a running punchlet.
|
String |
getStringResource(String name)
Return a the content of a string resource file content, loaded as an in memory tuple
|
GrokOperator |
grok(GrokArgs... args) |
boolean |
isAsynchronous() |
boolean |
isVerbose() |
void |
remove(Tuple tuple)
Remove a tuple.
|
void |
schedule(Runnable r) |
void |
setAttachment(String key,
Object value)
Set an attachment
|
void |
setLeadingLineNumber(int leadingLinesNumber) |
void |
setMetricContext(org.thales.punch.libraries.metrics.api.IMetricContext metricsContext) |
void |
setRootTuple(Tuple tuple)
Set the top level tuple.
|
void |
setVerbose(boolean verbose) |
DateOperator |
toDate()
Return a date format operator for implicit date format.
|
DateOperator |
toDate(int index)
Return a pre-compiled date format operator for a the corresponding index.
|
DateOperator |
toDate(int dstIndex,
int srcIndex)
Return a pre-compiled date format operator for a the corresponding source and destination index.
|
public static String LOCAL_RESOURCES_DIRECTORY
public final io.krakens.grok.api.Grok[] grokArray
public RuntimeContext()
public RuntimeContext(boolean isAsynchronous, List<Map.Entry<String,Tuple>> resources, List<Map.Entry<String,String>> siddhiRules, Map<String,String> strings, io.krakens.grok.api.Grok[] groks, org.apache.commons.net.util.SubnetUtils[] subnets, org.joda.time.format.DateTimeFormatter[] dateFormats, org.logstash.dissect.Dissector[] dissectors, String[] dateFormatStrings)
isAsynchronous
- true if the punchlet generates asynchronous eventsresources
- the resource tuples provided by configurationsiddhiRules
- the siddhi rulesstrings
- the static string (i.e. file content)groks
- the grok patternssubnets
- the subnet utils compiled from the punchletdateFormats
- the date formatter compiled from the punchletdissectors
- the compiled dissectorsdateFormatStrings
- the compiled date formatspublic RuntimeContext(io.krakens.grok.api.Grok[] groks, org.apache.commons.net.util.SubnetUtils[] subnets, org.joda.time.format.DateTimeFormatter[] dateFormats, org.logstash.dissect.Dissector[] dissectors, String[] dateFormatStrings)
groks
- the array of compiled regexes.subnets
- the compiled subnetutils.dateFormats
- the compiled date formattersdissectors
- the compiled dissectorsdateFormatStrings
- the compiled date format arraypublic void addRuntimeData(Object source, int key, Object o)
addRuntimeData
in interface IRuntimeContext
source
- source objectkey
- the object keyo
- the target objectpublic org.thales.punch.libraries.metrics.api.IMetricContext getMetricsContext()
public Tuple getJsonResource(String name)
name
- the name of the resource.public String getStringResource(String name)
name
- the name of the resource.public String getRule(String name)
name
- the name of the rulepublic DissectOperator dissect(int index)
public CidrMatchOperator cidrmatch(int index)
This is called directly by the punchlet at runtime. Return a CidrMatch operator ready to be used, already compiled. The index corresponds to a setup SubnetUtils object.
index
- the index of the compiled subnet utils.public CidrMatchOperator cidrmatch(Tuple cidr)
This is called directly by the punchlet at runtime. Return a CidrMatch operator ready to be used, already compiled. The index corresponds to a setup SubnetUtils object.
cidr
- the tuple where to find the input valuepublic DateOperator date()
public DateOperator date(int index)
public DateOperator date(int dstIndex, int srcIndex)
public void debug()
public Tuple getRootTuple()
public Object getRuntimeData(Object source, int key)
getRuntimeData
in interface IRuntimeContext
source
- the source object that requires an attachmentkey
- the name of the property that will be used for the querypublic GrokOperator grok(GrokArgs... args)
public boolean isVerbose()
public void remove(Tuple tuple)
tuple
- the tuple to removepublic void schedule(Runnable r)
public void setRootTuple(Tuple tuple)
tuple
- the tuple to use as root tuplepublic void setVerbose(boolean verbose)
public DateOperator toDate()
This is called directly by the punchlet at runtime.
public DateOperator toDate(int index)
This is called directly by the punchlet at runtime.
index
- the index of the compiled date formatpublic DateOperator toDate(int dstIndex, int srcIndex)
This is called directly by the punchlet at runtime.
dstIndex
- the index of the destination datesrcIndex
- the index of the target datepublic void addEventCallback(PunchletEventCallback callback)
callback
- the event callbackpublic void addEvent(Tuple tuple)
tuple
- the event as a tuplepublic void fireEvents(Punchlet punchlet)
punchlet
- the corresponding caller punchlet.public boolean isAsynchronous()
public Object getAttachment(String key)
key
- the attachment keypublic Object computeIfAbsent(String key, Function<? super String,?> mappingFunction)
key
- the attachment keymappingFunction
- the mapping function called if absentpublic void setAttachment(String key, Object value)
key
- the keyvalue
- the attached valuepublic void setMetricContext(org.thales.punch.libraries.metrics.api.IMetricContext metricsContext)
public void setLeadingLineNumber(int leadingLinesNumber)
public int getLeadingLineNumber()
Copyright © 2023. All rights reserved.