Implicit Request Contexts
2 min read
2 min read
2 min read
2 min read
2 min read
2 min read
2 min read
2 min read
Using Implicit Request Contexts
In addition to explicit and per-proxy request contexts, you can also establish an implicit context on a communicator. This implicit context is sent with all invocations made via proxies created by that communicator, provided that you do not supply an explicit context with the call.
Scope of the Implicit Context
You establish the implicit context on a communicator by setting a property, Ice.ImplicitContext. This property controls whether a communicator has an implicit context and, if so, at what scope the context applies. The property can be set to the following values:
NoneWith this setting (or ifIce.ImplicitContextis not set at all), the communicator has no implicit context, andgetImplicitContexton the communicator returns null.SharedThe communicator has a single implicit context that is shared by all threads. Access to the context via itsImplicitContextclass is interlocked, so different threads can concurrently manipulate the context without risking data corruption or reading stale values.
PerThreadThe communicator maintains a separate implicit context for each thread. This allows you to propagate contexts that depend on the sending thread (for example, to send per-thread transaction IDs).
Using the Implicit Context
getImplicitContext on the communicator returns its implicit context, an object with methods to read and update the context's entries. When Ice.ImplicitContext is PerThread, each thread has its own implicit context: call getImplicitContext and update the context on the thread that makes the invocations.
Ice::ImplicitContextPtr implicitContext = communicator->getImplicitContext();implicitContext->put("language", "fr");
// This invocation sends the "language" entry of the implicit context.string greeting = greeter->greet(name);Ice.ImplicitContext implicitContext = communicator.getImplicitContext();implicitContext.put("language", "fr");
// This invocation sends the "language" entry of the implicit context.string greeting = await greeter.GreetAsync(name);ImplicitContext implicitContext = communicator.getImplicitContext();implicitContext.put("language", "fr");
// This invocation sends the "language" entry of the implicit context.String greeting = greeter.greet(name);const implicitContext = communicator.getImplicitContext();implicitContext.put("language", "fr");
// This invocation sends the "language" entry of the implicit context.const greeting = await greeter.greet(name);implicitContext = communicator.getImplicitContext();implicitContext.put('language', 'fr');
% This invocation sends the 'language' entry of the implicit context.greeting = greeter.greet(name);implicitContext = communicator.getImplicitContext()implicitContext.put("language", "fr")
# This invocation sends the "language" entry of the implicit context.greeting = await greeter.greetAsync(name)implicitContext = communicator.getImplicitContext()implicitContext.put("language", "fr")
# This invocation sends the "language" entry of the implicit context.greeting = greeter.greet(name)let implicitContext = communicator.getImplicitContext()!implicitContext.put(key: "language", value: "fr")
// This invocation sends the "language" entry of the implicit context.let greeting = try await greeter.greet(name)