mx4j/src/core/mx4j/remote/resolver/rmi RMIResolver.java,1.10,1.11

Simone Bordet <[email protected]>
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/core/mx4j/remote/resolver/rmi
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29952/src/core/mx4j/remote/resolver/rmi

Modified Files:
	RMIResolver.java 
Log Message:
Refactored along with the implementation of destroyServer()

Index: RMIResolver.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/core/mx4j/remote/resolver/rmi/RMIResolver.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** RMIResolver.java	18 Sep 2003 18:45:25 -0000	1.10
--- RMIResolver.java	18 Jul 2004 21:33:13 -0000	1.11
***************
*** 9,24 ****
  package mx4j.remote.resolver.rmi;
  
- import java.io.IOException;
- import java.io.ByteArrayOutputStream;
- import java.io.ObjectOutputStream;
  import java.io.ByteArrayInputStream;
  import java.io.ObjectInputStream;
  import java.net.MalformedURLException;
  import java.rmi.server.RMIClientSocketFactory;
  import java.rmi.server.RMIServerSocketFactory;
- import java.rmi.Remote;
  import java.util.Hashtable;
  import java.util.Map;
- 
  import javax.management.remote.JMXServiceURL;
  import javax.management.remote.rmi.RMIConnectorServer;
--- 9,23 ----
  package mx4j.remote.resolver.rmi;
  
  import java.io.ByteArrayInputStream;
+ import java.io.ByteArrayOutputStream;
+ import java.io.IOException;
  import java.io.ObjectInputStream;
+ import java.io.ObjectOutputStream;
  import java.net.MalformedURLException;
+ import java.rmi.Remote;
  import java.rmi.server.RMIClientSocketFactory;
  import java.rmi.server.RMIServerSocketFactory;
  import java.util.Hashtable;
  import java.util.Map;
  import javax.management.remote.JMXServiceURL;
  import javax.management.remote.rmi.RMIConnectorServer;
***************
*** 178,211 ****
           return new JMXServiceURL(url.getProtocol(), url.getHost(), url.getPort(), path);
        }
! 
!       String jndiURL = parseJNDIForm(url);
!       if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("JMXServiceURL path for binding is: '" + jndiURL + "'");
! 
!       InitialContext ctx = null;
!       try
!       {
!          ctx = new InitialContext(new Hashtable(environment));
!          boolean rebind = Boolean.valueOf((String)environment.get(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE)).booleanValue();
!          if (rebind)
!             ctx.rebind(jndiURL, rmiServer.toStub());
!          else
!             ctx.bind(jndiURL, rmiServer.toStub());
!          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Bound " + rmiServer + " to " + jndiURL);
!          return url;
!       }
!       catch (NamingException x)
!       {
!          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot bind server " + rmiServer + " to " + jndiURL, x);
!          throw new IOException(x.toString());
!       }
!       finally
        {
           try
           {
!             if (ctx != null) ctx.close();
           }
           catch (NamingException x)
           {
!             if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot close InitialContext", x);
           }
        }
--- 177,212 ----
           return new JMXServiceURL(url.getProtocol(), url.getHost(), url.getPort(), path);
        }
!       else
        {
+          String jndiURL = parseJNDIForm(url);
+          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("JMXServiceURL path for binding is: '" + jndiURL + "'");
+ 
+          InitialContext ctx = null;
           try
           {
!             ctx = new InitialContext(new Hashtable(environment));
!             boolean rebind = Boolean.valueOf((String)environment.get(RMIConnectorServer.JNDI_REBIND_ATTRIBUTE)).booleanValue();
!             if (rebind)
!                ctx.rebind(jndiURL, rmiServer.toStub());
!             else
!                ctx.bind(jndiURL, rmiServer.toStub());
!             if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Bound " + rmiServer + " to " + jndiURL);
!             return url;
           }
           catch (NamingException x)
           {
!             if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot bind server " + rmiServer + " to " + jndiURL, x);
!             throw new IOException(x.toString());
!          }
!          finally
!          {
!             try
!             {
!                if (ctx != null) ctx.close();
!             }
!             catch (NamingException x)
!             {
!                if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot close InitialContext", x);
!             }
           }
        }
***************
*** 255,294 ****
        Logger logger = getLogger();
        if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("JMXServiceURL for unbinding is: '" + url + "'");
        // The server was not bound to JNDI (the stub was encoded), just return
        if (isEncodedForm(url))
        {
-          destroyServer(server, environment);
           return;
        }
! 
!       String jndiURL = parseJNDIForm(url);
!       if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("JMXServiceURL path for binding is: '" + jndiURL + "'");
! 
!       InitialContext ctx = null;
!       try
!       {
!          ctx = new InitialContext(new Hashtable(environment));
!          ctx.unbind(jndiURL);
!          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Unbound " + server + " from " + jndiURL);
!       }
!       catch (NamingException x)
!       {
!          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot unbind server " + server + " to " + jndiURL, x);
!          throw new IOException(x.toString());
!       }
!       finally
        {
           try
           {
!             if (ctx != null) ctx.close();
           }
           catch (NamingException x)
           {
!             if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot close InitialContext", x);
           }
        }
     }
  
!    protected void destroyServer(Object server, Map environment) throws IOException
     {
     }
--- 256,297 ----
        Logger logger = getLogger();
        if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("JMXServiceURL for unbinding is: '" + url + "'");
+ 
        // The server was not bound to JNDI (the stub was encoded), just return
        if (isEncodedForm(url))
        {
           return;
        }
!       else
        {
+          String jndiURL = parseJNDIForm(url);
+          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("JMXServiceURL path for binding is: '" + jndiURL + "'");
+ 
+          InitialContext ctx = null;
           try
           {
!             ctx = new InitialContext(new Hashtable(environment));
!             ctx.unbind(jndiURL);
!             if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Unbound " + server + " from " + jndiURL);
           }
           catch (NamingException x)
           {
!             if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot unbind server " + server + " to " + jndiURL, x);
!             throw new IOException(x.toString());
!          }
!          finally
!          {
!             try
!             {
!                if (ctx != null) ctx.close();
!             }
!             catch (NamingException x)
!             {
!                if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Cannot close InitialContext", x);
!             }
           }
        }
     }
  
!    public void destroyServer(Object server, JMXServiceURL url, Map environment) throws IOException
     {
     }



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.