Oracle Coherence

I was trying to setup Oracle Coherence on my Ubuntu machine. I searched for some good examples online but no luck. So i decided to post my own. Here is my experience setting up Oracle Coherence on a linux distro.

1. Download Coherence
You can download the latest Oracle Coherence from their website. At the time of this writing the current version is 3.7 (http://www.oracle.com/technetwork/middleware/coherence/overview/index.html)

2. Setup COHERENCE_HOME
I have JAVA_HOME already setup. If not you would need to set that up first.
After that you would need to set up the following:

$ export COHERENCE_HOME=/home/YOU_LOCATION/coherence
$ export PATH=$PATH:$COHERENCE_HOME/bin

Note: You can put this on your .profile if you want to plan to preserve your variables, else you will have to export the variable on each terminal tabs.

3. Basic setup
Since I am trying this out on 1 machine, I will do a basic setup. For this, I will have a cache server and a cache factory process running. Coherence by default does multicast to find cluster members. It could be set up to be unicast, if you so choose. Learn more from the pdf link below in the notes section. (You can simply ignore the details for now)

4. Touch up the scripts
The coherence directory should have few scripts inside the ‘bin’ folder. I was getting “Bad substitution” error when I tried running the script out of the box, So, I decided to trim it down. Below is the condensed version of the script that made sense to me and cut out some fat.
One of the thing to point out is that I added “-Dtangosol.coherence.cluster=shrestha -Dtangosol.coherence.clusterport=8090” in the JAVA_OPTS which doesnt exist in the canned script

See the scripts below:

cache-server.sh

# specify the JVM heap size
MEMORY=512m

if [ -f $JAVA_HOME/bin/java ]; then
  JAVAEXEC=$JAVA_HOME/bin/java
else
  JAVAEXEC=java
fi

if [[ $1 == '-jmx' ]]; then
    JMXPROPERTIES="-Dcom.sun.management.jmxremote -Dtangosol.coherence.management=all -Dtangosol.coherence.management.remote=true"
    shift
fi

JAVA_OPTS="-Xms$MEMORY -Xmx$MEMORY $JMXPROPERTIES -Dtangosol.coherence.cluster=shrestha -Dtangosol.coherence.clusterport=8090"

$JAVAEXEC -server -showversion $JAVA_OPTS -cp $COHERENCE_HOME/lib/coherence.jar com.tangosol.net.DefaultCacheServer $1

coherence.sh

if [ -f $JAVA_HOME/bin/java ]; then
  JAVAEXEC=$JAVA_HOME/bin/java
else
  JAVAEXEC=java
fi

if [ $STORAGE_ENABLED == "true" ]; then
	echo "** Starting storage enabled console **"
else
	echo "** Starting storage disabled console **"
fi

JAVA_OPTS="-Xms$MEMORY -Xmx$MEMORY -Dtangosol.coherence.distributed.localstorage=$STORAGE_ENABLED $JMXPROPERTIES -Dtangosol.coherence.cluster=shrestha -Dtangosol.coherence.clusterport=8090"

$JAVAEXEC -server -showversion $JAVA_OPTS -cp $COHERENCE_HOME/lib/coherence.jar com.tangosol.net.CacheFactory $1

5. Running Coherence
If you got through here, you are ready to start your coherence.
Now, Lets start the server, simply run the “cache-server.sh”

$ ./cache-server.sh

You should see something like

... ... ...
Services
  (
  ClusterService{Name=Cluster, State=(SERVICE_STARTED, STATE_JOINED), Id=0, Version=3.7.1, OldestMemberId=1}
  InvocationService{Name=Management, State=(SERVICE_STARTED), Id=1, Version=3.1, OldestMemberId=1}
  PartitionedCache{Name=DistributedCache, State=(SERVICE_STARTED), LocalStorage=enabled, PartitionCount=257, BackupCount=1, AssignedPartitions=257, BackupPartitions=0}
  ReplicatedCache{Name=ReplicatedCache, State=(SERVICE_STARTED), Id=3, Version=3.0, OldestMemberId=1}
  Optimistic{Name=OptimisticCache, State=(SERVICE_STARTED), Id=4, Version=3.0, OldestMemberId=1}
  InvocationService{Name=InvocationService, State=(SERVICE_STARTED), Id=5, Version=3.1, OldestMemberId=1}
  )

Started DefaultCacheServer...

Now, lets start a coherence.sh

$ ./coherence.sh

if everything went right, you may see a shell “Map(?) :”

... ... ...
TcpRing{Connections=[1]}
IpMonitor{AddressListSize=0}

2011-10-18 23:14:10.951/2.581 Oracle Coherence GE 3.7.1.0 <D5> (thread=Invocation:Management, member=2): Service Management joined the cluster with senior service member 1

Map (?):

foo bar
Now its time to take it for a spin,
in the pompt type “cache Test” to create cache named “Test”

Map (?): cache Test
Map (Test):

Lets add a key value pair, for this, we do “foo” “bar”

Map Test): put foo bar

Verify the value is stored property

Map (Test): get foo
bar

If you want to try more, you can spin up another “coherence” process by running the “coherence.sh” in another terminal. You can work with same cache, you can add values in that and go back to previous shell and see the value is globally replicated.

PS: http://download.oracle.com/docs/cd/E18686_01/coh.37/e18692.pdf