Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FBNS: RMI Exception

 
ehab emara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
i want the client to know if there was an RMI exception fired on the server side...so i hade to change the signature of the methods at the server to return a certain value and check for this value at the client part...
my question is there any way that i can propagate this exception back to the client instead of checking the return value each time at the client side...
thanks in advance
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Intercept the Remote object client side wrapping it in an object that presents a transport agnostic interface, this will extract the RemoteExceptions and Chain them inside a high level exception for your database / business / server layer (depending on design).

My approach FWIW
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ehab emara:
Dear All,
i want the client to know if there was an RMI exception fired on the server side...so i hade to change the signature of the methods at the server to return a certain value and check for this value at the client part...
my question is there any way that i can propagate this exception back to the client instead of checking the return value each time at the client side...
thanks in advance


The best way is to return a String, describing failure, or null to describe success. If all else fails, it's possible to return the exception object with the appropriate message, or null, if successful. But the best thing is to keep things as simple as possible. I am going with the Strings and null.
[ August 26, 2004: Message edited by: Anton Golovin ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ehab,

I am a little confused at what you are trying to do here. Perhaps you could provide a little more information for me?

Normally if the server receives an RMI Exception, then the exception is designed to be something the server should either handle or accept that communications are now impossible.
  • If the server has handled the exception, then why should the client find out about it?
  • If communication cannot be restored, you cannot pass anything to the client, so the question is irrelevant.


  • Perhaps if you gave an example of what sort of RMI exception you want the server to pass back to the client?

    Regards, Andrew
     
    ehab emara
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hello Andrew
    the issue is that i need the client to know if there was an exception in the server side or not(just simply displaying an error message)fo ana example...
    if the server cann't start and an exception was thrown at the server part...hoe the client will be notified that there was an exception or somthing wrong...
     
    Andrew Monkhouse
    author and jackaroo
    Marshal Commander
    Pie
    Posts: 12014
    220
    C++ Firefox Browser IntelliJ IDE Java Mac Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Ehab,

    If the server cannot start, then the client cannot connect to it, so this should not be an issue.

    However if you want a non RMI exception to be sent to clients after they have connected, you just declare it in the method signature the client will call. For example, you might have a read() method that the client will call defined as:Then if the RecordNotFoundException is thrown by your application, it will be sent to the client which called the read() method. All handled by RMI.

    Now if you wanted to have all connected clients notified of any critical error on the server, then you would have to make the clients Observers of the server. This is beyond the requirements of this assignment, but is not difficult to do. If you would like to read up on this, take a look at JGuru's article on Remote Method Invocation (RMI) particularly the section on RMIClientSideCallbacks.

    Regards, Andrew
     
    Marlene Miller
    Ranch Hand
    Posts: 1392
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ehab, Is this the situation you are thinking about?

    The server is up. The client invokes Naming.lookup() and gets a reference to the remote object stub.

    The client doesn�t know it, but for some reason the server disconnects. Now the client invokes a remote method. Since the server and the connection are down, the method throws a RemoteException.

    How does the client get the RemoteException if the server and the connection are down?

    When the client invokes some remote method, the RMI layer on the client side tries to send a message to the RMI layer on the server side. But the connection is down. So the RMI layer on the _client_ side throws a RemoteException to the stub object and the stub object throws a RemoteException to the client object that invoked the remote method.

    ----

    When I tested this scenario, I got the trace

    My client called the method m(). The stub for the remote object called the rmi transport layer. The RMI layer threw a ConnectException, which is a subclass of RemoteException.

    The client invoked the method twice. In between calls I stopped the server. I was surprised to see in the trace that the client establishes a new connection. Each remote call establishes a new connection?
    [ August 27, 2004: Message edited by: Marlene Miller ]
     
    ehab emara
    Greenhorn
    Posts: 8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    i would like to thank u all for clearing some points for me..and i guess now i know what shall i do...
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic