[Mulgara-svn] r1269 - in trunk/src/jar: query/java/org/mulgara/query/operation querylang/java/org/mulgara/itql resolver-distributed/java/org/mulgara/resolver/distributed/remote rules/java/org/mulgara/rules server-rmi/java/org/mulgara/server/rmi util/java/org/mulgara/util

pag at mulgara.org pag at mulgara.org
Wed Sep 24 18:47:05 UTC 2008


Author: pag
Date: 2008-09-24 11:47:03 -0700 (Wed, 24 Sep 2008)
New Revision: 1269

Added:
   trunk/src/jar/util/java/org/mulgara/util/Rmi.java
Modified:
   trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java
   trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java
   trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
   trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java
   trunk/src/jar/rules/java/org/mulgara/rules/RulesRefImpl.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswer.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionFactoryImpl.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteXAResourceWrapperXAResource.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/XAResourceWrapperRemoteXAResource.java
Log:
Changed RMI exports through UnicastRemoteObject to work through a new utility class instead. This class ignores the possibility of non-RMI transport, but that is OK as we don't expect to use this mechanism for anything but RMI anyway. The new org.mulgara.util.Rmi is now integrated, but configuration has not yet been set up to tell it to use any but the default ports.

Modified: trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataInputTx.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -16,12 +16,12 @@
 import java.net.URI;
 import java.net.URL;
 import java.rmi.NoSuchObjectException;
-import java.rmi.server.UnicastRemoteObject;
 import java.util.zip.GZIPInputStream;
 import java.util.zip.ZipInputStream;
 
 import org.mulgara.connection.Connection;
 import org.mulgara.query.QueryException;
+import org.mulgara.util.Rmi;
 
 import edu.emory.mathcs.util.remote.io.RemoteInputStream;
 import edu.emory.mathcs.util.remote.io.server.impl.RemoteInputStreamSrvImpl;
@@ -104,7 +104,7 @@
 
       // open and wrap the inputstream
       srv = new RemoteInputStreamSrvImpl(inputStream);
-      UnicastRemoteObject.exportObject(srv);
+      Rmi.export(srv);
       remoteInputStream = new RemoteInputStream(srv);
 
       // call back to the implementing class
@@ -114,7 +114,7 @@
       // clean up the RMI object
       if (srv != null) {
         try {
-          UnicastRemoteObject.unexportObject(srv, false);
+          Rmi.unexportObject(srv, false);
         } catch (NoSuchObjectException ex) {};
       }
       try {

Modified: trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java
===================================================================
--- trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/query/java/org/mulgara/query/operation/DataOutputTx.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -17,10 +17,10 @@
 import java.io.OutputStream;
 import java.net.URI;
 import java.rmi.NoSuchObjectException;
-import java.rmi.server.UnicastRemoteObject;
 
 import org.mulgara.connection.Connection;
 import org.mulgara.query.QueryException;
+import org.mulgara.util.Rmi;
 
 import edu.emory.mathcs.util.remote.io.RemoteOutputStream;
 import edu.emory.mathcs.util.remote.io.server.impl.RemoteOutputStreamSrvImpl;
@@ -100,7 +100,7 @@
       
       // open and wrap the output stream
       srv = new RemoteOutputStreamSrvImpl(outputStream);
-      UnicastRemoteObject.exportObject(srv);
+      Rmi.export(srv);
       remoteOutputStream = new RemoteOutputStream(srv);
       
       // call back to the implementing class
@@ -117,7 +117,7 @@
       // cleanup the RMI for the output stream
       if (srv != null) {
         try {
-          UnicastRemoteObject.unexportObject(srv, false);
+          Rmi.unexportObject(srv, false);
         } catch (NoSuchObjectException ex) {};
         try {
           srv.close();

Modified: trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java
===================================================================
--- trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/querylang/java/org/mulgara/itql/ItqlInterpreterBeanUnitTest.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -31,6 +31,7 @@
 import org.mulgara.query.QueryException;
 import org.mulgara.server.SessionFactory;
 import org.mulgara.server.driver.SessionFactoryFinder;
+import org.mulgara.util.Rmi;
 import org.mulgara.util.TempDir;
 
 // third party packages
@@ -41,7 +42,6 @@
 import java.net.URL;
 import java.util.Vector;
 import java.net.*;
-import java.rmi.server.UnicastRemoteObject;
 import java.io.File;
 import java.io.FileOutputStream;
 
@@ -434,7 +434,7 @@
         new RemoteInputStreamSrvImpl(sourceURI.toURL().openStream());
 
     // prepare it for exporting
-    UnicastRemoteObject.exportObject(srv);
+    Rmi.export(srv);
 
     RemoteInputStream inputStream = new RemoteInputStream(srv);
 

Modified: trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java
===================================================================
--- trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/resolver-distributed/java/org/mulgara/resolver/distributed/remote/RemotePagerImpl.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -16,9 +16,10 @@
 import java.rmi.*;
 import java.lang.reflect.Array;
 import java.io.Serializable;
-import java.rmi.server.UnicastRemoteObject;
 import java.util.logging.*;
 
+import org.mulgara.util.Rmi;
+
 /**
  * Implements the remote pager by iterating on a list and moving pages of elements over RMI.
  * @param <E> The elements of the paged list.
@@ -64,7 +65,7 @@
     size = collection.size();
     iter = null;
     currentPage = (E[])Array.newInstance(type, pageSize);
-    UnicastRemoteObject.exportObject(this);
+    Rmi.export(this);
   }
 
 

Modified: trunk/src/jar/rules/java/org/mulgara/rules/RulesRefImpl.java
===================================================================
--- trunk/src/jar/rules/java/org/mulgara/rules/RulesRefImpl.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/rules/java/org/mulgara/rules/RulesRefImpl.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -29,8 +29,9 @@
 
 // Java 2 standard packages
 import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
 
+import org.mulgara.util.Rmi;
+
 /**
  * Contains a reference to a local Rules object, while this object can be
  * shipped over RMI.
@@ -43,8 +44,11 @@
  * @copyright &copy; 2005 <a href="mailto:pgearon at users.sourceforge.net">Paul Gearon</a>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class RulesRefImpl extends UnicastRemoteObject implements RulesRef {
+public class RulesRefImpl extends Rmi implements RulesRef {
 
+  /** Generated UID. */
+  private static final long serialVersionUID = 2797292807815290355L;
+
   /** The internal reference to the local object. */
   private Rules rules;
 

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswer.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswer.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/AnswerWrapperRemoteAnswer.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -29,8 +29,6 @@
 
 // Java 2 standard packages
 import java.rmi.*;
-import java.util.*;
-import java.rmi.server.UnicastRemoteObject;
 
 // Third party packages
 import org.apache.log4j.*;
@@ -38,7 +36,7 @@
 import org.mulgara.query.ArrayAnswer;
 import org.mulgara.query.TuplesException;
 import org.mulgara.query.Variable;
-import org.mulgara.util.MulgaraResultSet;
+import org.mulgara.util.Rmi;
 
 /**
  * Remote ITQL answer. An answer is a set of solutions, where a solution is a
@@ -61,11 +59,10 @@
  *
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-public class AnswerWrapperRemoteAnswer extends UnicastRemoteObject implements
-    RemoteAnswer, Cloneable {
+public class AnswerWrapperRemoteAnswer extends Rmi implements RemoteAnswer, Cloneable {
+
   /** logger */
-  private static Logger logger =
-      Logger.getLogger(AnswerWrapperRemoteAnswer.class.getName());
+  private static Logger logger = Logger.getLogger(AnswerWrapperRemoteAnswer.class.getName());
 
   /**
    * Allow newer compiled version of the stub to operate when changes

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionFactoryImpl.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionFactoryImpl.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionFactoryImpl.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -28,10 +28,8 @@
 package org.mulgara.server.rmi;
 
 // Java 2 standard packages
-import java.io.*;
 import java.net.URI;
 import java.rmi.*;
-import java.rmi.server.*;
 import java.util.*;
 
 // Third party packages
@@ -40,73 +38,48 @@
 // Locally written packages
 import org.mulgara.jrdf.*;
 import org.mulgara.query.QueryException;
-import org.mulgara.server.JRDFSession;
-import org.mulgara.server.JenaSession;
 import org.mulgara.server.ServerInfo;
 import org.mulgara.server.Session;
 import org.mulgara.server.SessionFactory;
+import org.mulgara.util.Rmi;
 
 /**
  * RMI wrapper for {@link SessionFactory} implementations.
  *
  * @author <a href="http://staff.pisoftware.com/raboczi">Simon Raboczi</a>
- *
  * @created 2001-07-14
- *
- * @version $Revision: 1.12 $
- *
- * @modified $Date: 2005/06/26 12:48:16 $
- *
- * @maintenanceAuthor $Author: pgearon $
- *
- * @company <A href="mailto:info at PIsoftware.com">Plugged In Software</A>
- *
- * @copyright &copy; 2001-2003 <A href="http://www.PIsoftware.com/">Plugged In
- *      Software Pty Ltd</A>
- *
+ * @copyright &copy; 2001-2003 <A href="http://www.PIsoftware.com/">Plugged In Software Pty Ltd</A>
  * @licence <a href="{@docRoot}/../../LICENCE">Mozilla Public License v1.1</a>
  */
-class RemoteSessionFactoryImpl implements RemoteSessionFactory
-{
-  /**
-   * Logger. This is named after the classname.
-   */
-  private final static Logger logger =
-      Logger.getLogger(RemoteSessionFactoryImpl.class);
+class RemoteSessionFactoryImpl implements RemoteSessionFactory {
 
-  /**
-   * The local database.
-   */
+  /** Logger. This is named after the classname. */
+  @SuppressWarnings("unused")
+  private final static Logger logger = Logger.getLogger(RemoteSessionFactoryImpl.class);
+
+  /** The local database. */
   private SessionFactory sessionFactory;
 
-  /**
-   * The server URI used to create this factory.
-   * Used for reconnection
-   */
+  /** The server URI used to create this factory. Used for reconnection */
   private URI serverURI = null;
 
   /**
    * Set of {@link RemoteSession}s, the local copies of exported stubs. This is
    * necessary to prevent garbage collection.
    */
-  private Set remoteSessionSet = new HashSet();
+  private Set<RemoteSession> remoteSessionSet = new HashSet<RemoteSession>();
 
   /**
    * Constructor to create an RMI database server.
    *
-   * @param sessionFactory PARAMETER TO DO
+   * @param sessionFactory A local factory that this exports access to.
    * @throws IllegalArgumentException if <var>database</var> is <code>null</code>
    * @throws RemoteException if RMI communication fails
    */
-  RemoteSessionFactoryImpl(SessionFactory sessionFactory) throws
-      RemoteException {
-
+  RemoteSessionFactoryImpl(SessionFactory sessionFactory) throws RemoteException {
     // Validate "sessionFactory" parameter
-    if (sessionFactory == null) {
+    if (sessionFactory == null) throw new IllegalArgumentException("Null \"sessionFactory\" parameter");
 
-      throw new IllegalArgumentException("Null \"sessionFactory\" parameter");
-    }
-
     // Initialize fields
     this.sessionFactory = sessionFactory;
   }
@@ -117,29 +90,30 @@
 
   /**
    * {@inheritDoc RemoteSessionFactory}
-   *
-   * @return The SecurityDomain value
-   * @throws QueryException EXCEPTION TO DO
+   * @return The SecurityDomain value.
+   * @throws QueryException Error accessing the domain.
    */
   public URI getSecurityDomain() throws QueryException {
-
     return sessionFactory.getSecurityDomain();
   }
 
+
   /**
    * Get the server URI used to create the current remoteSessionFactory
    */
   public URI getServerURI()  {
-    return this.serverURI;
+    return serverURI;
   }
 
+
   /**
    * Set the server URI used to create the current remoteSessionFactory
    */
-  public void setServerURI( URI serverURI ) {
+  public void setServerURI(URI serverURI) {
     this.serverURI = serverURI;
   }
 
+
   /**
    * Get the default URI used by this server.
    */
@@ -147,60 +121,46 @@
     return ServerInfo.getServerURI();
   }
 
+
   /**
    * {@inheritDoc RemoteSessionFactory}
    *
-   * @return RETURNED VALUE TO DO
-   * @throws QueryException EXCEPTION TO DO
+   * @return A new remotely exported session
+   * @throws QueryException If an error occrred in the network protocol
    */
   public Session newSession() throws QueryException {
     try {
-
       // Create the session
-      RemoteSession remoteSession =
-          new RemoteSessionImpl(sessionFactory.newSession(), this);
+      RemoteSession remoteSession = new RemoteSessionImpl(sessionFactory.newSession(), this);
       remoteSessionSet.add(remoteSession);
 
-      RemoteSession exportedRemoteSession =
-          (RemoteSession) UnicastRemoteObject.exportObject(remoteSession);
+      RemoteSession exportedRemoteSession = (RemoteSession)Rmi.export(remoteSession);
 
       // Apply two wrappers to hide the RemoteExceptions of the
       // RemoteSession interface so everything looks like a Session
-      return new RemoteSessionWrapperSession(exportedRemoteSession,
-                                             this.getServerURI());
-    }
-    catch (RemoteException e) {
-
+      return new RemoteSessionWrapperSession(exportedRemoteSession, getServerURI());
+    } catch (RemoteException e) {
       throw new QueryException("Couldn't export session", e);
     }
   }
 
   /**
    * {@inheritDoc RemoteSessionFactory}
-   *
-   * @return RETURNED VALUE TO DO
-   * @throws QueryException EXCEPTION TO DO
+   * @return A new remotely exported JRDF session
+   * @throws QueryException If an error occrred in the network protocol
    */
   public Session newJRDFSession() throws QueryException {
-
     try {
-
       // Create the session
-      RemoteSession remoteSession =
-          new RemoteJRDFSessionImpl(
-          (LocalJRDFSession) sessionFactory.newJRDFSession(), this);
+      RemoteSession remoteSession = new RemoteJRDFSessionImpl((LocalJRDFSession)sessionFactory.newJRDFSession(), this);
       remoteSessionSet.add(remoteSession);
 
-      RemoteJRDFSession exportedRemoteSession =
-          (RemoteJRDFSession) UnicastRemoteObject.exportObject(remoteSession);
+      RemoteJRDFSession exportedRemoteSession = (RemoteJRDFSession)Rmi.export(remoteSession);
 
       // Apply two wrappers to hide the RemoteExceptions of the
       // RemoteSession interface so everything looks like a Session
-      return new RemoteSessionWrapperJRDFSession(exportedRemoteSession,
-          this.getServerURI());
-    }
-    catch (RemoteException e) {
-
+      return new RemoteSessionWrapperJRDFSession(exportedRemoteSession, getServerURI());
+    } catch (RemoteException e) {
       throw new QueryException("Couldn't export session", e);
     }
   }
@@ -208,19 +168,15 @@
 
   /**
    * {@inheritDoc RemoteSessionFactory}
-  */
+   */
   public RemoteSession newRemoteSession() throws QueryException, RemoteException {
     try {
-
       // Create the session
-      RemoteSession remoteSession =
-          new RemoteSessionImpl(sessionFactory.newSession(), this);
+      RemoteSession remoteSession = new RemoteSessionImpl(sessionFactory.newSession(), this);
       remoteSessionSet.add(remoteSession);
 
-      return (RemoteSession) UnicastRemoteObject.exportObject(remoteSession);
-    }
-    catch (RemoteException e) {
-
+      return (RemoteSession)Rmi.export(remoteSession);
+    } catch (RemoteException e) {
       throw new QueryException("Couldn't export session", e);
     }
   }
@@ -228,19 +184,17 @@
 
   /**
    * {@inheritDoc RemoteSessionFactory}
-   *
-   * @throws QueryException EXCEPTION TO DO
    */
   public void removeSession(RemoteSession session)  {
-
     remoteSessionSet.remove(session);
     try {
-      UnicastRemoteObject.unexportObject(session, true);
+      Rmi.unexportObject(session, true);
     } catch ( NoSuchObjectException ex ) {
-      // do nothing
+      logger.warn("Request to remove an unknown session");
     }
   }
 
+
   /**
    * {@inheritDoc RemoteSessionFactory}
    */

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteXAResourceWrapperXAResource.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteXAResourceWrapperXAResource.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteXAResourceWrapperXAResource.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -20,8 +20,6 @@
 // Java 2 standard packages
 import java.io.Serializable;
 import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
-import java.util.Arrays;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
@@ -41,8 +39,7 @@
  */
 class RemoteXAResourceWrapperXAResource implements XAResource, ResourceManagerInstanceAdaptor {
   /** logger */
-  private static Logger logger =
-      Logger.getLogger(RemoteXAResourceWrapperXAResource.class.getName());
+  private static Logger logger = Logger.getLogger(RemoteXAResourceWrapperXAResource.class.getName());
 
   /**
    * The wrapped instance.
@@ -53,8 +50,7 @@
    * Wrap a {@link RemoteAnswer} to make it into an {@link Answer}.
    *
    * @param remoteAnswer  the instance to wrap
-   * @throws IllegalArgumentException  if <var>remoteAnswer</var> is
-   *   <code>null</code>
+   * @throws IllegalArgumentException  if <var>remoteAnswer</var> is <code>null</code>
    */
   RemoteXAResourceWrapperXAResource(RemoteXAResource remoteResource) throws RemoteException {
     if (remoteResource == null) {
@@ -182,6 +178,9 @@
   }
 
   private static class SerializableXid implements Xid, Serializable {
+    /** Generated UID */
+    private static final long serialVersionUID = 2421196761757350942L;
+
     private byte[] bq;
     private int fi;
     private byte[] gtid;

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -31,7 +31,6 @@
 // Java 2 standard packages
 import java.net.*;
 import java.rmi.*;
-import java.rmi.server.UnicastRemoteObject;
 import javax.naming.*;
 
 // Third party packages
@@ -39,6 +38,7 @@
 
 // Locally written packages
 import org.mulgara.server.AbstractServer;
+import org.mulgara.util.Rmi;
 
 /**
  * Java RMI server.
@@ -171,7 +171,7 @@
 
     // Apply RMI wrapper to the session factory
     remoteSessionFactory = new RemoteSessionFactoryImpl(getSessionFactory());
-    exportedRemoteSessionFactory = (RemoteSessionFactory)UnicastRemoteObject.exportObject(remoteSessionFactory);
+    exportedRemoteSessionFactory = (RemoteSessionFactory)Rmi.export(remoteSessionFactory);
 
     // Bind the service to the RMI registry
     rmiRegistryContext.rebind(name, exportedRemoteSessionFactory);
@@ -185,7 +185,7 @@
   protected void stopService() throws NamingException, NoSuchObjectException {
     try {
       rmiRegistryContext.unbind(name);
-      UnicastRemoteObject.unexportObject(remoteSessionFactory, true);
+      Rmi.unexportObject(remoteSessionFactory, true);
     } catch (Exception e) {
       if (e.getCause() instanceof javax.naming.ServiceUnavailableException) {
         logger.warn("RMI Server no longer available to be stopped. Abandoning.");

Modified: trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/XAResourceWrapperRemoteXAResource.java
===================================================================
--- trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/XAResourceWrapperRemoteXAResource.java	2008-09-23 23:21:08 UTC (rev 1268)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/XAResourceWrapperRemoteXAResource.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -20,7 +20,6 @@
 // Java 2 standard packages
 import java.io.Serializable;
 import java.rmi.RemoteException;
-import java.rmi.server.UnicastRemoteObject;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
@@ -30,6 +29,7 @@
 
 // Local packages
 import org.mulgara.server.ResourceManagerInstanceAdaptor;
+import org.mulgara.util.Rmi;
 
 /**
  * Wraps an XAResource and makes it available as an RMI object.
@@ -38,11 +38,14 @@
  * @author Andrae Muys
  * @licence Apache License v2.0
  */
-public class XAResourceWrapperRemoteXAResource
-    extends UnicastRemoteObject implements RemoteXAResource {
+public class XAResourceWrapperRemoteXAResource extends Rmi implements RemoteXAResource {
+
+  /** Generated UID */
+  private static final long serialVersionUID = 1L;
+
   /** logger */
-  private static Logger logger =
-      Logger.getLogger(XAResourceWrapperRemoteXAResource.class.getName());
+  @SuppressWarnings("unused")
+  private static Logger logger = Logger.getLogger(XAResourceWrapperRemoteXAResource.class.getName());
 
   protected final XAResource resource;
   protected final ResourceManagerInstanceAdaptor adaptor;

Added: trunk/src/jar/util/java/org/mulgara/util/Rmi.java
===================================================================
--- trunk/src/jar/util/java/org/mulgara/util/Rmi.java	                        (rev 0)
+++ trunk/src/jar/util/java/org/mulgara/util/Rmi.java	2008-09-24 18:47:03 UTC (rev 1269)
@@ -0,0 +1,135 @@
+/*
+ * The contents of this file are subject to the Open Software License
+ * Version 3.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.opensource.org/licenses/osl-3.0.txt
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+ * the License for the specific language governing rights and limitations
+ * under the License.
+ */
+
+package org.mulgara.util;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.server.RemoteStub;
+import java.rmi.server.UnicastRemoteObject;
+
+/**
+ * A utility to centralize the port handling for RMI objects.
+ * This class is not set to handle different protocols. If this is needed, then the
+ * super constructor {@link #UnicastRemoteObject(int,RMIClientSocketFactory,RMIServerSocketFactory)}
+ * would need to be overridden.
+ *
+ * @created Sep 23, 2008
+ * @author Paul Gearon
+ * @copyright &copy; 2008 <a href="http://www.topazproject.org/">The Topaz Project</a>
+ * @licence <a href="{@docRoot}/../../LICENCE.txt">Open Software License v3.0</a>
+ */
+public class Rmi extends UnicastRemoteObject {
+
+  /** Generation UID */
+  private static final long serialVersionUID = -8087526398171872888L;
+
+  /** The default port used for exporting objects. */
+  protected static int defaultPort = 0;
+
+  /**
+   * Default constructor. Uses the default port.
+   * @throws RemoteException If the object could not be exported.
+   */
+  protected Rmi() throws RemoteException {
+    super(defaultPort);
+  }
+
+
+  /**
+   * Constructor with a specified port.
+   * @param port A specified port. If 0 then a default port will be used.
+   * @throws RemoteException If the object could not be exported.
+   */
+  protected Rmi(int port) throws RemoteException {
+    super(port == 0 ? defaultPort : port);
+  }
+
+
+  /**
+   * We don't want users using this method, since we cannot control the port, and we cannot
+   * control the return type if a port is specified through another method.
+   * @param obj The object to export.
+   * @return Not implemented.
+   * @throws RemoteException There was an error exporting the object.
+   */
+  public static RemoteStub exportObject(Remote obj) throws RemoteException {
+    throw new UnsupportedOperationException("Use the export() method instead.");
+  }
+
+
+  /**
+   * Exports an object through RMI, using a known port if configured, or a random port otherwise.
+   * This will not create a default exporter if one does not exist.
+   * @param obj The object to export.
+   * @return An exported object.
+   * @throws RemoteException There was an error exporting the object.
+   */
+  public static Remote export(Remote obj) throws RemoteException {
+    if (defaultPort == 0) return UnicastRemoteObject.exportObject(obj);
+    return UnicastRemoteObject.exportObject(obj, defaultPort);
+  }
+
+
+  /**
+   * Unexport an object from RMI.
+   * @param obj The object to unexport.
+   * @return <code>false</code> if the object could not be unexported. This may happen if it is
+   *         still in use.
+   * @throws RemoteException There was an error exporting the object.
+   */
+  public static boolean unexportObject(Remote obj) throws RemoteException {
+    return UnicastRemoteObject.unexportObject(obj, false);
+  }
+
+
+  /**
+   * Sets the port for the default exporter to use. 
+   * @param port The port number to use.
+   */
+  public static void setDefaultPort(int port) {
+    defaultPort = port;
+  }
+
+
+  /**
+   * Gets the port to use. 
+   * @return The port number, or 0 if a random port is to be used.
+   */
+  public static int getDefaultPort() {
+    return defaultPort;
+  }
+
+
+  /**
+   * Unexport this object from RMI.
+   * @return <code>false</code> if the object could not be unexported. This may happen if it is
+   *         still in use.
+   * @throws RemoteException There was an error exporting the object.
+   */
+  public boolean unexport() throws RemoteException {
+    return unexportObject(this);
+  }
+
+
+  /**
+   * Unexport an object from RMI.
+   * @param force If true, then unexport the object, even if it still in use.
+   * @return <code>false</code> if the object could not be unexported. This may happen if
+   *         <var>force</var> is <code>false</code> and <code>obj</code> is still in use.
+   * @throws RemoteException There was an error exporting the object.
+   */
+  public boolean unexport(boolean force) throws RemoteException {
+    return unexportObject(this, force);
+  }
+
+}




More information about the Mulgara-svn mailing list