Creating Proxies
6 min read
6 min read
6 min read
5 min read
5 min read
4 min read
6 min read
4 min read
6 min read
This page describes all the ways an application can create a proxy.
Creating a Proxy from a String
The generated proxy class provides a constructor that constructs a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
GreeterPrx greeter{communicator, "greeter:tcp -h localhost -p 4061"};The generated helper class for a proxy provides a static factory method createProxy that creates a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
GreeterPrx greeter = GreeterPrxHelper.createProxy( communicator, "greeter:tcp -h localhost -p 4061");The generated proxy class provides a static factory method createProxy from a communicator and a stringified representation of the proxy, as shown in the following example:
GreeterPrx greeter = GreeterPrx.createProxy( communicator, "greeter:tcp -h localhost -p 4061");The constructor of the generated proxy class allows you to construct a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
const greeter = new GreeterPrx( communicator, "greeter:tcp -h localhost -p 4061");The constructor of the generated proxy class allows you to construct a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
greeter = GreeterPrx(communicator, 'greeter:tcp -h localhost -p 4061');The generated helper class for a proxy provides a static factory method createProxy that creates a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
$greeter = GreeterPrxHelper::createProxy( $communicator, 'greeter:tcp -h localhost -p 4061');The constructor of the generated proxy class allows you to construct a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
greeter = GreeterPrx(communicator, "greeter:tcp -h localhost -p 4061")The constructor of the generated proxy class allows you to construct a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
greeter = GreeterPrx.new(communicator, "greeter:tcp -h localhost -p 4061")The Slice compiler generates a makeProxy function that allows you to construct a proxy from a communicator and a stringified representation of the proxy, as shown in the following example:
let greeter = try makeProxy( communicator: communicator, proxyString: "greeter:tcp -h localhost -p 4061", type: GreeterPrx.self)Creating a Proxy from a Property
Rather than hard-coding a stringified proxy as the previous example demonstrated, an application can gain more flexibility by externalizing the proxy in a configuration property. For example, we can define a property that contains our stringified proxy as follows:
Greeter.Proxy=greeter:tcp -h localhost -p 4061We can use the propertyToProxy template function on Communicator to convert the property's value into a proxy. A null proxy (std::nullopt) is returned if no property is found with the specified name.
std::optional<GreeterPrx> greeter = communicator->propertyToProxy<GreeterPrx>("Greeter.Proxy");We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
ObjectPrx? greeter = communicator.propertyToProxy("Greeter.Proxy");We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
ObjectPrx greeter = communicator.propertyToProxy("Greeter.Proxy");We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
const greeter = communicator.propertyToProxy("Greeter.Proxy");We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. An empty array (null proxy) is returned if no property is found with the specified name.
greeter = communicator.propertyToProxy('Greeter.Proxy');We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
$greeter = $communicator->propertyToProxy('Greeter.Proxy');We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
greeter = communicator.propertyToProxy("Greeter.Proxy")We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy is returned if no property is found with the specified name.
greeter = communicator.propertyToProxy("Greeter.Proxy")We can use the propertyToProxy method on Communicator to convert the property's value into a proxy. A null proxy (nil) is returned if no property is found with the specified name.
let greeter = try communicator.propertyToProxy("Greeter.Proxy")As an added convenience, propertyToProxy allows you to define subordinate properties that configure the proxy's local settings. The properties below demonstrate this feature:
Greeter.Proxy=greeter:tcp -h localhost -p 4061Greeter.Proxy.EndpointSelection=OrderedThese additional properties simplify the task of customizing a proxy (as you can with proxy methodsproxy methodsproxy methodsproxy methodsproxy methodsproxy methodsproxy methodsproxy methods) without the need to change the application's code. The properties shown above are equivalent to the following statements:
GreeterPrx greeter{communicator, "greeter:tcp -h localhost -p 4061"};greeter = greeter.ice_endpointSelection(EndpointSelectionType::Ordered);var greeter = GreeterPrxHelper.createProxy( communicator, "greeter:tcp -h localhost -p 4061");greeter = GreeterPrxHelper.uncheckedCast( greeter.ice_endpointSelection(EndpointSelectionType.Ordered));var greeter = GreeterPrx.createProxy( communicator, "greeter:tcp -h localhost -p 4061");greeter = greeter.ice_endpointSelection(EndpointSelectionType.Ordered);let greeter = new GreeterPrx( communicator, "greeter:tcp -h localhost -p 4061");greeter = greeter.ice_endpointSelection(Ice.EndpointSelectionType.Ordered);greeter = GreeterPrx(communicator, 'greeter:tcp -h localhost -p 4061');greeter = greeter.ice_endpointSelection(Ice.EndpointSelectionType.Ordered);$greeter = GreeterPrxHelper::createProxy( $communicator, 'greeter:tcp -h localhost -p 4061');$greeter = $greeter->ice_endpointSelection(Ice\EndpointSelectionType::Ordered);greeter = GreeterPrx(communicator, "greeter:tcp -h localhost -p 4061")greeter = greeter.ice_endpointSelection(Ice.EndpointSelectionType.Ordered)greeter = GreeterPrx.new(communicator, "greeter:tcp -h localhost -p 4061")greeter = greeter.ice_endpointSelection(Ice::EndpointSelectionType::Ordered)var greeter = try makeProxy( communicator: communicator, proxyString: "greeter:tcp -h localhost -p 4061", type: GreeterPrx.self)
greeter = greeter.ice_endpointSelection(.Ordered)The proxy properties cover the proxy settings that a stringified proxy cannot express, except the compression setting (ice_compress), the connection ID (ice_connectionId) and a fixed connection (ice_fixed). propertyToProxy throws PropertyException if it finds a subordinate property that is not one of these proxy properties.
Note that proxy properties can themselves have proxy properties. For example, the following sets the EndpointSelection property on the default locator's router:
Ice.Default.Locator.Router.EndpointSelection=OrderedCreating a Proxy from an Object Adapter
An object adapter can create a proxy for any identity, whether or not it hosts an Ice object with this identity.
createProxyreturns a proxy with the given identity. If the object adapter has an AdapterId, the proxy is an indirect proxy that refers to the object adapter'sReplicaGroupId, or to itsAdapterIdwhen no replica group ID is set. Otherwise, the proxy is a direct proxy that holds the object adapter's published endpoints.createDirectProxyreturns a direct proxy that holds the object adapter's published endpoints.createIndirectProxyreturns an indirect proxy that refers to the object adapter'sAdapterId, or a well-known proxy when the object adapter has no adapter ID.
createProxy and createDirectProxy both return a direct proxy that holds the object adapter's published endpoints.
add, addFacet, addWithUUID and addFacetWithUUID register a servant with the Active Servant Map and return the proxy that createProxy creates for the identity of this servant, with its facet.
All these proxies use the options set by the object adapter's ProxyOptions property, such as -o for oneway proxies.
Creating a Proxy from a Connection
createProxy on a connection returns a fixed proxy with the given identity: invocations on this proxy use only this connection. A server uses such a proxy to call back a client over a bidirectional connection.
Receiving a Proxy from an Operation
An application can also receive a proxy as the result of an Ice invocation. Consider the following Slice definitions:
interface Account { ... }interface Bank{ Account* findAccount(string id);}Invoking the findAccount operation returns a proxy for an Account object.
For example:
std::optional<AccountPrx> account = bank.findAccount("WXY-123456");AccountPrx? account = await bank.findAccountAsync("WXY-123456");AccountPrx account = bank.findAccount("WXY-123456");let account: AccountPrx | null = await bank.findAccount("WXY-123456");account = bank.findAccount('WXY-123456');$account = $bank->findAccount('WXY-123456');account = await bank.findAccountAsync("WXY-123456")account = bank.findAccount('WXY-123456')let account = try await bank.findAccount("WXY-123456")Proxy Factory Methods
A proxy is immutable. Its factory methods, such as ice_oneway, ice_facet and ice_invocationTimeout, return a proxy with the requested setting, and leave the original proxy unchanged. See ObjectPrx in the API reference for the complete list of factory methods and the accessors that return the current settings.
The language mapping for interfaces describes the type of the proxy that these factory methods return.
Creating a Proxy of Another Type
uncheckedCast and checkedCast create a proxy of the desired type from an existing proxy, for the same Ice object. Despite their names, these functions are not casts: they return a new proxy and leave the original proxy unchanged. uncheckedCast creates the new proxy without contacting the target object. checkedCast first calls ice_isA on the target object to verify that it implements the requested interface, and returns a null proxy if it does not.
You rarely need these functions. In new code, you create a typed proxy directly with one of the methods described above, and an application that converts a proxy of one type into a proxy of another type is uncommon.
The language mapping for interfaces shows these functions.
In C++, these functions are the Ice::uncheckedCast and Ice::checkedCast function templates, for example Ice::checkedCast<GreeterPrx>(proxy).