This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Patch for RMI
- From: Norbert Frese <postfach at nfrese dot net>
- To: java at gcc dot gnu dot org
- Date: Sat, 03 Jan 2004 16:42:23 +0100
- Subject: Patch for RMI
I have found a little problem in the libgcj rmi-classes. When you export
an object via rmi and you specify a distinct port and this port is
already occupied, libgcj just chooses another port without warning you.
This - for instance - is problematic when creating a rmi-registry on an
already used port (a rmi-registry has to use distinct ports).
As far i have investigated sun-rmi it always throws a
java.rmi.server.ExportException when it cannot 'bind' to a certain port.
A testcase is attached.
Norbert
Patch:
Index: gcc/libjava/gnu/java/rmi/server/UnicastConnectionManager.java
===================================================================
RCS file:
/cvs/gcc/gcc/libjava/gnu/java/rmi/server/UnicastConnectionManager.java,v
retrieving revision 1.5
diff -r1.5 UnicastConnectionManager.java
176c176,177
< private UnicastConnectionManager(int port, RMIServerSocketFactory ssf)
{
---
> private UnicastConnectionManager(int port, RMIServerSocketFactory ssf)
throws RemoteException {
>
181,189c182,185
< catch (IOException _) {
< try {
< ssock = ssf.createServerSocket(0);
< serverPort = ssock.getLocalPort();
< }
< catch (IOException __) {
< ssock = null;
< serverPort = 0;
< }
---
> catch (IOException ioex) {
> ssock = null;
> serverPort = 0;
> throw new java.rmi.server.ExportException("can not create Server
Socket on port " + port,ioex);
233c229
< public static synchronized UnicastConnectionManager getInstance(int
port, RMIServerSocketFactory ssf) {
---
> public static synchronized UnicastConnectionManager getInstance(int
port, RMIServerSocketFactory ssf) throws RemoteException {
Index: gcc/libjava/gnu/java/rmi/server/UnicastServerRef.java
===================================================================
RCS file:
/cvs/gcc/gcc/libjava/gnu/java/rmi/server/UnicastServerRef.java,v
retrieving revision 1.7
diff -r1.7 UnicastServerRef.java
88c88
< public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory
ssf) {
---
> public UnicastServerRef(ObjID id, int port, RMIServerSocketFactory
ssf) throws RemoteException {
/*
* Created on Jan 3, 2004
*
*/
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.net.*;
/**
* @author Norbert Frese
*
* compile with:
* javac DistinctRMIExportTest.java
* rmic DistinctRMIExportTest
*
* tests:
* java DistinctRMIExportTest
* gij DistinctRMIExportTest
*
*
*/
public class DistinctRMIExportTest extends UnicastRemoteObject implements Remote {
protected DistinctRMIExportTest() throws RemoteException {
super();
}
protected DistinctRMIExportTest(int port) throws RemoteException {
super(port);
}
public static void main(String[] args) throws Exception {
ServerSocket servsock = new ServerSocket(9999);
DistinctRMIExportTest o1 = new DistinctRMIExportTest(9999); // should throw an Exception
}
}