IDEMPIERE-4211 Schedulers launched twice - problem with RunOnlyOnIP null running on load balancer (#345)
- log errors from background init. - add explicit Env Context init for AdempiereMonitor thread and Background init thread.
This commit is contained in:
parent
c9a766c806
commit
03d668bf51
|
@ -148,6 +148,11 @@ public class WebEnv
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Properties ctx = new Properties();
|
||||||
|
Env.setContext(ctx, Env.AD_CLIENT_ID, 0);
|
||||||
|
Env.setContext(ctx, Env.AD_USER_ID, 0);
|
||||||
|
ServerContext.setCurrentInstance(ctx);
|
||||||
|
|
||||||
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
|
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
|
||||||
Enumeration<String> en = context.getInitParameterNames();
|
Enumeration<String> en = context.getInitParameterNames();
|
||||||
StringBuilder info = new StringBuilder("Servlet Context Init Parameters: ")
|
StringBuilder info = new StringBuilder("Servlet Context Init Parameters: ")
|
||||||
|
@ -179,18 +184,12 @@ public class WebEnv
|
||||||
|
|
||||||
// Logging now initiated
|
// Logging now initiated
|
||||||
if (log.isLoggable(Level.INFO)) log.info(info.toString());
|
if (log.isLoggable(Level.INFO)) log.info(info.toString());
|
||||||
//
|
//
|
||||||
Properties ctx = new Properties();
|
MClient client = MClient.get(Env.getCtx(), 0);
|
||||||
try {
|
MSystem system = MSystem.get(Env.getCtx());
|
||||||
ServerContext.setCurrentInstance(ctx);
|
client.sendEMail(client.getRequestEMail(),
|
||||||
MClient client = MClient.get(Env.getCtx(), 0);
|
"Server started: " + system.getName() + " (" + WebUtil.getServerName() + ")",
|
||||||
MSystem system = MSystem.get(Env.getCtx());
|
"ServerInfo: " + context.getServerInfo(), null);
|
||||||
client.sendEMail(client.getRequestEMail(),
|
|
||||||
"Server started: " + system.getName() + " (" + WebUtil.getServerName() + ")",
|
|
||||||
"ServerInfo: " + context.getServerInfo(), null);
|
|
||||||
} finally {
|
|
||||||
ServerContext.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_initOK;
|
return s_initOK;
|
||||||
} // initWeb
|
} // initWeb
|
||||||
|
|
|
@ -1282,46 +1282,62 @@ public class AdempiereMonitor extends HttpServlet
|
||||||
|
|
||||||
// initial Wait (default to 10 seconds) to give cluster service time to start first
|
// initial Wait (default to 10 seconds) to give cluster service time to start first
|
||||||
final int initialWaitSeconds = MSysConfig.getIntValue(MSysConfig.MONITOR_INITIAL_WAIT_FOR_CLUSTER_IN_SECONDS, 10);
|
final int initialWaitSeconds = MSysConfig.getIntValue(MSysConfig.MONITOR_INITIAL_WAIT_FOR_CLUSTER_IN_SECONDS, 10);
|
||||||
serverMgrFuture = Adempiere.getThreadPoolExecutor().schedule(() -> {
|
serverMgrFuture = Adempiere.getThreadPoolExecutor().schedule(() -> {
|
||||||
int maxSecondsToWait = MSysConfig.getIntValue(MSysConfig.MONITOR_MAX_WAIT_FOR_CLUSTER_IN_SECONDS, 180);
|
try {
|
||||||
int totalWaitSeconds = initialWaitSeconds;
|
Properties ctx = new Properties();
|
||||||
//check every 5 seconds (until maxSecondsToWait)
|
Env.setContext(ctx, Env.AD_CLIENT_ID, 0);
|
||||||
int waitSeconds = 5;
|
Env.setContext(ctx, Env.AD_USER_ID, 0);
|
||||||
while (ClusterServerMgr.getClusterService() == null)
|
ServerContext.setCurrentInstance(ctx);
|
||||||
{
|
|
||||||
try {
|
int maxSecondsToWait = MSysConfig.getIntValue(MSysConfig.MONITOR_MAX_WAIT_FOR_CLUSTER_IN_SECONDS, 180);
|
||||||
Thread.sleep(waitSeconds * 1000);
|
int totalWaitSeconds = initialWaitSeconds;
|
||||||
} catch (InterruptedException e) {
|
//check every 5 seconds (until maxSecondsToWait)
|
||||||
break;
|
int waitSeconds = 5;
|
||||||
|
while (ClusterServerMgr.getClusterService() == null)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
Thread.sleep(waitSeconds * 1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (Thread.interrupted())
|
||||||
|
break;
|
||||||
|
totalWaitSeconds += waitSeconds;
|
||||||
|
if (totalWaitSeconds >= maxSecondsToWait) {
|
||||||
|
log.warning("Cluster Service did not start after " + totalWaitSeconds + " seconds");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Thread.interrupted())
|
|
||||||
break;
|
//always create the local server manager instance
|
||||||
totalWaitSeconds += waitSeconds;
|
m_serverMgr = AdempiereServerMgr.get();
|
||||||
if (totalWaitSeconds >= maxSecondsToWait) {
|
|
||||||
log.warning("Cluster Service did not start after " + totalWaitSeconds + " seconds");
|
//switch to cluster manager if cluster service is available
|
||||||
break;
|
if (ClusterServerMgr.getClusterService() != null)
|
||||||
|
m_serverMgr = ClusterServerMgr.getInstance();
|
||||||
|
} catch (Throwable e) {
|
||||||
|
if (e.getCause() != null) {
|
||||||
|
log.log(Level.SEVERE, e.getCause().getMessage(), e.getCause());
|
||||||
|
} else {
|
||||||
|
log.log(Level.SEVERE, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
ServerContext.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
//always create the local server manager instance
|
|
||||||
m_serverMgr = AdempiereServerMgr.get();
|
|
||||||
|
|
||||||
//switch to cluster manager if cluster service is available
|
|
||||||
if (ClusterServerMgr.getClusterService() != null)
|
|
||||||
m_serverMgr = ClusterServerMgr.getInstance();
|
|
||||||
}, initialWaitSeconds, TimeUnit.SECONDS);
|
}, initialWaitSeconds, TimeUnit.SECONDS);
|
||||||
|
|
||||||
m_dirAccessList = getDirAcessList();
|
m_dirAccessList = getDirAcessList();
|
||||||
} // init
|
} // init
|
||||||
|
|
||||||
private IServerManager getServerManager()
|
private synchronized IServerManager getServerManager()
|
||||||
{
|
{
|
||||||
if (!serverMgrFuture.isDone() && !serverMgrFuture.isCancelled())
|
if (serverMgrFuture != null && !serverMgrFuture.isDone() && !serverMgrFuture.isCancelled())
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
serverMgrFuture.get();
|
serverMgrFuture.get();
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return m_serverMgr;
|
return m_serverMgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue