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

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.

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:

  • None With this setting (or if Ice.ImplicitContext is not set at all), the communicator has no implicit context, and getImplicitContext on the communicator returns null.

  • Shared The communicator has a single implicit context that is shared by all threads. Access to the context via its ImplicitContext class is interlocked, so different threads can concurrently manipulate the context without risking data corruption or reading stale values.

  • PerThread The 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).

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.

C++
Ice::ImplicitContextPtr implicitContext = communicator->getImplicitContext();
implicitContext->put("language", "fr");
// This invocation sends the "language" entry of the implicit context.
string greeting = greeter->greet(name);
C#
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);
Java
ImplicitContext implicitContext = communicator.getImplicitContext();
implicitContext.put("language", "fr");
// This invocation sends the "language" entry of the implicit context.
String greeting = greeter.greet(name);
JavaScript
const implicitContext = communicator.getImplicitContext();
implicitContext.put("language", "fr");
// This invocation sends the "language" entry of the implicit context.
const greeting = await greeter.greet(name);
MATLAB
implicitContext = communicator.getImplicitContext();
implicitContext.put('language', 'fr');
% This invocation sends the 'language' entry of the implicit context.
greeting = greeter.greet(name);
Python
implicitContext = communicator.getImplicitContext()
implicitContext.put("language", "fr")
# This invocation sends the "language" entry of the implicit context.
greeting = await greeter.greetAsync(name)
Ruby
implicitContext = communicator.getImplicitContext()
implicitContext.put("language", "fr")
# This invocation sends the "language" entry of the implicit context.
greeting = greeter.greet(name)
Swift
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)