Home > Coherence, Java, Oracle > Joining the Existing Cluster in Coherence

Joining the Existing Cluster in Coherence

In previous post I had tried to explain some of the output parameters of Coherence. In this post I will explain how a member can join the existing cluster by setting some parameters.

Before this post you should completed this post:
Running a Coherence Application in Eclipse
We’ve already run this example within Eclipse. Basically it creates a cluster and a cache then put a custom object into the cache. And because of code is over in CustomerTest1.java Coherence Cache automatically closed. To prevent closing automatically we’ll edit the CustomerTest1.java and add the below code to control the application flow.

String dummy;
Scanner user_input = new Scanner( System.in );
dummy = user_input.next( );

And the changed version of CustomerTest1.java is now here:

package com.afsungur.coherence.test;

import java.util.Scanner;

import com.afsungur.coherence.objects.Customer;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class CustomerTest1 {

        public static void main(String args[])
        Customer cust = new Customer("Ahmet Fuat", "Sungur", "Bahcelievler/Istanbul", "afsungur@gmail.com", "5321231231", 34111);
        NamedCache cache = CacheFactory.getCache("customers");
        cache.put(1, cust) ;
        System.out.println("Cache Size:"+cache.size());

        String dummy;
        Scanner user_input = new Scanner( System.in );
        dummy = user_input.next( );



After editing you can run the application inside Eclipse and then you see that application will wait for some input to terminate the cache server. But before terminating we may allow another member to join the cluster.

By the way you can check which parameters were used to start cluster inside the Eclipse as shown in below :

[oracle@localhost bin]$ ps -ef | grep coherence
oracle    6835  2873  8 13:18 ?        00:00:02 /labs/wls1211/jdk160_29/bin/java -Dtangosol.coherence.cacheconfig=src/config/coherence-cache-config.xml -Dtangosol.coherence.cluster=MyFirstCluster -Dtangosol.pof.config=/home/oracle/labs/Coh_labs/workspace/CohExam_AFSungur/src/config/pof-config.xml -Dtangosol.coherence.clusterport=7252 -Dfile.encoding=UTF-8 -classpath /home/oracle/labs/Coh_labs/workspace/CohExam_AFSungur/src/config:/labs/wls1211/coherence_3.7/lib/coherence.jar:/home/oracle/labs/Coh_labs/workspace/CohExam_AFSungur/bin com.afsungur.coherence.test.CustomerTest1
oracle    6874  5387  0 13:19 pts/1    00:00:00 grep coherence
[oracle@localhost bin]$ 

And so, how we can add a member to cluster? We know that there is a cluster which serves from 7252 port and also we now the cluster name ( MyFirstCluster ) and so on. We can check this parameters from Run->Run Configurations->Coherence(Main Tab)->Other(Sub Tab).
And also you can check as shown in above by using “ps” linux command.

Under the bin folder of coherence main folder ( something like coherence3.7/bin ), there are some sh files. cache-server.sh and coherence.sh can be used to join cluster. Coherence.sh provides an interactive environment to query the cache for putting, getting, listing or something else. Therefore, we use coherence.sh to join cluster.

Just before running the coherence.sh file we edit file and add below arguments to the line which starts with “JAVA_OPTS=” and then save as the file coherence_join_cluster_test1.sh .

-Dtangosol.coherence.cluster=MyFirstCluster -Dtangosol.coherence.clusterport=7252

Then, start the coherence_join_cluster_test1.sh and the analyse the output:
Cluster Join

Most part of output is similar to single member cluster. But there are a few differences.
First of all, at the top of output you see that new member are using the default operational configuration file which is inside the jar file.
And the middle of the output at the MasterMemberSet section you can see that currently how many members are there in the cluster, what is the current member id (ThisMember part), oldest member id and so on.
At the bottom of page you can see the interactive command line and “Map (?):” is written at the left side. Type “help” and then you can see all available commands.

In this post I’ve explained how a member join the existing cluster. In next post I’ll explain how just joined member can use the existing cache.

  1. Sundeep
    February 20, 2013 at 6:25 am

    Hi, first of all thanks for the great tutorial. Can’t we do this by modifying the coherence-cache-config.xml by defining another distributed scheme in the same file instead of running Coherence.sh file?

  2. Ahmet Fuat Sungur
    February 20, 2013 at 8:20 am

    You’re welcome. In a coherence cluster there are several members ( each jvm process which connects to the cluster is a member ) and several caches. Each member can use several caches and several members can use just one cache as well.

    In this post I have tried to explain how several members can use the same cache in the same cluster. We need to several members in order to carry out high availability and scalability. To create a member we have to start a jvm process which specifies the coherence.jar as in its classpath. If we will add a new distributed scheme or cache mapping in the coherence-cache-config.xml file we would add a new cache or cache scheme but we dont want to do it.

    I hope I could help you.

  1. August 23, 2012 at 6:41 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: