S
Screamin Lord Byron
Hello,
I am learning RMI and I ran into this difficulty.
Let's say we have:
import java.rmi.*;
public interface Foo extends Remote {
public Bar constructBar(String name);
// other stuff
}
public interface Bar extends Remote {
public void mutate();
}
---------
import java.rmi.*;
import java.rmi.server.*;
public class BarImpl extends UnicastRemoteObject
implements Bar {
String name;
public BarImpl(String name) throws RemoteException {
this.name = name;
}
public void mutate() throws RemoteException {
name = "some new name";
}
}
---------
import...
public class FooImpl extends UnicastRemoteObject
implements Foo {
public FooImpl() throws RemoteException {
// some init
}
public Bar constructBar(String name) throws RemoteException {
return new BarImpl(name);
}
// other stuff
}
----------
Now I have some server and rmi initialization in the main class
----------
import...
public class Server {
public static void main(String[] args) {
// Construct Foo implementation, no problem
FooImpl myFoo = new FooImpl();
// Construct Bar Implementation
BarImpl myBar = new BarImpl(// oops, don't have the name,
// the client has it
);
// So I can bind Foo,
new InitialContext().bind("rmi:my_foo", myFoo);
// But can't bind Bar
}
}
I don't even know how many Bars there will be, and I can't just
serialize Bar and transfer a copy to the client, because I need all Bars
to be remote.
However, if I try to bind in constructBar() method of the Foo class I
get something like this on the client:
java.lang.IllegalArgumentException: illegal remote method encountered:
public abstract void Bar.mutate()
I suppose it's because there is no Bar in the RMI registry yet.
What can I do? I'm sorry if I'm asking nonsense, but how to make a stub
object for this Bar class? Am I doing it completely the wrong way?
I have no problem invoking methods of remote objects instantiated by the
server. That is to say -- if I remove this Bar business, everything else
runs as expected.
I've just started with RMI so (obviously) I don't know anything about it
yet. Can you please tell me is maybe Remote Object Activation right way
to look?
Thanks!
I am learning RMI and I ran into this difficulty.
Let's say we have:
import java.rmi.*;
public interface Foo extends Remote {
public Bar constructBar(String name);
// other stuff
}
public interface Bar extends Remote {
public void mutate();
}
---------
import java.rmi.*;
import java.rmi.server.*;
public class BarImpl extends UnicastRemoteObject
implements Bar {
String name;
public BarImpl(String name) throws RemoteException {
this.name = name;
}
public void mutate() throws RemoteException {
name = "some new name";
}
}
---------
import...
public class FooImpl extends UnicastRemoteObject
implements Foo {
public FooImpl() throws RemoteException {
// some init
}
public Bar constructBar(String name) throws RemoteException {
return new BarImpl(name);
}
// other stuff
}
----------
Now I have some server and rmi initialization in the main class
----------
import...
public class Server {
public static void main(String[] args) {
// Construct Foo implementation, no problem
FooImpl myFoo = new FooImpl();
// Construct Bar Implementation
BarImpl myBar = new BarImpl(// oops, don't have the name,
// the client has it
);
// So I can bind Foo,
new InitialContext().bind("rmi:my_foo", myFoo);
// But can't bind Bar
}
}
I don't even know how many Bars there will be, and I can't just
serialize Bar and transfer a copy to the client, because I need all Bars
to be remote.
However, if I try to bind in constructBar() method of the Foo class I
get something like this on the client:
java.lang.IllegalArgumentException: illegal remote method encountered:
public abstract void Bar.mutate()
I suppose it's because there is no Bar in the RMI registry yet.
What can I do? I'm sorry if I'm asking nonsense, but how to make a stub
object for this Bar class? Am I doing it completely the wrong way?
I have no problem invoking methods of remote objects instantiated by the
server. That is to say -- if I remove this Bar business, everything else
runs as expected.
I've just started with RMI so (obviously) I don't know anything about it
yet. Can you please tell me is maybe Remote Object Activation right way
to look?
Thanks!