public class TopologyContext extends WorkerTopologyContext implements IMetricsContext
A TopologyContext
is given to bolts and spouts in their prepare()
and open()
methods, respectively. This object provides information about the component’s place within the topology, such as task ids, inputs and outputs, etc.
The TopologyContext
is also used to declare ISubscribedState
objects to synchronize state with StateSpouts this object is subscribed to.
SHARED_EXECUTOR
doSanityCheck, topoConf
Constructor and Description |
---|
TopologyContext(StormTopology topology,
Map<String,Object> topoConf,
Map<Integer,String> taskToComponent,
Map<String,List<Integer>> componentToSortedTasks,
Map<String,Map<String,Fields>> componentToStreamToFields,
Map<String,Long> blobToLastKnownVersionShared,
String stormId,
String codeDir,
String pidDir,
Integer taskId,
Integer workerPort,
List<Integer> workerTasks,
Map<String,Object> defaultResources,
Map<String,Object> userResources,
Map<String,Object> executorData,
Map<Integer,Map<Integer,Map<String,IMetric>>> registeredMetrics,
AtomicBoolean openOrPrepareWasCalled,
StormMetricRegistry metricRegistry) |
Modifier and Type | Method and Description |
---|---|
void |
addTaskHook(ITaskHook hook) |
Map<String,Long> |
getBlobToLastKnownVersion() |
Object |
getExecutorData(String name) |
List<ITaskHook> |
getHooks() |
IMetric |
getRegisteredMetricByName(String name)
Deprecated.
|
Object |
getTaskData(String name) |
String |
getThisComponentId()
Get component id.
|
Map<String,Map<String,List<String>>> |
getThisInputFields()
Gets the declared input fields for this component.
|
Fields |
getThisOutputFields(String streamId)
Gets the declared output fields for the specified stream id for the component this task is a part of.
|
Map<String,List<String>> |
getThisOutputFieldsForStreams()
Gets the declared output fields for all streams for the component this task is a part of.
|
Map<GlobalStreamId,Grouping> |
getThisSources()
Gets the declared inputs to this component.
|
Set<String> |
getThisStreams()
Gets the set of streams declared for the component of this task.
|
Map<String,Map<String,Grouping>> |
getThisTargets()
Gets information about who is consuming the outputs of this component, and how.
|
int |
getThisTaskId()
Gets the task id of this task.
|
int |
getThisTaskIndex()
Gets the index of this task id in getComponentTasks(getThisComponentId()).
|
com.codahale.metrics.Counter |
registerCounter(String name) |
<T> com.codahale.metrics.Gauge<T> |
registerGauge(String name,
com.codahale.metrics.Gauge<T> gauge) |
com.codahale.metrics.Histogram |
registerHistogram(String name) |
com.codahale.metrics.Meter |
registerMeter(String name) |
CombinedMetric |
registerMetric(String name,
ICombiner combiner,
int timeBucketSizeInSecs)
Deprecated.
|
ReducedMetric |
registerMetric(String name,
IReducer reducer,
int timeBucketSizeInSecs)
Deprecated.
|
<T extends IMetric> |
registerMetric(String name,
T metric,
int timeBucketSizeInSecs)
Deprecated.
|
void |
registerMetricSet(String prefix,
com.codahale.metrics.MetricSet set) |
com.codahale.metrics.Timer |
registerTimer(String name) |
<T extends ISubscribedState> |
setAllSubscribedState(T obj)
All state from all subscribed state spouts streams will be synced with the provided object.
|
void |
setExecutorData(String name,
Object data) |
<T extends ISubscribedState> |
setSubscribedState(String componentId,
String streamId,
T obj)
Synchronizes the specified stream from the specified state spout component id with the provided ISubscribedState object.
|
<T extends ISubscribedState> |
setSubscribedState(String componentId,
T obj)
Synchronizes the default stream from the specified state spout component id with the provided ISubscribedState object.
|
void |
setTaskData(String name,
Object data) |
String |
toJSONString() |
getCodeDir, getPIDDir, getResource, getSharedExecutor, getTaskToNodePort, getThisWorkerHost, getThisWorkerPort, getThisWorkerTasks
doSanityCheck, getComponentCommon, getComponentId, getComponentIds, getComponentOutputFields, getComponentOutputFields, getComponentStreams, getComponentTasks, getConf, getRawTopology, getSources, getStormId, getTargets, getTaskToComponent, maxTopologyMessageTimeout
public TopologyContext(StormTopology topology, Map<String,Object> topoConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, Map<String,Long> blobToLastKnownVersionShared, String stormId, String codeDir, String pidDir, Integer taskId, Integer workerPort, List<Integer> workerTasks, Map<String,Object> defaultResources, Map<String,Object> userResources, Map<String,Object> executorData, Map<Integer,Map<Integer,Map<String,IMetric>>> registeredMetrics, AtomicBoolean openOrPrepareWasCalled, StormMetricRegistry metricRegistry)
public <T extends ISubscribedState> T setAllSubscribedState(T obj)
All state from all subscribed state spouts streams will be synced with the provided object.
It is recommended that your ISubscribedState object is kept as an instance variable of this object. The recommended usage of this method is as follows:
java _myState = context.setAllSubscribedState(new MyState());
obj
- Provided ISubscribedState implementationpublic <T extends ISubscribedState> T setSubscribedState(String componentId, T obj)
Synchronizes the default stream from the specified state spout component id with the provided ISubscribedState object.
The recommended usage of this method is as follows:
java _myState = context.setSubscribedState(componentId, new MyState());
componentId
- the id of the StateSpout component to subscribe toobj
- Provided ISubscribedState implementationpublic <T extends ISubscribedState> T setSubscribedState(String componentId, String streamId, T obj)
Synchronizes the specified stream from the specified state spout component id with the provided ISubscribedState object.
The recommended usage of this method is as follows:
java _myState = context.setSubscribedState(componentId, streamId, new MyState());
componentId
- the id of the StateSpout component to subscribe tostreamId
- the stream to subscribe toobj
- Provided ISubscribedState implementationpublic int getThisTaskId()
Gets the task id of this task.
public String getThisComponentId()
Get component id.
public Fields getThisOutputFields(String streamId)
Gets the declared output fields for the specified stream id for the component this task is a part of.
public Map<String,List<String>> getThisOutputFieldsForStreams()
Gets the declared output fields for all streams for the component this task is a part of.
public Set<String> getThisStreams()
Gets the set of streams declared for the component of this task.
public int getThisTaskIndex()
Gets the index of this task id in getComponentTasks(getThisComponentId()). An example use case for this method is determining which task accesses which resource in a distributed resource to ensure an even distribution.
public Map<String,Map<String,List<String>>> getThisInputFields()
Gets the declared input fields for this component.
public Map<GlobalStreamId,Grouping> getThisSources()
Gets the declared inputs to this component.
public Map<String,Map<String,Grouping>> getThisTargets()
Gets information about who is consuming the outputs of this component, and how.
public void addTaskHook(ITaskHook hook)
public String toJSONString()
toJSONString
in interface org.apache.storm.shade.org.json.simple.JSONAware
toJSONString
in class GeneralTopologyContext
@Deprecated public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs)
IMetricsContext
Register metric.
registerMetric
in interface IMetricsContext
@Deprecated public ReducedMetric registerMetric(String name, IReducer reducer, int timeBucketSizeInSecs)
IMetricsContext
Register metric.
registerMetric
in interface IMetricsContext
@Deprecated public CombinedMetric registerMetric(String name, ICombiner combiner, int timeBucketSizeInSecs)
IMetricsContext
Register metric.
registerMetric
in interface IMetricsContext
@Deprecated public IMetric getRegisteredMetricByName(String name)
Get component’s metric from registered metrics by name. Notice: Normally, one component can only register one metric name once. But now registerMetric has a bug(https://issues.apache.org/jira/browse/STORM-254) cause the same metric name can register twice. So we just return the first metric we meet.
public com.codahale.metrics.Timer registerTimer(String name)
registerTimer
in interface IMetricsContext
public com.codahale.metrics.Histogram registerHistogram(String name)
registerHistogram
in interface IMetricsContext
public com.codahale.metrics.Meter registerMeter(String name)
registerMeter
in interface IMetricsContext
public com.codahale.metrics.Counter registerCounter(String name)
registerCounter
in interface IMetricsContext
public <T> com.codahale.metrics.Gauge<T> registerGauge(String name, com.codahale.metrics.Gauge<T> gauge)
registerGauge
in interface IMetricsContext
public void registerMetricSet(String prefix, com.codahale.metrics.MetricSet set)
registerMetricSet
in interface IMetricsContext
Copyright © 2022 The Apache Software Foundation. All rights reserved.