Package org.apache.storm.task

# Class WorkerTopologyContext

java.lang.Object
org.apache.storm.task.GeneralTopologyContext
org.apache.storm.task.WorkerTopologyContext

All Implemented Interfaces:
  `org.apache.storm.shade.net.minidev.json.JSONAware`

Direct Known Subclasses:
  `TopologyContext`, `WorkerUserContext`

public class WorkerTopologyContext extends GeneralTopologyContext

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final String`
  `SHARED_EXECUTOR`

  ### Fields inherited from class org.apache.storm.task.GeneralTopologyContext

  `doSanityCheck, topoConf`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `WorkerTopologyContext(StormTopology topology, Map<String,Object> topoConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, String stormId, String codeDir, String pidDir, Integer workerPort, List<Integer> workerTasks, Map<String,Object> defaultResources, Map<String,Object> userResources)`
  `WorkerTopologyContext(StormTopology topology, Map<String,Object> topoConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, String stormId, String codeDir, String pidDir, Integer workerPort, List<Integer> workerTasks, Map<String,Object> defaultResources, Map<String,Object> userResources, AtomicReference<Map<Integer,NodeInfo>> taskToNodePort, String assignmentId, AtomicReference<Map<String,String>> nodeToHost)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getAssignmentId()`
  `String`
  `getCodeDir()`
  Gets the location of the external resources for this worker on the local filesystem.
  `AtomicReference<Map<String,String>>`
  `getNodeToHost()`
  Get a map from nodeId to hostname.
  `String`
  `getPIDDir()`
  If this task spawns any subprocesses, those subprocesses must immediately write their PID to this directory on the local filesystem to ensure that Storm properly destroys that process when the worker is shutdown.
  `Object`
  `getResource(String name)`
  Fetches the worker-level data for the given name.
  `ExecutorService`
  `getSharedExecutor()`
  `AtomicReference<Map<Integer,NodeInfo>>`
  `getTaskToNodePort()`
  Get a map from task Id to NodePort.
  `Integer`
  `getThisWorkerPort()`
  `List<Integer>`
  `getThisWorkerTasks()`
  Gets all the task ids that are running in this worker process (including the task for this task).

  ### Methods inherited from class org.apache.storm.task.GeneralTopologyContext

  `doSanityCheck, getComponentCommon, getComponentId, getComponentIds, getComponentOutputFields, getComponentOutputFields, getComponentStreams, getComponentTasks, getConf, getRawTopology, getSources, getStormId, getTargets, getTaskToComponent, maxTopologyMessageTimeout, toJSONString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### SHARED_EXECUTOR

    public static final String SHARED_EXECUTOR
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### WorkerTopologyContext

    public WorkerTopologyContext(StormTopology topology, Map<String,Object> topoConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, String stormId, String codeDir, String pidDir, Integer workerPort, List<Integer> workerTasks, Map<String,Object> defaultResources, Map<String,Object> userResources, AtomicReference<Map<Integer,NodeInfo>> taskToNodePort, String assignmentId, AtomicReference<Map<String,String>> nodeToHost)

  - ### WorkerTopologyContext

    public WorkerTopologyContext(StormTopology topology, Map<String,Object> topoConf, Map<Integer,String> taskToComponent, Map<String,List<Integer>> componentToSortedTasks, Map<String,Map<String,Fields>> componentToStreamToFields, String stormId, String codeDir, String pidDir, Integer workerPort, List<Integer> workerTasks, Map<String,Object> defaultResources, Map<String,Object> userResources)

- ## Method Details

  - ### getThisWorkerTasks

    public List<Integer> getThisWorkerTasks()
    Gets all the task ids that are running in this worker process (including the task for this task).

  - ### getThisWorkerPort

    public Integer getThisWorkerPort()

  - ### getAssignmentId

    public String getAssignmentId()

  - ### getTaskToNodePort

    public AtomicReference<Map<Integer,NodeInfo>> getTaskToNodePort()
    Get a map from task Id to NodePort.
    Returns:
      a map from task To NodePort

  - ### getNodeToHost

    public AtomicReference<Map<String,String>> getNodeToHost()
    Get a map from nodeId to hostname.
    Returns:
      a map from nodeId to hostname

  - ### getCodeDir

    public String getCodeDir()
    Gets the location of the external resources for this worker on the local filesystem. These external resources typically include bolts implemented in other languages, such as Ruby or Python.

  - ### getPIDDir

    public String getPIDDir()
    If this task spawns any subprocesses, those subprocesses must immediately write their PID to this directory on the local filesystem to ensure that Storm properly destroys that process when the worker is shutdown.

  - ### getResource

    public Object getResource(String name)
    Fetches the worker-level data for the given name. The corresponding data needs to be first set in an implementation of `IWorkerHook.start(Map, WorkerUserContext)` via `WorkerUserContext.setResource(String, Object)`
    Parameters:
      `name` - name of the worker-level data to be fetched
    Returns:
      Associated worker-level data

  - ### getSharedExecutor

    public ExecutorService getSharedExecutor()