Fusion Middleware Documentation
Advanced Search


Tutorial for Oracle Coherence
Close Window

Table of Contents

Show All | Collapse

1 Installing and Configuring Coherence

This chapter describes how to install and set up your environment for running Oracle Coherence 12c (12.1.2) (Coherence).

Note:

This tutorial uses the Eclipse Juno 3.8.0 release with Oracle Enterprise Pack for Eclipse (OEPE) 12.1.2.0.0. For information about configuring Eclipse and OEPE for Coherence-based projects, see Chapter 2, "Installing and Configuring Eclipse and OEPE with Coherence".

You must have the privileges to install software and set system environment variables as the oracle user, an understanding of how to use a terminal window, including setting environment variables, and creating and moving between directories. You must have a working installation of Java SE (JDK) version 1.7 or higher. You must also be running one of the following Microsoft Windows operating systems: XP, Vista, 2000, 2003, or 2008.

This chapter contains the following sections:

1.1 Installing Coherence

For information on installing Oracle Coherence, see "Installing Oracle Coherence for Java" in Oracle Fusion Middleware Developing Applications with Oracle Coherence. This chapter provides instructions for installing Oracle Coherence by using the Oracle Universal Installer. The installer supports both a graphical mode and a silent mode. You can also choose to use the Coherence Quick Installer to perform a silent installation with no options.

Note:

This tutorial assumes that you have used the Oracle Universal Installer graphical interface to install Oracle Coherence at C:\oracle\Middleware\Oracle_Home.

The coherence folder which appears under Oracle_Home contains these subfolders:

  • bin, which contains command scripts

  • doc, which contains the product documentation

  • examples, which contains code examples for the Java, .NET, and C++ platforms

  • lib, which contains the required library files

1.2 Testing a Coherence Installation

In this exercise, you test whether your Coherence installation can cluster Java processes. This ensures that Coherence-based applications that ship with Coherence will run as expected. If Coherence is not capable of clustering on a single machine, then you must reconfigure your network and firewall settings.

To complete this exercise, you must have Coherence (Java Edition) 12c (12.1.2) installed. See "Installing Coherence" for more information.

Coherence uses a variety of network addresses and ports to enable communication between clustered processes. If these addresses and ports are unavailable due to other applications using them, or because of a firewall, then Coherence may be unreliable, may fail to cluster, or may not work at all. By default, Coherence assumes that the network addresses and ports listed in Table 1-1 are available:

Table 1-1 Network Addresses and Ports Used by Coherence

Address / Port / Type Purpose

224.version / version / Multicast

Cluster member discovery and broadcast. The variable version represents the release version of Coherence. For example, the multicast address for the 12.1.2 release is 224.12.1.0. The port number also reflects the release version. For example, for the 12.1.2 release, the port number is 12100. Designing the address in this way ensures that different versions of Coherence do not cluster with each other by default.

localhost / 8088+ / Unicast

Interprocess communication between cluster members. (localhost is the local IP address and not the loop back address.)

localhost / 8089 / Unicast

An additional port that is used for unicast communication. By default, the port is assigned as the next available port after the first unicast port.

localhost / 7 / Unicast

The default port of the IpMonitor component that is used for detecting hardware failure of cluster members is "7".


Coherence ships with two simple command-line (shell-based) applications that can be used to determine whether Coherence operates correctly.

  • The cache server is a simple application that hosts and manages data on behalf of other applications in a cluster.

  • The cache client is a simple application that enables a developer to access, process, and update cached data within a cluster. It also provides information about the cluster. By executing these applications either on a single host or on several hosts, you can determine whether Coherence is operating correctly locally or across a network.

    When an application uses Coherence as shipped, objects placed into Coherence caches are typically stored and managed in-process within the application. However, to increase object availability, Coherence can manage objects in memory but out of the application process. This enables objects to survive possible application outages (either deliberate or accidental). To manage objects in this way, Coherence uses cache servers. The purpose of a Coherence cache server is to manage the application state in a cluster outside the application process. It is similar to a database server, but without the requirement for storage.

1.2.1 To Test a Coherence Installation—Main Steps

Follow these steps to test a Coherence Installation. The steps are described in detail in the following sections.

  1. Configure and Run the Sample Cache Server Application

  2. Configure and Run the Sample Cache Client Application

  3. Exercise the Sample Cache Client Application

  4. Troubleshooting Cache Server Clustering

1.2.2 Configure and Run the Sample Cache Server Application

To set up and run the sample cache server application:

  1. Open a terminal window and verify that the PATH environment variable is set to include the Java JDK (for example, C:\oracle\Middleware\jdk170\bin). If the PATH environment variable does not include the JDK \bin folder, then set it as follows:

    1. Set the JAVA_HOME environment variable to the base of the JDK installation.

      set JAVA_HOME=\oracle\Middleware\jdk170
      
    2. Include JAVA_HOME\bin in the PATH environment variable.

      set PATH=%JAVA_HOME%\bin;%PATH%
      
  2. Navigate to the folder where Coherence is installed. Edit the cache-server.cmd file and set the COHERENCE_HOME variable to point to the Coherence installation folder.

    cd C:\oracle\Middleware\Oracle_Home\coherence\bin
    

    In the cache-server.cmd file, set the COHERENCE_HOME environment variable:

    COHERENCE_HOME=C:\oracle\Middleware\Oracle_Home\coherence
    

    Example 1-1 illustrates the cache-server.cmd file with the edited value of the COHERENCE_HOME environment variable.

    Example 1-1 cache-server.cmd File with an Edited COHERENCE_HOME

    @echo off
    @
    @rem This will start a cache server
    @
    setlocal
     
    :config
    @rem specify the Coherence installation directory
    set coherence_home=c:\oracle\product\coherence
     
    @rem specify the JVM heap size
    set memory=512m
     
     
    :start
    if not exist "%coherence_home%\lib\coherence.jar" goto instructions
     
    if "%java_home%"=="" (set java_exec=java) else (set java_exec=%java_home%\bin\java)
     
     
    :launch
     
    if "%1"=="-jmx" (
       set jmxproperties=-Dtangosol.coherence.management=all -Dtangosol.coherence.management.remote=true
       shift  
    )       
     
    set java_opts=-Xms%memory% -Xmx%memory% %jmxproperties%
     
    %java_exec% -server -showversion %java_opts% -cp "%coherence_home%\lib\coherence.jar" -Dtangosol.coherence.clusterport=3155 com.tangosol.net.DefaultCacheServer %1
     
    goto exit
     
    :instructions
     
    echo Usage:
    echo   ^<coherence_home^>\bin\cache-server.cmd
    goto exit
     
    :exit
    endlocal
    @echo on
    
  3. Execute the cache server application that is located in the coherence\bin folder.

    C:\oracle\product\coherence\bin>cache-server.cmd
    

    When you start the first cache server, there is a slight delay because the cache server looks for an existing cluster. When the cache server determines that there are no clusters to join, it starts one. On start-up, the cache server produces output similar to the text in Example 1-2.

    Several important features are highlighted in the example:

    • The Java JDK version number.

    • Information about how configuration files are loaded. The default is to load from the coherence.jar file:

      Loaded operational configuration from resource "jar:file:/C:/oracle/product/coherence/lib/coherence.jar!/tangosol-coherence.xml"

    • The Coherence release number: Oracle Coherence 12.1.0.0...

    • The Coherence edition: Grid Edition: Development mode

    • The multicast address. This address changes with each Coherence version. Note the 12.1.0 in the address for Coherence 12c (12.1.2): Group{Address=224.12.1.0, Port=12100, TTL=4}

    • The Member ID indicates the number of members in your cluster. For the purpose of this exercise, the value should be 1. ThisMember=Member(Id=1...

    Example 1-2 Output from Starting a Coherence Cache Server

    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
     
    2012-08-14 15:29:26.171/0.656 Oracle Coherence 12.1.2.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:/oracle/Middleware/Oracle_Home/coherence/lib/coherence.jar!/tangosol-coherence.xml"
    2012-08-14 15:29:26.453/0.938 Oracle Coherence 12.1.2.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/oracle/Middleware/Oracle_Home/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
    2012-08-14 15:29:26.453/0.938 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-override.xml" is not specified
    2012-08-14 15:29:26.453/0.938 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "cache-factory-config.xml" is not specified
    2012-08-14 15:29:26.468/0.953 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "cache-factory-builder-config.xml" is not specified
    2012-08-14 15:29:26.468/0.953 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not specified
     
    Oracle Coherence Version 12.1.2.0 Build 36845
     Grid Edition: Development mode
    Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
     
    2012-08-14 15:29:27.015/1.500 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/oracle/Middleware/Oracle_Home/coherence/lib/coherence.jar!/coherence-cache-config.xml"
    2012-08-14 15:29:27.203/1.688 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/oracle/Middleware/Oracle_Home/coherence/lib/coherence.jar!/internal-txn-cache-config.xml"
    2012-08-14 15:29:27.781/2.266 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Created cache factory com.tangosol.net.ExtensibleConfigurableCacheFactory
    2012-08-14 15:29:28.265/2.750 Oracle Coherence GE 12.1.2.0 <D4> (thread=main, member=n/a): TCMP bound to /130.35.99.202:8088 using SystemDatagramSocketProvider
    2012-08-14 15:29:31.687/6.172 Oracle Coherence GE 12.1.2.0 <Info> (thread=Cluster, member=n/a): Created a new cluster "cluster:0x47DB" with Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.35.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:5044, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, CpuCount=2, SocketCount=1)
    2012-08-14 15:29:31.703/6.188 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Started cluster Name=cluster:0x47DB
     
    Group{Address=224.12.1.0, Port=12100, TTL=4}
     
    MasterMemberSet(
      ThisMember=Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.35.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:
    5044, Role=CoherenceServer)
      OldestMember=Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.35.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,proces
    s:5044, Role=CoherenceServer)
      ActualMemberSet=MemberSet(Size=1
        Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.35.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:5044, Rol
    e=CoherenceServer)
        )
      MemberId|ServiceVersion|ServiceJoined|MemberState
        1|12.1.2|2012-08-14 15:29:28.39|JOINED
      RecycleMillis=1200000
      RecycleSet=MemberSet(Size=0
        )
      )
     
    TcpRing{Connections=[]}
    IpMonitor{Addresses=0}
     
    2012-08-14 15:29:32.031/6.516 Oracle Coherence GE 12.1.2.0 <D5> (thread=Invocation:Management, member=1): Service Management joined the cluster with senior service member 1
    2012-08-14 15:29:32.203/6.688 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=1): Loaded Reporter configuration from "jar:file:/C:/oracle/Middleware/Oracle_Home/coherence/lib/coherence.jar!/reports/report-group.xml"
    2012-08-14 15:29:32.625/7.110 Oracle Coherence GE 12.1.2.0 <D5> (thread=DistributedCache, member=1): Service DistributedCache joined the cluster with senior service member 1
    2012-08-14 15:29:32.718/7.203 Oracle Coherence GE 12.1.2.0 <D5> (thread=ReplicatedCache, member=1): Service ReplicatedCache joined the cluster with senior service member 1
    2012-08-14 15:29:32.718/7.203 Oracle Coherence GE 12.1.2.0 <D5> (thread=OptimisticCache, member=1): Service OptimisticCache joined the cluster with senior service member 1
    2012-08-14 15:29:32.734/7.219 Oracle Coherence GE 12.1.2.0 <D5> (thread=Invocation:InvocationService, member=1): Service InvocationService joined the cluster with senior service member 1
    2012-08-14 15:29:32.734/7.219 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=1):
    Services
      (
      ClusterService{Name=Cluster, State=(SERVICE_STARTED, STATE_JOINED), Id=0, Version=12.1.2, OldestMemberId=1}
      InvocationService{Name=Management, State=(SERVICE_STARTED), Id=1, Version=12.1.2, OldestMemberId=1}
      PartitionedCache{Name=DistributedCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=257, BackupCount=1, AssignedPartitions=257, Ba
    ckupPartitions=0}
      ReplicatedCache{Name=ReplicatedCache, State=(SERVICE_STARTED), Id=3, Version=12.1.2, OldestMemberId=1}
      Optimistic{Name=OptimisticCache, State=(SERVICE_STARTED), Id=4, Version=12.1.2, OldestMemberId=1}
      InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=5, Version=12.1.2, OldestMemberId=1}
      )
     
    Started DefaultCacheServer...
    

    Note:

    By default, Coherence is configured to use multicast to join a cluster and to distribute cluster events. Multicast can also be used to distribute a message efficiently to multiple nodes in the cluster. You can configure Coherence to disable multicast.

    The output of the cache-server.cmd file indicates whether you have one or more members in your cluster. The value of Member Id should be equal to 1:

    ...
    In MasterMemberSet
    ThisMember=Member(Id should be equal to 1)
    ...
    

    If ThisMember has an Id greater than one, it means that your cache server has joined a pre-existing cluster in your network. For the purposes of these exercises, the cluster should contain only one member. Follow the steps in "Restricting Coherence to Your Own Host" to restrict Coherence to your own host.

1.2.3 Configure and Run the Sample Cache Client Application

To set up and run the sample cache client application:

  1. Open another terminal window to start the cache client.

    Verify that the PATH environment variable is set to include the %JAVA_HOME%\bin folder. If the PATH environment variable does not include the %JAVA_HOME%\bin folder, then set the variable as described in "Configure and Run the Sample Cache Server Application".

  2. Navigate to the \oracle\Middleware\Oracle_Home\coherence\bin folder. Edit the query.cmd file to set the COHERENCE_HOME variable to point to the Coherence installation folder.

    The query.cmd file includes a reference to the JLine JAR file (jline.jar). JLine is a Java library that simplifies working with console commands. The jline.jar file is included in the coherence\lib folder.

    Example 1-3 illustrates the query.cmd file, with COHERENCE_HOME=\oracle\product\coherence. JLINE_HOME is set to %jline_home%\lib.

    Example 1-3 query.cmd File with an Edited COHERENCE_HOME

    @echo off
    @
    @rem This will start a console application
    @rem demonstrating the functionality of the Coherence(tm) API
    @
    setlocal
     
    :config
    @rem specify the Coherence installation directory
    set coherence_home=C:\oracle\Middleware\Oracle_Home\coherence
     
    @rem specify the jline installation directory
    set jline_home=%coherence_home%\lib
     
    @rem specify if the console will also act as a server
    set storage_enabled=false
     
    @rem specify the JVM heap size
    set memory=64m
     
     
    :start
    if not exist "%coherence_home%\lib\coherence.jar" goto instructions
     
    if "%java_home%"=="" (set java_exec=java) else (set java_exec=%java_home%\bin\java)
     
     
    :launch
     
    if "%storage_enabled%"=="true" (echo ** Starting storage enabled console **) else (echo ** 
    Starting storage disabled console **)
     
    set java_opts="-Xms%memory% -Xmx%memory% 
    -Dtangosol.coherence.distributed.localstorage=%storage_enabled%"
     
    "%java_exec%" -server -showversion "%java_opts%" -cp 
    "%coherence_home%\lib\coherence.jar;%jline_home%\jline.jar" 
    com.tangosol.coherence.dslquery.QueryPlus %*
     
    goto exit
     
    :instructions
     
    echo Usage:
    echo   ^<coherence_home^>\bin\query.cmd
    goto exit
     
    :exit
    endlocal
    @echo on
    
  3. Execute the query.cmd file to start the cache client.

    query.cmd
    

    The output of starting the cache client, illustrated in Example 1-4, displays the basic distributed cache functionality that is built into Coherence. At the end of the output, the CohQL> prompt is displayed.

    Example 1-4 Output from Starting the Coherence Cache Client

    C:\oracle\Middleware\Oracle_Home\coherence\bin>query.cmd
    ** Starting storage disabled console **
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Server VM (build 21.0-b17, mixed mode)
    
    Coherence Command Line Tool
    
    CohQL>
    

1.2.4 Exercise the Sample Cache Client Application

Exercise the cache client application by entering various commands and examining the output.

  1. Execute the following Coherence commands in the cache client:

    • Enter help to see the list of commands that are available.

    • Enter create cache "products" to create a cache named products.

      The cache products implements the com.tangosol.net.NamedCache interface. A cluster can have many named caches.

      Example 1-5 illustrates that by using the default configuration file (coherence-cache-config.xml) within the supplied coherence.jar file, a NamedCache called products is created using the distributed scheme.

      Example 1-5 Output from Starting a Coherence Cache Client

      2012-08-14 16:15:28.828/26.485 Oracle Coherence 12.1.2.0 <Info> (thread=main, member=n/a): Loaded operational configuration from "jar:file:/C:/oracle/
      Middleware/Oracle_Home/coherence/lib/coherence.jar!/tangosol-coherence.xml"
      2012-08-14 16:15:29.062/26.719 Oracle Coherence 12.1.2.0 <Info> (thread=main, member=n/a): Loaded operational overrides from "jar:file:/C:/oracle/Midd
      leware/Oracle_Home/coherence/lib/coherence.jar!/tangosol-coherence-override-dev.xml"
      2012-08-14 16:15:29.062/26.719 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "/tangosol-coherence-override
      .xml" is not specified
      2012-08-14 16:15:29.062/26.719 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "cache-factory-config.xml" is
       not specified
      2012-08-14 16:15:29.062/26.719 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "cache-factory-builder-config
      .xml" is not specified
      2012-08-14 16:15:29.062/26.719 Oracle Coherence 12.1.2.0 <D5> (thread=main, member=n/a): Optional configuration override "/custom-mbeans.xml" is not s
      pecified
       
      Oracle Coherence Version 12.1.2.0 Build 36845
       Grid Edition: Development mode
      Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
       
      2012-08-14 16:15:31.296/28.953 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/oracle/Mid
      dleware/Oracle_Home/coherence/lib/coherence.jar!/coherence-cache-config.xml"
      2012-08-14 16:15:31.984/29.641 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Loaded cache configuration from "jar:file:/C:/oracle/Mid
      dleware/Oracle_Home/coherence/lib/coherence.jar!/internal-txn-cache-config.xml"
      2012-08-14 16:15:35.484/33.141 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Created cache factory com.tangosol.net.ExtensibleConfigu
      rableCacheFactory
      2012-08-14 16:15:37.125/34.782 Oracle Coherence GE 12.1.2.0 <D4> (thread=main, member=n/a): TCMP bound to /130.35.99.202:8090 using SystemDatagramSock
      etProvider
      2012-08-14 16:15:37.703/35.360 Oracle Coherence GE 12.1.2.0 <Info> (thread=Cluster, member=n/a): This Member(Id=2, Timestamp=2012-08-14 16:15:37.687,
      Address=130.35.99.202:8090, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:3796, Role=TangosolCoherenceQueryPlus, Edition=Grid Edition,
       Mode=Development, CpuCount=2, SocketCount=1) joined cluster "cluster:0x47DB" with senior Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.3
      5.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:5044, Role=CoherenceServer, Edition=Grid Edition, Mode=Development, CpuCo
      unt=2, SocketCount=1)
      2012-08-14 16:15:37.828/35.485 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service Management with senior member 1
       
      2012-08-14 16:15:37.828/35.485 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service DistributedCache with senior me
      mber 1
      2012-08-14 16:15:37.828/35.485 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service ReplicatedCache with senior mem
      ber 1
      2012-08-14 16:15:37.828/35.485 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service OptimisticCache with senior mem
      ber 1
      2012-08-14 16:15:37.828/35.485 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=n/a): Member 1 joined Service InvocationService with senior m
      ember 1
      2012-08-14 16:15:37.828/35.485 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=n/a): Started cluster Name=cluster:0x47DB
       
      Group{Address=224.12.1.0, Port=3155, TTL=4}
       
      MasterMemberSet(
        ThisMember=Member(Id=2, Timestamp=2012-08-14 16:15:37.687, Address=130.35.99.202:8090, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process
      :3796, Role=TangosolCoherenceQueryPlus)
        OldestMember=Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.35.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,proces
      s:5044, Role=CoherenceServer)
        ActualMemberSet=MemberSet(Size=2
          Member(Id=1, Timestamp=2012-08-14 15:29:28.39, Address=130.35.99.202:8088, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:5044, Rol
      e=CoherenceServer)
          Member(Id=2, Timestamp=2012-08-14 16:15:37.687, Address=130.35.99.202:8090, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:3796, Ro
      le=TangosolCoherenceQueryPlus)
          )
        MemberId|ServiceVersion|ServiceJoined|MemberState
          1|12.1.2|2012-08-14 15:29:28.39|JOINED,
          2|12.1.2|2012-08-14 16:15:37.687|JOINED
        RecycleMillis=1200000
        RecycleSet=MemberSet(Size=0
          )
        )
       
      TcpRing{Connections=[1]}
      IpMonitor{Addresses=0}
       
      2012-08-14 16:15:38.125/35.782 Oracle Coherence GE 12.1.2.0 <D5> (thread=Invocation:Management, member=2): Service Management joined the cluster with
      senior service member 1
      2012-08-14 16:15:38.640/36.297 Oracle Coherence GE 12.1.2.0 <Info> (thread=main, member=2): Loaded Reporter configuration from "jar:file:/C:/oracle/Mi
      ddleware/Oracle_Home/coherence/lib/coherence.jar!/reports/report-group.xml"
      2012-08-14 16:15:40.593/38.250 Oracle Coherence GE 12.1.2.0 <D5> (thread=DistributedCache, member=2): Service DistributedCache joined the cluster with
       senior service member 1
       
      CohQL>
      
  2. Execute the following commands at the CohQL> prompt in the cache client. For definitions of these commands, see "Using Coherence Query Language" in Oracle Fusion Middleware Developing Applications with Oracle Coherence.

    • Insert an entry (key-value pair) into the products cache:

      insert into "products" key "television" value "ID-5070"
      
    • Change the value of the key:

      update "products" set value() = "ID-5080" where key() like "television"
      
    • Retrieve the values in the cache:

      select * from "products" 
      
    • Retrieve the value of a key that does not exist. An empty result set will be returned:

      select key(), value() from "products" where key() is "radio" 
      
    • Delete an existing key in the cache. An empty result set will be returned:

      delete from "products" where key() = "television"
      
    • Delete the contents of the products cache. An empty result set will be returned:

      delete from "products"
      
    • Destroy the products cache:

      drop cache "products" 
      
    • Re-create the products cache:

      create cache "products" 
      
    • Insert more entries into the cache:

      insert into "products" key "television" value "ID-5080"
      insert into "products" key "radio" value "ID-5090"
      insert into "products" key "MP3 Player" value "ID-5100"
      insert into "products" key "laptop" value "ID-5110"
      
    • Retrieve the keys and values in the products cache:

      select key(), value() from "products" 
      
    • Save a serialized representation of the cache in a file:

      backup cache "products" to "products.bkup"
      
    • Delete a key from the cache:

      delete from "products" where key() = "television"  
      
    • Retrieve the cache contents again, notice that the deleted key and value will not be present:

      select key(), value() from "products" 
      
    • Delete the contents of the cache:

      delete from "products" 
      
    • Retrieve the contents of the cache. An empty result set will be returned:

      select * from "products"  
      
    • Restore the cache contents from the backup file:

      restore cache "products" from file "products.bkup" 
      
    • Retrieve the cache contents. Note that all of the entries will be restored and returned:

      select key(), value() from "products" 
      
    • Destroy the products cache:

      drop cache "products" 
      
    • Exit the command-line tool:

      bye 
      

    Example 1-6 illustrates the output of each of these commands.

    Example 1-6 Exercising Coherence Commands

    CohQL> create cache "products"
     
    CohQL> insert into "products" key "television" value "ID-5070"
     
    CohQL> update "products" set value() = "ID-5080" where key() like "television
    Results
    television: true
     
    CohQL> select * from "products"
    Results
    ID-5080
     
    CohQL> select key(), value() from "products" where key() is "radio"
    Results
     
    CohQL> delete from "products" where key() = "television"
    Results
     
    CohQL> delete from "products"
    Results
     
    CohQL> drop cache "products"
     
    CohQL> create cache "products"
     
    CohQL> insert into "products" key "television" value "ID-5080"
     
    CohQL> insert into "products" key "radio" value "ID-5090"
     
    CohQL> insert into "products" key "MP3 Player" value "ID-5100"
     
    CohQL> insert into "products" key "laptop" value "ID-5110"
    
    CohQL> select key(), value() from "products"
    Results
    "television", "ID-5080"
    "radio", "ID-5090"
    "MP3 Player", "ID-5100"
    "laptop", "ID-5110"
     
    CohQL> backup cache "products" to "products.bkup"
    WARNING: The backup command should not be used on active data set,
    as it makes no provisions that ensure data consistency during the backup.
    Please see the documentation for more detailed information.
     
    CohQL> delete from "products" where key() = "television"
    Results
     
    CohQL> select key(), value() from "products"
    Results
    "radio", "ID-5090"
    "MP3 Player", "ID-5100"
    "laptop", "ID-5110"
     
    CohQL> delete from "products"
    Results
     
    CohQL> select * from "products"
    Results
     
    CohQL> restore cache "products" from file "products.bkup"
     
    CohQL> select key(), value() from "products"
    Results
    "television", "ID-5080"
    "radio", "ID-5090"
    "MP3 Player", "ID-5100"
    "laptop", "ID-5110"
     
    CohQL> drop cache "products"
     
    CohQL> bye
    
    

    In the cache server window, you should see a response similar to the following, indicating that the client (member 2) has left the cluster:

    2012-08-14 16:57:54.953/5309.438 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): TcpRing disconnected from Member(Id=2, Timestamp=2012-08-14 16:15:37.687, Address=130.35.99.202:8090, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:3796, Role=TangosolCoherenceQueryPlus) due to a peer departure; removing the member.
    2012-08-14 16:57:54.953/5309.438 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): Member 2 left service Management with senior member 1
    2012-08-14 16:57:54.953/5309.438 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): Member 2 left service DistributedCache with senior member 1
    2012-08-14 16:57:54.953/5309.438 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): Member(Id=2, Timestamp=2012-08-14 16:57:54.953, Address=130.35.99.202:8090, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:3796, Role=TangosolCoherenceQueryPlus) left Cluster with senior member 1
    
  3. Open another terminal window and set the PATH environment variable to include %JAVA_HOME% and %JAVA_HOME%\bin. Enter the query.cmd command in the new terminal window to start an instance of the cache client.

  4. Restart the first client with the query.cmd command. Enter the create cache "products" command. The terminal window displays a message similar to the following that describes where the first client is running. member 1 is the cache server and member 3 is the restarted first client.

    2012-08-14 16:58:01.990/1562.468 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): Member(Id=3, Timestamp=2012-08-14 16:48:01.85, Address=130.35.99.165:8090, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:2804, Role=TangosolCoherenceQueryPlus) joined Cluster with senior member 12012-08-14 16:58:02.256/1562.734 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): Member 3 joined Service Management with senior member 12012-08-14 16:58:02.740/1563.218 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=1): Member 3 joined Service DistributedCache with senior member 1 
    
    CohQL> 
    
  5. Enter the create cache "products" command in the new terminal window to connect to the products cache. It enters the cluster as Member 4. Try to get and put values in different sessions. Notice that each client can observe changes made by the other client.

  6. Terminate one of the query.cmd client shells (bye). Note that the other shell displays a message indicating that the member has left the cluster, for example:

    CohQL> 2012-08-14 16:56:43.912/714.109 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=3): TcpRing disconnected from Member(Id=4, Timestamp=2012-08-14 16:53:08.709, Address=130.35.99.165:8092, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:4656, Role=TangosolCoherenceQueryPlus) due to a peer departure; removing the member.2012-08-14 16:56:43.912/714.109 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=3): Member 4 left service Management with senior member 12012-08-14 16:56:43.912/714.109 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=3): Member 4 left service DistributedCache with senior member 12012-08-14 16:56:43.912/714.109 Oracle Coherence GE 12.1.2.0 <D5> (thread=Cluster, member=3): Member(Id=4, Timestamp=2012-08-14 16:56:43.912, Address=130.35.99.165:8092, MachineId=18578, Location=site:,machine:tpfaeffl-lap7,process:4656, Role=TangosolCoherenceQueryPlus) left Cluster with senior member 1  
    
  7. If you terminate each of the cache clients (bye), and then restart them, note that data from the previous session is still available. This is because the data is held in the cache server.

  8. If you start another Coherence cache server, and then terminate the initial one that was started (using Ctrl+C or by closing the command window), note that the data is still available.

  9. Terminate both the query.cmd shells and cache-server.cmd shell. Restart query.cmd. Create a cache called test using the command create cache test. Try to put a value into the cache, as before. Because the cache client is configured to start in storage-disabled mode, you will receive a response similar to the following:

    com.tangosol.net.RequestPolicyException: No storage-enabled nodes exist for service DistributedCache
    
  10. Start a cache server by running the cache-server.cmd file. Try to insert a value again. This time, the value will be accepted.

  11. Terminate all cache servers.

1.2.5 Troubleshooting Cache Server Clustering

If the value of Member ID in the cache-server.cmd output is anything other than 1, then this indicates that the cache server has clustered with one or more other cache servers or processes running Coherence. These servers or processes can be running on the network or running locally on your host. Though this is the default behavior for Coherence—to cluster with other processes running Coherence locally or on a network—it is strongly advised that while you perform this tutorial, you restrict Coherence to your own host.

Note:

To restrict Coherence to a single host, the cache server and cache client executable files used in this tutorial use the tangosol.coherence.clusterport command line property set to 3155.

1.2.5.1 Restricting Coherence to Your Own Host

The value of the Member ID in the output of the cache-server.cmd cache server command indicates whether you have one or more members in your cluster. For the purpose of this tutorial, the value of Member ID must be equal to 1:

...
In MasterMemberSet
ThisMember=Member(Id should be equal to 1)
...

If the value of Member ID is greater than 1, it means that multiple clusters are being formed in your subnet.

There are several ways to restrict Coherence to your own host. The easiest way is to use the tangosol.coherence.clusterport system property to declare a unique cluster port value in your cache server startup file. For example, add the following Java option to your cache-server.cmd file. The value assigned to the system property can be any unique value, such as the last four digits of your telephone number.

-Dtangosol.coherence.clusterport=3155

1.2.5.2 Advanced Steps to Restrict Coherence to Your Own Host

If you follow the steps in "Restricting Coherence to Your Own Host" and the cache-server.cmd command still fails to return a Member Id value of 1, then there might be additional problems to resolve.

Disconnect from the network or disable networking on your host. If errors or exceptions occur when starting the cache server, your network settings might need to be modified. Try each of the following one at a time, restarting the cache server after each attempt:

  • If connected to a Virtual Private Network (VPN), then disconnect from it. By default, most VPN are not configured to permit multicast and some unicast traffic. In this environment, Coherence might not work, if left in the configuration in which it was shipped. Coherence can be configured to run across a VPN, but this requires some advanced settings.

  • If you run a firewall, configure it to enable the specified addresses and ports.

  • If you still experience problems, disconnect from all networks. This includes wireless and wired networks.

  • If all the preceding options fail, set up Coherence to run on a single host.

1.3 Introducing the Coherence examples.zip File

The Coherence distribution provides an examples.zip file that contains many of the examples found in this tutorial. They demonstrate many of the cache access, processing, and security features in Coherence. The examples are designed to be built and run from the command line. The output of the examples is directed to standard output (stdout).

Appendix A, "Coherence Examples in the examples.zip File"provides information on building and running the examples. It also provides minimal documentation on the code in the examples.zip file. More detailed information about the code is embedded as comments in the individual code files.

There are a number of differences between the examples in the examples.zip file and the examples in this tutorial:

  • The examples in the examples.zip must be built and run from the command line. This tutorial uses an IDE to compile and run the code.

  • The examples in the examples.zip file demonstrate how to use basic Coherence functionality and security features in all supported languages (Java, .NET, and C++). The tutorial covers only Java implementations.

  • The Java examples in the examples.zip file are only a subset of the Java examples presented in the tutorial.

  • The Java files in the examples.zip file are similar to the files used in this tutorial. In many instances, the code in the tutorial has been simplified for demonstration purposes.

You can obtain the examples.zip file by performing a full Coherence installation with the coherence_version.jar or wls_version.jar file.

If you have already installed Coherence but without the examples, you can obtain the examples.zip file by running the coherence_quick_supp_version.jar supplemental installer file. The supplemental installer contains only API documentation and examples.

Note that the coherence_quick_version.jar quick installer does not install the examples.