2 Building Your First Extend Application
This chapter includes the following sections:
- Overview of the Extend Example
The Coherence*Extend example is organized into a set of steps that are used to create, configure, and run a basic Coherence*Extend client. - Step 1: Configure the Cluster Side
The example extend client requires a proxy and cache to be configured in the cluster's cache configuration deployment descriptor. - Step 2: Configure the Client Side
The example client queries a remote cache and also invokes a task which is run on a remote cluster node. - Step 3: Create the Sample Client
The client application for this example is a simple client that increments anInteger
value in a remote cache using theCacheService
and then retrieves the value from the cache using theInvocationService
. - Step 4: Start the Cache Server Process
Extend Proxies are started as part of a cache server process(DefaultCacheServer
). - Step 5: Run the Application
TheTestClient
application is started using thejava
command and must be configured to use the cache configuration file.
Parent topic: Getting Started
Overview of the Extend Example
Coherence for Java must be installed to complete the steps. For simplicity and ease of deployment, the client and cache server in this example are run on the same computer. Typically, extend clients and cache servers are located on separate systems.
Parent topic: Building Your First Extend Application
Step 1: Configure the Cluster Side
dist-extend
is defined and is used to store client data in the cluster.
To configure the cluster side:
Parent topic: Building Your First Extend Application
Step 2: Configure the Client Side
The remote cache scheme includes a service name that matches the service name of a proxy service on the cluster to which the client connects. In addition, the cache name that is used in the cluster must also be used as the name of the remote cache scheme. For this example (based on Step 1), the remote cache scheme service name is ExtendTcpCacheService
and the cache name is dist-extend
. Lastly, the remote cache scheme includes the address and port of the cluster's name service, which is used to find a proxy. The name service runs on the cluster port which is 7574 by default.
The example extend client invokes a task on the remote cache and therefore requires a remote invocation scheme. The remote invocation scheme defines the ExtendTcpInvocationService
service, which allows the client to create an Invocable
instance and send it to the cluster for processing. The remote invocation scheme uses the name service to find a proxy and includes the name of the proxy service to which it connects.
To configure the client side:
Parent topic: Building Your First Extend Application
Step 3: Create the Sample Client
Integer
value in a remote cache using the CacheService
and then retrieves the value from the cache using the InvocationService
. The client writes the value to the system output before exiting.
Note:
-
The client class must be on the classpath for all cache servers in the cluster. The
TestClient$1
class is an anonymous inner class that is generated during compilation. It is serialized and sent to theInvocationService
running on a cluster member. In this example, the client and cluster member run on a single computer. Therefore, both Java invocations use the same classpath. -
This example could also be run on a Coherence node (that is, within the cluster) as is. The fact that operations are being sent to a remote cluster node over TCP/IP is completely transparent to the client application.
To create the sample application:
Coherence*Extend InvocationService
Since, by definition, a Coherence*Extend client has no direct knowledge of the cluster and the members running within the cluster, the Coherence*Extend InvocationService
only allows Invocable
tasks to be executed on the JVM to which the client is connected. Therefore, you should always pass a null member set to the query()
method. As a consequence, the single result of the execution is keyed by the local Member
, which is null if the client is not part of the cluster. This Member
can be retrieved by calling service.getCluster().getLocalMember()
. Additionally, the Coherence*Extend InvocationService
only supports synchronous task execution (that is, the execute()
method is not supported).
Parent topic: Building Your First Extend Application
Step 4: Start the Cache Server Process
DefaultCacheServer
). The cache server must be configured to use the cache configuration that was created in Step 1. In addition, the cache server process must be able to find the TestClient
application on the classpath at run time.
The following command line starts a cache server process and explicitly names the cache configuration file created in Step 1 by using the coherence.cacheconfig
system property:
java -cp COHERENCE_HOME\lib\coherence.jar;PATH_TO_CLIENT -Dcoherence.cacheconfig=PATH\example-config.xml com.tangosol.net.DefaultCacheServer
Check the console output to verify that the proxy service is started. The output message is similar to the following:
(thread=Proxy:ExtendTcpProxyService:TcpAcceptor, member=1): TcpAcceptor now listening for connections on 192.168.1.5:7077
Parent topic: Building Your First Extend Application
Step 5: Run the Application
TestClient
application is started using the java
command and must be configured to use the cache configuration file.The following command line runs the application and assumes that the TestClient
class is located in the current directory. The cache configuration file is explicitly named using the coherence.cacheconfig
system property:
java -cp .;COHERENCE_HOME\lib\coherence.jar -Dcoherence.cacheconfig=PATH\example-client-config.xml TestClient
The output displays (among other things) that the client successfully connected to the extend proxy TCP address and the current value of the key in the cache. Run the client again to increment the key's value.
Note:
Check the cache server process output for the message confirming that the invocation task was executed remotely using the ExtendTcpInvocationService
service.
This has been run...
Parent topic: Building Your First Extend Application