Clustering with Shoal

Clustering for failover is a common practice but in the past always required heavy-weight frameworks or application servers and in the java world was mostly tailored towards J2EE/web applications. Writing clustering code from scratch is not always an option since you have to account for various boundary conditions and configurations (Two GeneralsSplit Brain). Ultimately it can be done but in the real world of business applications it will probably be difficult to find someone who would be willing to pay for it.

So if you have a lightweight (Java SE/pojo) business critical service and you want to protect your service from hardware failures your options were somewhat limited in the past (shell scripts and ping?). I recently discovered the Shoal project which fills that void beautifully.

Shoal is: “an open source, Java-based generic clustering framework. It can be used in your applications to add clustering functionalities like load balancing, fault tolerance, or both. Applications using Shoal can share data, communicate via messages with other cluster nodes across the network, and notify of relevant events like the joining, shutdown, and failure of a node or group of nodes.”. It also happens to be the clustering framework used by the Glassfish project and uses JXTA for peer-to-peer communications.

I recently used Shoal for a prototype that I was working on and it worked like a charm. Using the api is fairly straight-forward. In order to join a group:

//initialize Group Management Service
GroupManagementService gms = initializeGMS(serverName, groupName);

//register for Group Events
registerForGroupEvents(gms);

//join group
joinGMSGroup(groupName, gms);

// get group handle
groupHandle = gms.getGroupHandle();

And you can monitor whether you are the master node by using a simple monitor thread and taking actions based on status changes. This example just prints out your current status:

if(groupHandle != null) {
     print("Am I the master node?: " + groupHandle.isGroupLeader());
     print("Master node is:" + groupHandle.getGroupLeader());
}

Shoal also has various api’s that facilitate communication and data sharing amongst cluster members. Using Shoal you should be able to put together any mission-critical application quickly by enabling load balancing and fault tolerance without having to rely on bloated frameworks/infrastructure.

2 responses to “Clustering with Shoal

  1. Hey Kaveh,

    I am going down the same road you went 2 years back in search of a clustering solution. After my initial research, I am more inclined to go with JGroups. Is there any reason why you preferred Shoal over JGroups? There is not much activity around Shoal these days.

    Alosh

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s