mx4j/src/tools/mx4j/tools/naming CosNamingService.java,1.12,1.13

Simone Bordet <[email protected]> Sat, 14 May 2005 10:21:04 +0000
Newsgroups gmane.comp.java.mx4j.cvs
Message-ID <[email protected]>
Update of /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/naming
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29811/src/tools/mx4j/tools/naming

Modified Files:
	CosNamingService.java 
Log Message:
Improved checks to see if the external process really started

Index: CosNamingService.java
===================================================================
RCS file: /cvsroot/mx4j/mx4j/src/tools/mx4j/tools/naming/CosNamingService.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** CosNamingService.java	13 Nov 2004 16:38:40 -0000	1.12
--- CosNamingService.java	14 May 2005 10:21:02 -0000	1.13
***************
*** 94,98 ****
        final Logger logger = getLogger();
  
! // We start another thread because Process.waitFor() blocks until the process is destroyed.
        Thread thread = new Thread(new Runnable()
        {
--- 94,98 ----
        final Logger logger = getLogger();
  
!       // We start another thread because Process.waitFor() blocks until the process is destroyed.
        Thread thread = new Thread(new Runnable()
        {
***************
*** 123,141 ****
              try
              {
! // Blocks until the process is destroyed
                 int result = m_process.waitFor();
!                if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Exit value is: " + result);
  
! // If we're still running after waitFor() returns, means stop() has not been called
! // so the process has returned unexpectedly
                 if (isRunning())
                 {
                    stop();
!                   if (logger.isEnabledFor(Logger.INFO)) logger.info("Unexpected exception (maybe the port " + getPort() + " is already in use)");
                 }
              }
              catch (InterruptedException x)
              {
!                if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Process has been interrupted", x);
                 stop();
              }
--- 123,142 ----
              try
              {
!                // Blocks until the process is destroyed
                 int result = m_process.waitFor();
!                if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Exit value for tnameserv is: " + result);
  
!                // If we're still running after waitFor() returns, means stop() has not been called
!                // so the process has returned unexpectedly, we signal this by setting the exception
                 if (isRunning())
                 {
                    stop();
!                   if (logger.isEnabledFor(Logger.INFO)) logger.info("Unexpected death of tnameserv process (maybe the port " + getPort() + " is already in use)");
!                   exception = new IOException("Unexpected death of tnameserv process " + m_process);
                 }
              }
              catch (InterruptedException x)
              {
!                if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Process tnameserv has been interrupted", x);
                 stop();
              }
***************
*** 146,152 ****
        thread.start();
  
!       while (!m_running && exception == null) wait(10);
  
!       if (exception != null) throw exception;
  
        if (logger.isEnabledFor(Logger.TRACE)) logger.trace("CosNamingService started");
--- 147,169 ----
        thread.start();
  
!       // Nothing better than wait for a while for the process to check if it is really started
!       Thread.sleep(500);
  
!       // Check if the process is still alive; it is not fool proof since
!       // the sleep above may not have been enough.
!       try
!       {
!          m_process.exitValue();
!          // The process exited unexpectedly
!          throw new IOException("Unexpected death of tnameserv process " + m_process);
!       }
!       catch (IllegalThreadStateException ignored)
!       {
!          // There are good chances that the process is still running, go on
!          if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Process tnameserv is alive");
!       }
! 
!       // Double check that the process is still running, since we're not fool proof
!       if (!isRunning() && exception != null) throw exception;
  
        if (logger.isEnabledFor(Logger.TRACE)) logger.trace("CosNamingService started");



-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7393&alloc_id=16281&op=click