private static ServerMain createProcessAndDoLookup(HibernateConfiguration cfg, HibernatePlugin plugin)
{
try
{
IMessageHandler mh = plugin.getApplication().getMessageHandler();
ServerMain stub;
if (cfg.isEndProcessOnDisconnect())
{
mh.showMessage("Launching Hibernate process ...");
try
{
launchProcess(cfg);
}
catch (Throwable e)
{
s_log.error("Error launching process. Maybe port is in use. Tryin to connect and kill existing process:", e);
try
{
stub = attachToProcess(cfg, mh, true);
if (null != stub)
{
stub.exit();
}
}
catch (Throwable e1)
{
// Nothing
}
launchProcess(cfg);
}
stub = attachToProcess(cfg, mh, false);
}
else
{
stub = attachToProcess(cfg, mh, false);
if(null == stub)
{
mh.showMessage("Attaching to existing Hibernate process failed. Now will launch new process ...");
launchProcess(cfg);
stub = attachToProcess(cfg, mh, false);
}
}
if (null == stub)
{
throw new IllegalStateException("Could not attach to Hibernate process");
}
mh.showMessage("Successfully attached to Hibernate process. Now creating Hibernate session.");
return stub;
}
catch (IOException e)
{
throw new RuntimeException(e);