From 287e78722fa75ce45930f2b6ea37a50fc164bcbb Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Thu, 23 Aug 2012 16:27:39 +0800 Subject: [PATCH] IDEMPIERE-356 Change Role. Refactoring, reduce min thread pool size and added timeout setting. --- .../src/org/compiere/Adempiere.java | 5 +- .../org/adempiere/webui/AdempiereWebUI.java | 52 ++++++++++++------- .../webui/session/SessionManager.java | 11 ---- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/Adempiere.java b/org.adempiere.base/src/org/compiere/Adempiere.java index 0cd15dc3ef..96d24730e6 100644 --- a/org.adempiere.base/src/org/compiere/Adempiere.java +++ b/org.adempiere.base/src/org/compiere/Adempiere.java @@ -567,10 +567,11 @@ public final class Adempiere max = 200; } if (min < 0) { - min = 20; + min = 10; } // start thread pool - threadPoolExecutor = new ThreadPoolExecutor(min, max, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue()); + threadPoolExecutor = new ThreadPoolExecutor(min, max, 1, TimeUnit.MINUTES, new LinkedBlockingQueue()); + threadPoolExecutor.allowCoreThreadTimeOut(true); } /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java index 3eaff9009a..35ae874def 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/AdempiereWebUI.java @@ -344,18 +344,34 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb */ public void logout() { - appDesktop.logout(); - Executions.getCurrent().getDesktop().getSession().getAttributes().clear(); - - AEnv.logout(); - - SessionManager.clearSession(); - super.getChildren().clear(); - Page page = this.getPage(); - page.removeComponents(); + Session session = logout0(); + + //clear context, invalidate session + Env.getCtx().clear(); + session.invalidate(); + + //redirect to login page Executions.sendRedirect("index.zul"); } + protected Session logout0() { + Session session = Executions.getCurrent().getDesktop().getSession(); + + //stop background thread + appDesktop.logout(); + + //clear remove all children and root component + getChildren().clear(); + getPage().removeComponents(); + + //clear session attributes + session.getAttributes().clear(); + + //logout ad_session + AEnv.logout(); + return session; + } + /** * @return IDesktop */ @@ -426,6 +442,7 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb @Override public void changeRole(MUser user) { + //save context for re-login Properties properties = new Properties(); Env.setContext(properties, Env.AD_CLIENT_ID, Env.getAD_Client_ID(Env.getCtx())); Env.setContext(properties, Env.AD_ORG_ID, Env.getAD_Org_ID(Env.getCtx())); @@ -438,17 +455,16 @@ public class AdempiereWebUI extends Window implements EventListener, IWeb Env.setContext(properties, Env.LANGUAGE, Env.getContext(Env.getCtx(), Env.LANGUAGE)); Env.setContext(properties, AEnv.LOCALE, Env.getContext(Env.getCtx(), AEnv.LOCALE)); - Locale locale = (Locale) Executions.getCurrent().getSession().getAttribute(Attributes.PREFERRED_LOCALE); + Locale locale = (Locale) Executions.getCurrent().getDesktop().getSession().getAttribute(Attributes.PREFERRED_LOCALE); + HttpServletRequest httpRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest(); - appDesktop.logout(); - HttpServletRequest httpRequest = (HttpServletRequest) Executions.getCurrent().getNativeRequest(); - Session session = Executions.getCurrent().getDesktop().getSession(); - session.getAttributes().clear(); - - AEnv.logout(); - ((SessionCtrl)session).invalidateNow(); - Env.getCtx().clear(); + Session session = logout0(); + //clear context and invalidate session + Env.getCtx().clear(); + ((SessionCtrl)session).invalidateNow(); + + //put saved context into new session Map map = new HashMap(); map.put("context", properties); map.put("locale", locale); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionManager.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionManager.java index aecfe4528e..9c02b50455 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionManager.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/session/SessionManager.java @@ -78,17 +78,6 @@ public class SessionManager return app; } - public static void clearSession() - { - Env.getCtx().clear(); - Session session = getSession(); - if (session != null) - { - session.removeAttribute(SessionContextListener.SESSION_CTX); - session.invalidate(); - } - } - public static void logoutSession() { IWebClient app = getSessionApplication();