Per-Proxy Request Contexts

2 min read

2 min read

2 min read

Each proxy stores a request context, empty by default. Ice sends this per-proxy context with each invocation made through the proxy, unless the invocation has an explicit context.

ice_context returns a new proxy that stores the given context, and ice_getContext returns the proxy's context:

C++
auto greeterEs = greeter->ice_context({{"language", "es"}});
C#
var greeterEs = GreeterPrxHelper.uncheckedCast(
greeter.ice_context(new Dictionary<string, string> { ["language"] = "es" }));
Java
var greeterEs = greeter.ice_context(Map.of("language", "es"));
JavaScript
const greeterEs = greeter.ice_context(new Map([["language", "es"]]));
MATLAB
context = configureDictionary('string', 'string');
context('language') = 'es';
greeterEs = greeter.ice_context(context);
PHP
$context = ["language" => "es"];
$greeterEs = $greeter->ice_context($context);
Python
greeterEs = greeter.ice_context({"language": "es"})
Ruby
greeterEs = greeter.ice_context({"language"=>"es"})
Swift
let greeterEs = greeter.ice_context(["language": "es"])

The per-proxy context is a local setting of the proxy: a stringified proxy cannot carry one, and Ice does not marshal it when it sends the proxy to another application.

When you create a proxy with propertyToProxy, the Context properties of the proxy property set its per-proxy context:

Properties
Greeter.Proxy=greeter:tcp -h localhost -p 4061
Greeter.Proxy.Context.language=es

Each name.Context.key=value property adds the entry key with the value value. To change this context, call ice_context with an updated copy of the dictionary that ice_getContext returns.