[sword-cvs] sword/bindings/corba/java/src/org/crosswire/sword/orb SwordOrb.java,1.5,1.6

sword@www.crosswire.org sword@www.crosswire.org
Mon, 18 Aug 2003 10:32:55 -0700


Update of /usr/local/cvsroot/sword/bindings/corba/java/src/org/crosswire/sword/orb
In directory www:/tmp/cvs-serv12750/bindings/corba/java/src/org/crosswire/sword/orb

Modified Files:
	SwordOrb.java 
Log Message:
Added testConnection to ORB and use this in the java client to assure
if ORB service dies for a session, that it is restarted seamlessly.


Index: SwordOrb.java
===================================================================
RCS file: /usr/local/cvsroot/sword/bindings/corba/java/src/org/crosswire/sword/orb/SwordOrb.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- SwordOrb.java	6 May 2003 07:43:18 -0000	1.5
+++ SwordOrb.java	18 Aug 2003 17:32:53 -0000	1.6
@@ -19,11 +19,17 @@
 	private SWMgr attach() {
 		SWMgr retVal = null;
 		try {
+System.out.println("attaching...");
 			org.omg.CORBA.Object obj = orb.string_to_object(ior);
 			retVal = SWMgrHelper.narrow(obj);
+System.out.println("calling testConnection");
+			retVal.testConnection();
+System.out.println("testConnection successful");
 		}
 		catch(org.omg.CORBA.SystemException e) {
 			e.printStackTrace();
+			retVal = null;
+System.out.println("failed in attach");
 		}
 		return retVal;
 	}
@@ -35,7 +41,6 @@
 //	this doesn't seem to work.  Never seems to get called for me
 	public void finalize () throws Throwable {
 		// shut down external process
-System.err.println("finalizing");
 		try {
 			getSWMgrInstance().terminate();
 		}
@@ -43,14 +48,18 @@
 
 	}
 
+
 	public void valueBound(HttpSessionBindingEvent httpSessionBindingEvent) {}
+
 	public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent) {
 		try {
-			getSWMgrInstance().terminate();
+			throw new Exception("value unbound; showing stacktrace");
+//			getSWMgrInstance().terminate();
 		}
-		catch (Exception e) {}	// we know this doesn't return property cuz we killed the orb! :)
+		catch (Exception e) {e.printStackTrace();}	// we know this doesn't return property cuz we killed the orb! :)
 	}
 
+
 	private void startOrb() {
 		try {
 			// start external process
@@ -63,21 +72,32 @@
 			line = input.readLine();
 //		retVal = p.waitFor();
 			ior = line;
+System.out.println("Launched ORB, IOR: " + ior);
 		}
 		catch (Exception e) {e.printStackTrace();}
 	}
 
+
 	public SWMgr getSWMgrInstance() {
 		SWMgr retVal = null;
 		try {
+System.out.println("trying to attach to running ORB");
 			retVal = attach();
-			if (retVal == null) {
-				startOrb();
-				retVal = attach();
-			}
 		}
 		catch(org.omg.CORBA.SystemException e) {
 			e.printStackTrace();
+			retVal = null;
+		}
+		if (retVal == null) {
+			try {
+System.out.println("no ORB running; trying to launch");
+				startOrb();
+System.out.println("trying to attach to newly launched ORB");
+				retVal = attach();
+			}
+			catch(org.omg.CORBA.SystemException e) {
+				e.printStackTrace();
+			}
 		}
 		return retVal;
 	}
@@ -86,10 +106,15 @@
 	public static SWMgr getSWMgrInstance(HttpSession session) {
 		SwordOrb orb = (SwordOrb)session.getAttribute("SwordOrb");
 		if (orb == null) {
+System.out.println("No ORB found in session; constructing a new instance");
 			orb = new SwordOrb();
 			session.setAttribute("SwordOrb", orb);
 		}
-		return orb.getSWMgrInstance();
+		else {
+System.out.println("ORB found in session");
+		}
+		SWMgr mgr = orb.getSWMgrInstance();
+		return mgr;
 	}