[Mulgara-svn] r1911 - trunk/src/jar/server-rmi/java/org/mulgara/server/rmi

alexhall at mulgara.org alexhall at mulgara.org
Fri Feb 5 20:49:05 UTC 2010


Author: alexhall
Date: 2010-02-05 12:49:04 -0800 (Fri, 05 Feb 2010)
New Revision: 1911

Modified:
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionFactoryImpl.java
   trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java
Log:
Add logic to the RMI server and session factory to enable interruptible RMI operations when exporting remote sessions, if the application is configured to enable this behavior.

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	2010-02-05 20:47:54 UTC (rev 1910)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RemoteSessionFactoryImpl.java	2010-02-05 20:49:04 UTC (rev 1911)
@@ -57,7 +57,10 @@
   private final static Logger logger = Logger.getLogger(RemoteSessionFactoryImpl.class);
 
   /** The local database. */
-  private SessionFactory sessionFactory;
+  private final SessionFactory sessionFactory;
+  
+  /** Flag to control whether to support interruptible RMI operations on exported sessions. */
+  private final boolean interruptible;
 
   /** The server URI used to create this factory. Used for reconnection */
   private URI serverURI = null;
@@ -75,12 +78,13 @@
    * @throws IllegalArgumentException if <var>database</var> is <code>null</code>
    * @throws RemoteException if RMI communication fails
    */
-  RemoteSessionFactoryImpl(SessionFactory sessionFactory) throws RemoteException {
+  RemoteSessionFactoryImpl(SessionFactory sessionFactory, boolean interruptible) throws RemoteException {
     // Validate "sessionFactory" parameter
     if (sessionFactory == null) throw new IllegalArgumentException("Null \"sessionFactory\" parameter");
 
     // Initialize fields
     this.sessionFactory = sessionFactory;
+    this.interruptible = interruptible;
   }
 
   //
@@ -133,7 +137,7 @@
       RemoteSession remoteSession = new RemoteSessionImpl(sessionFactory.newSession(), this);
       remoteSessionSet.add(remoteSession);
 
-      RemoteSession exportedRemoteSession = (RemoteSession)Rmi.export(remoteSession);
+      RemoteSession exportedRemoteSession = (RemoteSession)Rmi.export(remoteSession, interruptible);
 
       // Apply two wrappers to hide the RemoteExceptions of the
       // RemoteSession interface so everything looks like a Session
@@ -154,7 +158,7 @@
       RemoteSession remoteSession = new RemoteJRDFSessionImpl((LocalJRDFSession)sessionFactory.newJRDFSession(), this);
       remoteSessionSet.add(remoteSession);
 
-      RemoteJRDFSession exportedRemoteSession = (RemoteJRDFSession)Rmi.export(remoteSession);
+      RemoteJRDFSession exportedRemoteSession = (RemoteJRDFSession)Rmi.export(remoteSession, interruptible);
 
       // Apply two wrappers to hide the RemoteExceptions of the
       // RemoteSession interface so everything looks like a Session
@@ -174,7 +178,7 @@
       RemoteSession remoteSession = new RemoteSessionImpl(sessionFactory.newSession(), this);
       remoteSessionSet.add(remoteSession);
 
-      return (RemoteSession)Rmi.export(remoteSession);
+      return (RemoteSession)Rmi.export(remoteSession, interruptible);
     } catch (RemoteException e) {
       throw new QueryException("Couldn't export session", e);
     }

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	2010-02-05 20:47:54 UTC (rev 1910)
+++ trunk/src/jar/server-rmi/java/org/mulgara/server/rmi/RmiServer.java	2010-02-05 20:49:04 UTC (rev 1911)
@@ -29,14 +29,18 @@
 
 
 // Java 2 standard packages
-import java.net.*;
-import java.rmi.*;
-import javax.naming.*;
+import java.net.InetAddress;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.RemoteException;
 
-// Third party packages
-import org.apache.log4j.*;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
 
-// Locally written packages
+import org.apache.log4j.Logger;
+import org.mulgara.config.MulgaraConfig;
 import org.mulgara.server.AbstractServer;
 import org.mulgara.util.Rmi;
 
@@ -69,7 +73,7 @@
 
   /** The default port used for RMI. */
   public static final int DEFAULT_PORT = 1099;
-
+  
   /** The Java RMI registry naming context. */
   private Context rmiRegistryContext;
 
@@ -155,6 +159,15 @@
   // Methods implementing AbstractServer
   //
 
+  /* (non-Javadoc)
+   * @see org.mulgara.server.AbstractServer#setConfig(org.mulgara.config.MulgaraConfig)
+   */
+  @Override
+  public void setConfig(MulgaraConfig config) {
+    super.setConfig(config);
+    Rmi.configure(config);
+  }
+
   /**
    * Start the server.
    * @throws IllegalStateException if <var>name</var> is <code>null</code>
@@ -169,8 +182,7 @@
     // Initialize fields
     rmiRegistryContext = new InitialContext();
 
-    // Apply RMI wrapper to the session factory
-    remoteSessionFactory = new RemoteSessionFactoryImpl(getSessionFactory());
+    remoteSessionFactory = new RemoteSessionFactoryImpl(getSessionFactory(), Rmi.getDefaultInterrupt());
     exportedRemoteSessionFactory = (RemoteSessionFactory)Rmi.export(remoteSessionFactory);
 
     // Bind the service to the RMI registry




More information about the Mulgara-svn mailing list