[Mulgara-dev] SessionFactoryFinder local vs. remote behavior

Edwin Shin eddie at cs.cornell.edu
Thu Nov 22 04:58:22 UTC 2007


SessionFactoryFinder.newSessionFactory(URI, boolean) suggests (to me, 
anyway) that if isRemote is false, a local connection should be 
attempted. However, the implementation is such that a remote connection 
is always attempted first, and a local connection is only attempted as a 
fallback.

So, if for example, I wish to work with a local (in-JVM) Mulgara but 
also happen to have a "remote" Mulgara running at the moment, the 
following code will always fail with a ClassCastException:

LocalSessionFactory factory = (LocalSessionFactory) 
SessionFactoryFinder.newSessionFactory(new 
URI("rmi://localhost/server1"), false);

(java.lang.ClassCastException: org.mulgara.server.rmi.RmiSessionFactory 
cannot be cast to org.mulgara.server.local.LocalSessionFactory)

This can all be avoided by simply using "local" for the scheme instead 
of "rmi" (e.g. local://localhost/server1) but I'd argue that
a) the method signature and javadoc are misleading
b) it's unfortunate that the success or failure of the above code varies 
according to Mulgara running alongside or not.

I think something like the following would do the trick:

@@ -142,7 +142,9 @@
      String className;

      // Handle RMI schemes differently.
-    if (serverURI.getScheme().equals("rmi")) {
+    if (!isRemote) {
+      className = (String) schemeMap.get("local");
+    } else if (serverURI.getScheme().equals("rmi")) {
        logger.debug("Attempting to connect via RMI");
        // First attempt to connect via RMI.
        try {



More information about the Mulgara-dev mailing list