An Invocable
can execute any arbitrary action and can use any cluster-side services (cache services, grid services, and so on) necessary to perform their work. The Invocable operations can also be stateful, which means that their state is serialized and transmitted to the grid nodes on which the Invocable is run.
Coherence for C++ provides a Remote Invocation Service which allows the execution of Invocables
within the cluster-side JVM to which the client is connected. In Java, Invocables are simply runnable application classes that implement the com.tangosol.net.Invocable
interface. To employ an Invocable
in Coherence for C++, you must deploy a compiled Java implementation of the Invocable
task on the cluster-side node, in addition to providing a C++ implementation of Invocable
: coherence::net::Invocable
. Since execution is server-side (that is, Java), the C++ invocable only must be concerned with state; the methods themselves can be no-ops.
A Remote Invocation Service is configured using the remote-invocation-scheme
element in the cache configuration descriptor. Example 11-1 illustrates a sample remote invocation scheme configuration.
Example 11-1 Sample Remote Invocation Scheme Configuration
<remote-invocation-scheme> <scheme-name>example-invocation</scheme-name> <service-name>ExtendTcpInvocationService</service-name> <initiator-config> <tcp-initiator> <remote-addresses> <socket-address> <address>localhost</address> <port>9099</port> </socket-address> </remote-addresses> </tcp-initiator> <outgoing-message-handler> <request-timeout>30s</request-timeout> </outgoing-message-handler> </initiator-config> </remote-invocation-scheme>
A reference to a configured Remote Invocation Service can then be obtained by name by using the coherence::net::CacheFactory
class:
Example 11-2 Reference to a Remote Invocation Service
InvocationService::Handle hService = hService::getService("ExtendTcpInvocationService");
To execute an agent on the grid node to which the client is connected requires only one line of code:
Map::View hResult = hService->query(myTask::create(), NULL);
The Map
returned from query is keyed by the member on which the query is run. For Extend clients, there is no concept of membership, so the result is keyed by the local member which can be retrieved by calling CacheFactory::getConfigurableCacheFactory()::GetLocalMember()
Like cached value objects, all Invocable
implementation classes must be correctly registered in the POF context of the C++ application (see the PortableObject
description in "Building Integration Objects for C++ Clients") and cluster-side node to which the client is connected. As such, a Java implementation of the Invocable
task (a com.tangosol.net.Invocable
implementation) must be created, compiled, and deployed on the cluster-side node.
See "POF Registration" for additional details.