2

I have a EJB application running on Glassfish server which stores data on MySQL DB which I call as Global DB. I have two exact remote Swing applications which are stand alone applications accessing EJB's using RMI. They have their own local DB in case of lost connection.

My aim is to implement two phase commit protocol i.e to make one participant as coordinator and others as participants.

One method which I could think of was to implement using JMS i.e send a message across queue and make remote clients listen to these messages and take appropriate action. I do this my sending a message on Buttonclick of one of the Swing application. Problem is, even tough I have implemented MessageListener, onMessage() method does not receive any message for the other client.

Each Remote client has following properties set:

 props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
 props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
 props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
 props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
 props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

This is to connect to Glassfish server and access the connectionFactory and Queue which I have already configured.

Is it because only application running on server are allowed to receive messages and not remote applications?

Any suggestions for topology for 2 PC are welcome.

fmendez
  • 7,250
  • 5
  • 36
  • 35
qwerty
  • 163
  • 3
  • 12

2 Answers2

1

For this, we used JMS for exchanging the messages between these systems i.e one acting as coordinator who will initiate the process by sending message on the queue and others will respond accordingly by sending back again a message on the queue.

qwerty
  • 163
  • 3
  • 12
0

Since you are using EJB,you can use JTA to manage transcation,it a standard implementation of two-phased commit protocal,and JMS support JTA too. Here are my steps:

  1. config the trans-attribute to Required/Mandatory /Supports, depends on you need.
  2. in your client get UserTransaction by lookup jndi from the EJB server.
  3. start the transaction from client.
  4. commit/rollback the transaction at client side

This is the so called "Client owner tranaction design pattern". I suggest you to read the book javatransactionsbook

Harry.Chen
  • 1,582
  • 11
  • 12
  • Thank you for your response. We did try looking into into JTA as you mentioned but eventually we handled our task by implementing JMS+Queue. – qwerty Mar 19 '13 at 09:30