ThreadLocalContext (Apache Hadoop HDFS-RBF 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.server.federation.router, class: ThreadLocalContext

Package org.apache.hadoop.hdfs.server.federation.router

# Class ThreadLocalContext

java.lang.Object
org.apache.hadoop.hdfs.server.federation.router.ThreadLocalContext

public class ThreadLocalContext extends Object
The ThreadLocalContext class is designed to capture and transfer the context of a thread-local environment within the Hadoop Distributed File System (HDFS) federation router operations. This is particularly useful for preserving the state across asynchronous operations where the context needs to be maintained consistently. The context includes details such as the current call being processed by the server, the caller's context, and performance monitoring timestamps. By transferring this context, the class ensures that the operations performed on worker threads correctly reflect the state of the original calling thread. Here is a high-level overview of the main components captured by this context:

- `Server.Call` - Represents the current server call.
- `CallerContext` - Stores information about the caller.
- startOpTime - Time for an operation to be received in the Router.
- proxyOpTime - Time for an operation to be sent to the Namenode.

This class is typically used in scenarios where asynchronous processing is involved, to ensure that the thread executing the asynchronous task has the correct context applied.

See Also:
  - `Server`
  - `CallerContext`
  - `FederationRPCPerformanceMonitor`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ThreadLocalContext()`
  Constructs a new `ThreadLocalContext` instance, capturing the current thread-local context at the point of creation.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `toString()`
  `void`
  `transfer()`
  Transfers the captured context to the current thread.

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

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

- ## Constructor Details

  - ### ThreadLocalContext

    public ThreadLocalContext()
    Constructs a new `ThreadLocalContext` instance, capturing the current thread-local context at the point of creation.

- ## Method Details

  - ### transfer

    public void transfer()
    Transfers the captured context to the current thread. This method is used to apply the context to worker threads that are processing asynchronous tasks, ensuring that the task execution reflects the state of the original calling thread.

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`