Catching java.rmi.UnmarshalException: invalid method hash for backwards compatability
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   simomon
Posted On:   Wednesday, November 28, 2012 07:00 PM

I am working on a very large and older software system, which uses java rmi at its core. I have just started digging into the core and we are trying to add some new methods to old classes,  We need to add a backwards compatibility check to make sure that the servers that we are attempting to run the code against have the new methods in them. as an example consider the following server interface where we add one new method public interface  VersionChecker extends Remotef{               public boolean checkVersion(String versionString) throws RemoteException; <--- OLD        public b   More>>

I am working on a very large and older software system, which uses java rmi at its core.

I have just started digging into the core and we are trying to add some new methods to old classes, 

We need to add a backwards compatibility check to make sure that the servers that we are attempting to run the code against have the new methods in them.

as an example consider the following server interface where we add one new method

public interface  VersionChecker extends Remotef{

      
       public boolean checkVersion(String versionString) throws RemoteException; <--- OLD

       public boolean checkVersion(String  versionString ,int versionNumber) throws RemoteException ; <--- NEW 


}


Now on the client side we do something like 

VersionChecker versionChecker = (VersionCheckerIntf) Naming.lookup("ip and port");

which works fine...

We then have added a backwards comparability check ( this might be  dumb/ignorant ) 
- try running the new method
- if you get a specific type of exception try the old

boolean isVersionOk = false;

try
{
            isVersionOk  = versionChecker .checkVerison("aVersionString",1231231);   <-- try the new method
}
catch(UnmarshalException exp) <- catch the unmarhsall exception 
{
     if(cause.conatins("invalid method hash) <-- check to see that the cause was a invalid method hash
     {
              isVersionOk  = versionChecker .checkVerison("aVersionString");   <--  use the old version
      }     
     else 
        throw exp;

}


The problem is that we are getting inconsistent results  , in that most of the time this works but then we occasionaly get a socket exception.

I.e the socket has been closed before the second call to the old method ??

My basic questions are 

Is this a really dumb way to do this ?

Is RMI  set up to close the socket if it gets an invalid method hash exception on the class ( or is this a bug ) ?

Is the only reason why this is working is because we got lucky ?


thanks in advance for any advice :)


   <<Less
About | Sitemap | Contact