2

I need to run some business logic once and only once in a Geronimo/Tomcat cluster when a WAR (or EAR) deploys and before the applications starts serving to users.

The way I've been doing this has been to-date has been ad-hoc and is not fault tolerant. I use a configuration file on node 1 and designate it the "startup node". When the application starts up in the cluster, every node writes its ip address to a database and then sleep-waits in a Servlet.init that was set to load-on-startup in web.xml. When the startup node sees that all expected nodes have written their IP to the database, it runs the business logic. When the startup business logic completes, it sends the all-clear to the other nodes by writing a confirmation row to the database.

All of the non-startup nodes periodically (twice a second) poll the database for this all-clear signal, and when they see it, they finish their startup and return from Servlet.init. At this point all of the nodes serve the application normally to users.

I haven't had my startup logic fail yet, but I was wondering if there was some Java EE standard or robust 3rd party library approach to running my startup logic only once across my cluster. Thanks!

Edit 2013/07/21: I recalled that WebLogic Server had sophisticated startup facilities that might be useful in achieving the "init only once in the cluster" logic that I want to do in my Geronimo/Tomcat cluster. I did some digging and yes, WebLogic can do exactly what I want! Here is a great article on the subject: http://developsimpler.blogspot.com/2012/03/weblogic-clusters-and-singleton-service.html

I cannot afford WebLogic, unfortunately. So, is there anything similar in Geronimo or Tomcat (or other open source Java EE servers?) Or, are there 3rd party libraries I might use to achieve the same thing?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
DWoldrich
  • 3,817
  • 1
  • 21
  • 19

1 Answers1

1

For distributed coordination, there are tools like Zookeeper.

I don't think there is a Java EE standard for what you are looking for and I can't understand such an usecase, can you describe why you want 1 single "master" app to wait for other applications to startup?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
  • Sure. In my particular app, I need the startup node to wait for the cassandra cluster to start (each node of my Geronimo cluster is also a cassandra storage node). After the Cassandra ring is ready, I have the nodes wait until the startup node can make any needed schema changes that the code expects. – DWoldrich Jul 19 '13 at 23:10
  • I like zookeeper, but it's memory footprint puts it out of my league for the time being. – DWoldrich Jul 19 '13 at 23:11
  • Can this solve your problem? http://www.datastax.com/drivers/java/apidocs/com/datastax/driver/core/Host.StateListener.html – Sebastien Lorber Jul 19 '13 at 23:17
  • I essentially do something similar to what that class describes by tapping the JMX Beans that Cassandra exposes. The kernel of my question is not concerned managing Cassandra startup (although that's a prereq step to my implementation). To abstract my question a little: is there some good way to synchronize all my nodes at startup and make them wait while one healthy node in the cluster is elected to run some business logic. Once that business logic is complete, then the nodes are free to complete their init and start serving requests from users. – DWoldrich Jul 19 '13 at 23:37
  • IMO if you need to upgrade the schema without losing the data, you should not run embeded Cassandra nodes. The concept of "healthy node" is relative to your usecase so I really don't think any solution exist for your problem – Sebastien Lorber Jul 20 '13 at 00:09
  • @Sebastian_Lorber I suspect also there is no solution to my problem. To help stimulate discussion, I added some notes to my original question above. – DWoldrich Jul 22 '13 at 04:19