This discussion is archived
2 Replies Latest reply: Jan 5, 2011 12:19 PM by jtahlborn RSS

[java rmi] PortableRemoteObject with unreferenced method

815614 Newbie
Currently Being Moderated
Hello everyone.

I'm using a portable proxy between a IIOP client and a JRMI login server (activatable). While the proxy has an active reference to the login server it can't run his unreferenced method. So I'm trying to use unreferenced in the proxy too, but once it gets a reference to the login server (the first time an IIOP user calls PortableProxy.login() method), the proxy unreferenced method is never called.

This is my proxy code:
public class PortableProxy extends ClientAuthentication, Unreferenced{
     private String path = System.getenv("WORKDIR");
     private ClientAuthentication authLogin = null;
     private static final String authServer = "authServer";
     private static final int authServerPort = 1098;
     private static final String authServerIP = "localhost";
     private static final int portableProxyRMI = 3500;
     private static final String portableProxy = "PortableProxy";
     /**
        * PortableProxy()
        */
     public PortableProxy(){
          Properties prop = new Properties();
          Object obj = null;
          System.setProperty("javax.net.ssl.trustStore",""+path+"client/mySrvKeystore");
          System.setProperty("javax.net.ssl.trustStorePassword", "123456");
          try{
               PortableRemoteObject.exportObject(this);
                  System.setProperty("java.rmi.dgc.leaseValue", "12000");
                  System.setProperty("java.rmi.dgc.checkInterval", "6000");
          }catch(RemoteException re){
               System.out.println("PortableProxy.PortableProxy() RemoteException: "+re.getMessage());
               re.printStackTrace();
          }
          System.out.println("PortableProxy exported");
     }
     
     /**
        * lookRef()
        */
     public void lookRef(){
          Properties prop = new Properties();
          Object obj = null;
          prop.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
          prop.put(Context.PROVIDER_URL, "rmi://"+authServerIP+":"+authServerPort);
          InitialContext ic = null;
          try{
             ic = new InitialContext(prop);
             obj = ic.lookup(authServer);
          }catch(NamingException ne){
             System.out.println("PortableProxy.lookRef() NamingException: "+ne.getMessage());
             ne.printStackTrace();
          }
          authLogin = (ClientAuthentication) PortableRemoteObject.narrow(obj, ClientAuthentication.class);
   }
     
     /**
        * login()
        */
     public Runnable login(String user, String password){
          System.out.println("Sono in PortableProxy.login()");
          Runnable ret = null;
          if(authLogin == null){
               lookRef();
          }
          try{
               ret = authLogin.login(user, password);
          }catch(RemoteException re){
               System.out.println("PortableProxy.login() RemoteException: "+re.getMessage());
               re.printStackTrace();
          }
          return ret;
     }
     
     /**
        * unreferenced()
        */
     public void unreferenced(){
          authLogin = null;
          if(authLogin == null){
               System.out.println("authLogin = null");
          }else{
               System.out.println("Something went wrong: authLogin != null.");
          }
          System.gc();
     }

     /**
     * MAIN
     */
     public static void main(String[] args){
          Properties prop = new Properties();
          PortableProxy proxy = new PortableProxy();
          prop.put("java.naming.factory.initial",  "com.sun.jndi.cosnaming.CNCtxFactory");
          prop.put("java.naming.provider.url", "iiop://localhost:"+portableProxyRMI);
          try{
               InitialContext icProxy = new InitialContext(prop);
               icProxy.rebind(portableProxy, proxy);
          }catch(NamingException ne){
               System.out.println("PortableProxy.main() NamingException: "+ne.getMessage());
               ne.printStackTrace();
          }
     }
}
I closed all user jvm, but nothing happened. Everytime I don't need anymore a reference to the proxy, I set it to null.
Where I'm doing wrong?
ps: I'd also like to set the leaseValue and checkInterval to a shorter time. Is that way (under the PortableRemoteObject.exportObject()) the right way?
Thanks in advance, if you need some additional information tell me. Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points