RMI, Exporter and Runnable

O

Olivier Ricou

Hi,

I don't understand why I cannot make a stub (proxy) of a class
which inherite from a Interface which extends Runnable.

It surprise me even more because I can make a stub of a class
which implements directly Runnable and of course the Interface
(move the Runnable from Plouf to PloufServer and it works...).

Here is an exemple which gives (java 1.4, Sun and IBM) :

java.rmi.server.ExportException: cannot get proxy interfaces; nested
exception is:
java.lang.IllegalArgumentException: illegal remote method encountered:
public abstract void java.lang.Runnable.run()

Best regards,

Olivier.

-------------------------
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Plouf extends Remote, Runnable
{
public String plouf(int n) throws RemoteException;
}

--------------------------

import java.rmi.*;

import net.jini.jeri.BasicILFactory;
import net.jini.jeri.BasicJeriExporter;
import net.jini.jeri.tcp.TcpServerEndpoint;

import net.jini.config.*;
import net.jini.export.*;

public class PloufServer implements Plouf
{
static String[] configArgs = new String[] {"jeri.config"};

public void run()
{
try
{
Exporter exporter =
new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
new BasicILFactory());
Remote stub = exporter.export(this);
}
catch (Exception e){System.out.println(e);}
}

public String plouf(int n) throws RemoteException
{ return new String("Plouf"); }

public static void main(String[] args)
{
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try {
PloufServer f = new PloufServer();
Thread ft = new Thread(f);
ft.start();
System.out.println("Plouf Server ready.");
}
catch (Exception e) { System.out.println(e); }
}
}


---------------

the full run :
java -Djava.rmi.server.codebase="http://localhost/" \
-Djava.security.policy=./no.security -classpath \
/usr/share/jini/lib/jini-core.jar:.:/usr/share/jini/lib/jini-ext.jar \
PloufServer
Plouf Server ready.
java.rmi.server.ExportException: cannot get proxy interfaces; nested
exception is:
java.lang.IllegalArgumentException: illegal remote method encountered:
public abstract void java.lang.Runnable.run()
 
E

EJP

Any methods exported by a remote interface must be declared to throw
RemoteException. Runnable.run() doesn't.

EJP

Olivier said:
Hi,

I don't understand why I cannot make a stub (proxy) of a class
which inherite from a Interface which extends Runnable.

It surprise me even more because I can make a stub of a class
which implements directly Runnable and of course the Interface
(move the Runnable from Plouf to PloufServer and it works...).

Here is an exemple which gives (java 1.4, Sun and IBM) :

java.rmi.server.ExportException: cannot get proxy interfaces; nested
exception is:
java.lang.IllegalArgumentException: illegal remote method encountered:
public abstract void java.lang.Runnable.run()

Best regards,

Olivier.

-------------------------
import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Plouf extends Remote, Runnable
{
public String plouf(int n) throws RemoteException;
}

--------------------------

import java.rmi.*;

import net.jini.jeri.BasicILFactory;
import net.jini.jeri.BasicJeriExporter;
import net.jini.jeri.tcp.TcpServerEndpoint;

import net.jini.config.*;
import net.jini.export.*;

public class PloufServer implements Plouf
{
static String[] configArgs = new String[] {"jeri.config"};

public void run()
{
try
{
Exporter exporter =
new BasicJeriExporter(TcpServerEndpoint.getInstance(0),
new BasicILFactory());
Remote stub = exporter.export(this);
}
catch (Exception e){System.out.println(e);}
}

public String plouf(int n) throws RemoteException
{ return new String("Plouf"); }

public static void main(String[] args)
{
if (System.getSecurityManager() == null)
System.setSecurityManager(new RMISecurityManager());
try {
PloufServer f = new PloufServer();
Thread ft = new Thread(f);
ft.start();
System.out.println("Plouf Server ready.");
}
catch (Exception e) { System.out.println(e); }
}
}

---------------

the full run :
java -Djava.rmi.server.codebase="http://localhost/" \
-Djava.security.policy=./no.security -classpath \
/usr/share/jini/lib/jini-core.jar:.:/usr/share/jini/lib/jini-ext.jar \
PloufServer
Plouf Server ready.
java.rmi.server.ExportException: cannot get proxy interfaces; nested
exception is:
java.lang.IllegalArgumentException: illegal remote method encountered:
public abstract void java.lang.Runnable.run()
 
O

Olivier Ricou

Any methods exported by a remote interface must be declared to throw
RemoteException. Runnable.run() doesn't.

which means I have no way to grab an object from a Jini Lookup service
(reggi) knowing only its Interface and run it in a thread to start a
RMI service ?

Olivier.
 
E

EJP

Olivier said:
which means I have no way to grab an object from a Jini Lookup service
(reggi) knowing only its Interface and run it in a thread to start a
RMI service ?

You can only export an object as an RMI remote object if it implements a
remote interface, i.e. an interface which extends Remote and which
satisifes the RMI semantics of every method throwing RemoteException.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top