Skip Headers
Oracle® Coherence Client Guide
Release 3.7.1

Part Number E22839-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

13 Performing Remote Invocations (C++)

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 need only be concerned with state; the methods themselves can be no-operations.

The following sections are included in this chapter:

13.1 Configuring and Using the Remote Invocation Service

A Remote Invocation Service is configured using the remote-invocation-scheme element in the cache configuration descriptor. Example 13-1 illustrates a sample remote invocation scheme configuration.

Example 13-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 13-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()

13.2 Registering Invocable Implementation Classes

Like cached value objects, all Invocable implementation classes must be correctly registered in the POF context of the C++ application (see "PortableObject (Self-Serialization)") 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 "Registering Custom C++ Types" for additional details.