Class 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.

    • 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.
      • setTaskData

        public void setTaskData​(String name,
                                Object data)
      • addTaskHook

        public void addTaskHook​(ITaskHook newHook)