0



i'm developing two via RMI connected apps. Communication is bidirectional and everything works just fine, until i'm running on windows. when i take jar files to Debian, connection fails with java.rmi.NoSuchObjectException.

Any idea what difference linux makes or why isn't it working ?

EDIT: my code:
Server side:

static Registrator clientRegistrator = null; // static field, interface extending java.rmi.Remote
...
Registry rmiRegistry = LocateRegistry.createRegistry(RmiConstants.RMI_REGISTRY_PORT);
clientRegistrator = (Registrator) UnicastRemoteObject.exportObject(new RmiClientRegistrator(networkListeners), RmiConstants.RMI_REGISTRY_PORT); // RmiClientRegistrator implements Registrator interface
rmiRegistry.bind(RmiConstants.RMI_SERVER_MARK, clientRegistrator);


Client side:

static Registrator serverRegistrator = null;
String rmiConnectionString = "rmi://localhost:" + RmiConstants.RMI_REGISTRY_PORT + "/" + RmiConstants.RMI_SERVER_MARK;
serverRegistrator = (Registrator) Naming.lookup(rmiConnectionString);
serverRegistrator.registerClient(dataReceiver); // fails here, with mentioned exception
Kousalik
  • 2,997
  • 3
  • 19
  • 39

2 Answers2

2

The remote object referred to by your stub no longer exists. More accurately, it is no longer exported. This shouldn't happen while a client still has a live stub to it, unless you unexported it yourself, or unless a network partition caused a DGC failure.

The surest remedy against this is to keep a static reference to the remote object in the JVM it was exported from.

user207421
  • 289,834
  • 37
  • 266
  • 440
  • the reference exists, I start one app, immediatly second app, both on localhost. I may try to make the reference static, but I'm afraid, nonexisting reference isn't the problem – Kousalik Jan 25 '13 at 07:53
  • now I'm looking, it has been static reference all the time. lookup finds the reference, but when I immediately call a method on it, it fails. – Kousalik Jan 25 '13 at 09:23
  • @Kousalik Is it a reference to the remote object as created by new(), or is it a reference to the stub as returned by exportObject()? And are you using a separate Registry or an in-process Registry? And if the latter, are you holding a static reference to that? As returned by LocateRegistry().createRegistry()? – user207421 Jan 25 '13 at 09:27
  • its reference returned by exportObject method. I've updated the question with my code – Kousalik Jan 25 '13 at 09:32
  • 1
    @Kousalik As I said above, that's a stub. You need to store a static reference to the object itself as returned by new(). And also to the Registry as above. – user207421 Jan 25 '13 at 09:35
  • Perfect, I thought that the original reference is encapsulated in stub reference. I also don't get, why windows JVM behaves differently. But I think it doesn't matter now. Thank you – Kousalik Jan 25 '13 at 10:23
  • @Kousalik If the original object was encapsulated in the stub, what would the stub be for? The stub communicates with the remote object *via the network.* That's how RMI works. – user207421 Jan 25 '13 at 11:09
  • I think the main issue is why it works on windows and not on Linux ... i have the same issue. upvote as assigning the instance created by new and then exporting that fixes the problem. – Peter Jamieson Jul 12 '13 at 09:05
-1

Did you see here:

java.rmi.NoSuchObjectException: no such object in table

Java RMI NoSuchObjectException

and here:

A NoSuchObjectException is thrown if an attempt is made to invoke a method on an object that no longer exists in the remote virtual machine. If a NoSuchObjectException occurs attempting to invoke a method on a remote object, the call may be retransmitted and still preserve RMI's "at most once" call semantics. A NoSuchObjectException is also thrown by the method java.rmi.server.RemoteObject.toStub and by the unexportObject methods of java.rmi.server.UnicastRemoteObject and java.rmi.activation.Activatable and

Community
  • 1
  • 1
Azodious
  • 13,385
  • 1
  • 32
  • 68
  • yes, I did, but I don't see, how it is related. My apps are working well on Windows. Problem is when running on Linux. Both are running Oracle JVM – Kousalik Jan 24 '13 at 13:01