User: starksm
Date: 01/05/30 09:09:00
Modified: src/main/org/jnp/server Tag: Branch_2_2 Main.java
MainMBean.java
Log:
Add support for externalization of the RMI client and server socket factories
Revision Changes Path
No revision
No revision
1.5.2.2 +60 -14 jnp/src/main/org/jnp/server/Main.java
Index: Main.java
===================================================================
RCS file: /cvsroot/jboss/jnp/src/main/org/jnp/server/Main.java,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -r1.5.2.1 -r1.5.2.2
--- Main.java 2001/05/24 16:24:04 1.5.2.1
+++ Main.java 2001/05/30 16:09:00 1.5.2.2
@@ -16,6 +16,8 @@
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.MarshalledObject;
+import java.rmi.server.RMIClientSocketFactory;
+import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject;
import java.util.Properties;
@@ -33,7 +35,7 @@
@author oberg
@author [EMAIL PROTECTED]
-@version $Revision: 1.5.2.1 $
+@version $Revision: 1.5.2.2 $
*/
public class Main
implements Runnable, MainMBean
@@ -41,13 +43,26 @@
// Constants -----------------------------------------------------
// Attributes ----------------------------------------------------
- NamingServer theServer;
- MarshalledObject serverStub;
- ServerSocket serverSocket;
-
- int port = 1099;
- int rmiPort = 0; // Anonymous
- Category log;
+ /** The Naming interface server implementation */
+ protected NamingServer theServer;
+ protected MarshalledObject serverStub;
+ /** The jnp server socket through which the NamingServer stub is vended */
+ protected ServerSocket serverSocket;
+ /** An optional custom client socket factory */
+ protected RMIClientSocketFactory clientSocketFactory;
+ /** An optional custom server socket factory */
+ protected RMIServerSocketFactory serverSocketFactory;
+ /** The class name of the optional custom client socket factory */
+ protected String clientSocketFactoryName;
+ /** The class name of the optional custom server socket factory */
+ protected String serverSocketFactoryName;
+ /** The jnp protocol listening port. The default is 1099, the same as
+ the RMI registry default port. */
+ protected int port = 1099;
+ /** The RMI port on which the Naming implementation will be exported. The
+ default is 0 which means use any available port. */
+ protected int rmiPort = 0;
+ protected Category log;
// Static --------------------------------------------------------
public static void main(String[] args)
@@ -78,7 +93,7 @@
// Set configuration from the system properties
setPort(Integer.getInteger("jnp.port",getPort()).intValue());
setRmiPort(Integer.getInteger("jnp.rmiPort",getRmiPort()).intValue());
- //log = Category.getInstance("Naming");
+ log = Category.getInstance("Naming");
}
// Public --------------------------------------------------------
@@ -88,6 +103,32 @@
public void setPort(int p) { port = p; }
public int getPort() { return port; }
+ public String getClientSocketFactory()
+ {
+ return serverSocketFactoryName;
+ }
+ public void setClientSocketFactory(String factoryClassName)
+ throws ClassNotFoundException, InstantiationException,
IllegalAccessException
+ {
+ this.clientSocketFactoryName = factoryClassName;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class clazz = loader.loadClass(clientSocketFactoryName);
+ clientSocketFactory = (RMIClientSocketFactory) clazz.newInstance();
+ }
+
+ public String getServerSocketFactory()
+ {
+ return serverSocketFactoryName;
+ }
+ public void setServerSocketFactory(String factoryClassName)
+ throws ClassNotFoundException, InstantiationException,
IllegalAccessException
+ {
+ this.serverSocketFactoryName = factoryClassName;
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class clazz = loader.loadClass(serverSocketFactoryName);
+ serverSocketFactory = (RMIServerSocketFactory) clazz.newInstance();
+ }
+
public void start()
throws Exception
{
@@ -99,18 +140,24 @@
NamingContext.setLocal(theServer);
// Export server
- serverStub = new
MarshalledObject(UnicastRemoteObject.exportObject(theServer, rmiPort));
+ Remote stub = UnicastRemoteObject.exportObject(theServer, rmiPort,
clientSocketFactory, serverSocketFactory);
+ serverStub = new MarshalledObject(stub);
// Start listener
try
{
serverSocket = null;
- serverSocket = new ServerSocket(getPort());
- System.out.println("Started jnpPort=" + getPort()+",
rmiPort="+getRmiPort());
+ serverSocket = new ServerSocket(port);
+ // If an anonymous port was specified get the actual port used
+ if( port == 0 )
+ port = serverSocket.getLocalPort();
+ String msg = "Started jnpPort=" + port +", rmiPort=" + rmiPort
+ + ", Client SocketFactory="+clientSocketFactory+", Server
SocketFactory="+serverSocketFactory;
+ System.out.println(msg);
listen();
} catch (IOException e)
{
- System.err.println("Could not start on port " + getPort());
+ System.err.println("Could not start on port " + port);
e.printStackTrace();
}
}
@@ -148,8 +195,7 @@
} catch (IOException e)
{
if (serverSocket == null) return; // Stopped by normal means
- System.err.println("Naming stopped");
- e.printStackTrace();
+ log.error("Naming stopped", e);
System.out.println("Restarting naming");
try
{
1.3.2.1 +11 -6 jnp/src/main/org/jnp/server/MainMBean.java
Index: MainMBean.java
===================================================================
RCS file: /cvsroot/jboss/jnp/src/main/org/jnp/server/MainMBean.java,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -r1.3 -r1.3.2.1
--- MainMBean.java 2001/04/23 06:08:06 1.3
+++ MainMBean.java 2001/05/30 16:09:00 1.3.2.1
@@ -7,13 +7,11 @@
*/
package org.jnp.server;
-/**
- * <description>
+/** The Mbean interface for the jnp provider server.
*
- * @see <related>
- * @author $Author: starksm $
+ * @author oberg
* @author [EMAIL PROTECTED]
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.3.2.1 $
*/
public interface MainMBean
{
@@ -26,8 +24,15 @@
public void setPort(int p);
public int getPort();
+ public String getClientSocketFactory();
+ public void setClientSocketFactory(String factoryClassName)
+ throws ClassNotFoundException, InstantiationException,
IllegalAccessException;
+ public String getServerSocketFactory();
+ public void setServerSocketFactory(String factoryClassName)
+ throws ClassNotFoundException, InstantiationException,
IllegalAccessException;
+
public void start()
throws Exception;
public void stop();
-}
\ No newline at end of file
+}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development