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;
|
||||
}
|
||||
|
||||
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)
|
||||
Enumeration<String> en = context.getInitParameterNames();
|
||||
StringBuilder info = new StringBuilder("Servlet Context Init Parameters: ")
|
||||
|
@ -180,17 +185,11 @@ public class WebEnv
|
|||
// Logging now initiated
|
||||
if (log.isLoggable(Level.INFO)) log.info(info.toString());
|
||||
//
|
||||
Properties ctx = new Properties();
|
||||
try {
|
||||
ServerContext.setCurrentInstance(ctx);
|
||||
MClient client = MClient.get(Env.getCtx(), 0);
|
||||
MSystem system = MSystem.get(Env.getCtx());
|
||||
client.sendEMail(client.getRequestEMail(),
|
||||
"Server started: " + system.getName() + " (" + WebUtil.getServerName() + ")",
|
||||
"ServerInfo: " + context.getServerInfo(), null);
|
||||
} finally {
|
||||
ServerContext.dispose();
|
||||
}
|
||||
|
||||
return s_initOK;
|
||||
} // initWeb
|
||||
|
|
|
@ -1283,6 +1283,12 @@ public class AdempiereMonitor extends HttpServlet
|
|||
// 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);
|
||||
serverMgrFuture = Adempiere.getThreadPoolExecutor().schedule(() -> {
|
||||
try {
|
||||
Properties ctx = new Properties();
|
||||
Env.setContext(ctx, Env.AD_CLIENT_ID, 0);
|
||||
Env.setContext(ctx, Env.AD_USER_ID, 0);
|
||||
ServerContext.setCurrentInstance(ctx);
|
||||
|
||||
int maxSecondsToWait = MSysConfig.getIntValue(MSysConfig.MONITOR_MAX_WAIT_FOR_CLUSTER_IN_SECONDS, 180);
|
||||
int totalWaitSeconds = initialWaitSeconds;
|
||||
//check every 5 seconds (until maxSecondsToWait)
|
||||
|
@ -1309,18 +1315,28 @@ public class AdempiereMonitor extends HttpServlet
|
|||
//switch to cluster manager if cluster service is available
|
||||
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();
|
||||
}
|
||||
}, initialWaitSeconds, TimeUnit.SECONDS);
|
||||
|
||||
m_dirAccessList = getDirAcessList();
|
||||
} // init
|
||||
|
||||
private IServerManager getServerManager()
|
||||
private synchronized IServerManager getServerManager()
|
||||
{
|
||||
if (!serverMgrFuture.isDone() && !serverMgrFuture.isCancelled())
|
||||
if (serverMgrFuture != null && !serverMgrFuture.isDone() && !serverMgrFuture.isCancelled())
|
||||
{
|
||||
try {
|
||||
serverMgrFuture.get();
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return m_serverMgr;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue