folly::RequestContext

Per-request context associated with an enqueued item.

Synopsis

Declared in <folly/io/async/Request.h>

class RequestContext;

Types

NameDescription
RootIdInfo Describes the root id associated with a thread.
State Internal state of a RequestContext.
StaticContext Thread-local holder of the current request context.
StaticContextAccessor Accessor that iterates the StaticContext of every thread.

Type Aliases

NameDescription
SetContextWatcherSig Signature for watcher callbacks invoked after a setContext.

Enums

NameDescription
DoSetBehaviour Selects the behavior of doSetContextDataHelper.

Member Functions

NameDescription
RequestContext [constructor]Constructors
operator= Assignment operators
clearContextData clearContextData overloads
doSetContextDataHelper doSetContextDataHelper overloads
getContextData getContextData overloads
getRootId Returns the root id of this context.
getThreadCachedContextData Returns cached context data for the token, keyed by a type tag.
hasContextData hasContextData overloads
onSet Invokes the onSet() callbacks of all held RequestData instances.
onUnset Invokes the onUnset() callbacks of all held RequestData instances.
overwriteContextData overwriteContextData overloads
setContextData setContextData overloads
setContextDataIfAbsent setContextDataIfAbsent overloads

Static Member Functions

NameDescription
accessAllThreads Returns an accessor that pins the StaticContext of all threads.
addSetContextWatcher Registers a watcher invoked on every context change.
copyAsChild Copies a context as a child of the given one.
copyAsRoot Copies a context as a new root context.
create Creates a unique request context and sets it as the current context.
get Returns the current context, or the default global request context.
getRootIdsFromAllThreads Collects the root id information from all threads.
saveContext Returns a shared pointer to the current context.
setContext Sets the given context as current and returns the previous one.
setShallowCopyContext Sets a shallow copy of the current context as current.
try_get Returns the current context, if it has already been set, or nullptr.

Data Members

NameDescription
rootId_ The root id; shallow copies keep a note of the root context.
state_ The internal state of this context.

Friends

NameDescription
folly::ShallowCopyRequestContextScopeGuardThis guard maintains all the RequestData pointers of the parent. This allows to overwrite a specific RequestData pointer for the scope's duration, without breaking others.