Package org.apache.storm.task
Class TopologyContext
- java.lang.Object
-
- org.apache.storm.task.GeneralTopologyContext
-
- org.apache.storm.task.WorkerTopologyContext
-
- org.apache.storm.task.TopologyContext
-
- All Implemented Interfaces:
IMetricsContext
,org.json.simple.JSONAware
- Direct Known Subclasses:
BoltTopologyContext
,SpoutTopologyContext
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.
-
-
Constructor Summary
Constructors Constructor Description TopologyContext(org.apache.heron.api.topology.TopologyContext delegate)
TopologyContext(StormTopology topology, Map stormConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, 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<String,Object> registeredMetrics, Atom openOrPrepareWasCalled)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTaskHook(ITaskHook newHook)
Collection<ITaskHook>
getHooks()
Object
getTaskData(String name)
String
getThisComponentId()
Gets the component id for this task.Fields
getThisOutputFields(String streamId)
Gets the declared output fields for the specified stream id for the component this task is a part of.Set<String>
getThisStreams()
Gets the set of streams declared for the component of this task.int
getThisTaskId()
Gets the task id of this task.int
getThisTaskIndex()
Gets the index of this task id in getComponentTasks(getThisComponentId()).CombinedMetric
registerMetric(String name, ICombiner combiner, int timeBucketSizeInSecs)
ReducedMetric
registerMetric(String name, IReducer reducer, int timeBucketSizeInSecs)
<T extends IMetric>
TregisterMetric(String name, T metric, int timeBucketSizeInSecs)
void
setTaskData(String name, Object data)
-
Methods inherited from class org.apache.storm.task.WorkerTopologyContext
getCodeDir, getPIDDir, getResource, getSharedExecutor, getThisWorkerPort, getThisWorkerTasks
-
Methods inherited from class org.apache.storm.task.GeneralTopologyContext
getComponentId, getComponentIds, getComponentOutputFields, getComponentStreams, getComponentTasks, getRawTopology, getStormId, getTaskToComponent, toJSONString
-
-
-
-
Constructor Detail
-
TopologyContext
public TopologyContext(StormTopology topology, Map stormConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, 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<String,Object> registeredMetrics, Atom openOrPrepareWasCalled)
-
TopologyContext
public TopologyContext(org.apache.heron.api.topology.TopologyContext delegate)
-
-
Method Detail
-
getThisTaskId
public int getThisTaskId()
Gets the task id of this task.- Returns:
- the task id
-
getThisComponentId
public String getThisComponentId()
Gets the component id for this task. The component id maps to a component id specified for a Spout or Bolt in the topology definition.
-
getThisOutputFields
public Fields getThisOutputFields(String streamId)
Gets the declared output fields for the specified stream id for the component this task is a part of.
-
getThisStreams
public Set<String> getThisStreams()
Gets the set of streams declared for the component of this task.
-
getThisTaskIndex
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.
-
addTaskHook
public void addTaskHook(ITaskHook newHook)
-
getHooks
public Collection<ITaskHook> getHooks()
-
registerMetric
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs)
- Specified by:
registerMetric
in interfaceIMetricsContext
-
registerMetric
public ReducedMetric registerMetric(String name, IReducer reducer, int timeBucketSizeInSecs)
- Specified by:
registerMetric
in interfaceIMetricsContext
-
registerMetric
public CombinedMetric registerMetric(String name, ICombiner combiner, int timeBucketSizeInSecs)
- Specified by:
registerMetric
in interfaceIMetricsContext
-
-