*/
public synchronized void start() throws Exception
{
if (isRunning()) return;
final Logger logger = getLogger();
// We start another thread because Process.waitFor() blocks until the process is destroyed.
Thread thread = new Thread(new Runnable()
{
public void run()
{
String home = getJavaHomeBin();
String command = (home == null ? "" : home) + "tnameserv -ORBInitialPort " + getPort();
try
{
m_process = Runtime.getRuntime().exec(command);
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Process created: " + m_process);
}
catch (IOException x)
{
if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Could not create process", x);
exception = x;
return;
}
m_output = new InputStreamConsumer(m_process.getInputStream());
m_error = new InputStreamConsumer(m_process.getErrorStream());
m_output.start();
m_error.start();
m_running = true;
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();
}
}
}, "CosNamingService Thread");
thread.setDaemon(true);
thread.start();
while (!m_running && exception == null) wait(10);
if (exception != null) throw exception;
if (logger.isEnabledFor(Logger.TRACE)) logger.trace("CosNamingService started");
}