public class TopologyContext extends WorkerTopologyContext implements IMetricsContext
The TopologyContext is also used to declare ISubscribedState objects to synchronize state with StateSpouts this object is subscribed to.
SHARED_EXECUTOR
_stormConf
Constructor and Description |
---|
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 registeredMetrics,
clojure.lang.Atom openOrPrepareWasCalled) |
Modifier and Type | Method and Description |
---|---|
void |
addTaskHook(ITaskHook hook) |
Object |
getExecutorData(String name) |
Collection<ITaskHook> |
getHooks() |
IMetric |
getRegisteredMetricByName(String name)
Get component's metric from registered metrics by name.
|
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.
|
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()).
|
CombinedMetric |
registerMetric(String name,
ICombiner combiner,
int timeBucketSizeInSecs) |
ReducedMetric |
registerMetric(String name,
IReducer reducer,
int timeBucketSizeInSecs) |
<T extends IMetric> |
registerMetric(String name,
T metric,
int timeBucketSizeInSecs) |
<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, getThisWorkerPort, getThisWorkerTasks
getComponentCommon, getComponentId, getComponentIds, getComponentOutputFields, getComponentOutputFields, getComponentStreams, getComponentTasks, getRawTopology, getSources, getStormId, getTargets, getTaskToComponent, maxTopologyMessageTimeout
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 registeredMetrics, clojure.lang.Atom openOrPrepareWasCalled)
public <T extends ISubscribedState> T setAllSubscribedState(T obj)
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:
_myState = context.setAllSubscribedState(new MyState());
obj
- Provided ISubscribedState implementationpublic <T extends ISubscribedState> T setSubscribedState(String componentId, T obj)
The recommended usage of this method is as follows:
_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)
The recommended usage of this method is as follows:
_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()
public String getThisComponentId()
public Fields getThisOutputFields(String streamId)
public Set<String> getThisStreams()
public int getThisTaskIndex()
public Map<GlobalStreamId,Grouping> getThisSources()
public Map<String,Map<String,Grouping>> getThisTargets()
public void addTaskHook(ITaskHook hook)
public Collection<ITaskHook> getHooks()
public String toJSONString()
toJSONString
in interface org.json.simple.JSONAware
toJSONString
in class GeneralTopologyContext
public <T extends IMetric> T registerMetric(String name, T metric, int timeBucketSizeInSecs)
registerMetric
in interface IMetricsContext
public IMetric getRegisteredMetricByName(String name)
public ReducedMetric registerMetric(String name, IReducer reducer, int timeBucketSizeInSecs)
registerMetric
in interface IMetricsContext
public CombinedMetric registerMetric(String name, ICombiner combiner, int timeBucketSizeInSecs)
registerMetric
in interface IMetricsContext
Copyright © 2016 The Apache Software Foundation. All Rights Reserved.