From 4cfe1258b0ec1129296cc9190a6076623f89f47b Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 19 Aug 2014 17:16:01 +0800 Subject: [PATCH] IDEMPIERE-3653 1004207 Change behavior of system cacheing for multi-tenants. Add API to support dynamic addition and removal of scheduler. --- .../rpl/imp/ReplicationServerFactory.java | 7 +- .../org/adempiere/server/IServerFactory.java | 8 ++ .../compiere/server/AdempiereServerMgr.java | 88 ++++++++++++++++++- .../factory/DefaultAcctProcessorFactory.java | 7 +- .../factory/DefaultAlertProcessorFactory.java | 7 +- .../factory/DefaultLDAPProcessorFactory.java | 7 +- .../DefaultRequestProcessorFactory.java | 7 +- .../factory/DefaultSchedulerFactory.java | 7 +- .../DefaultWorkflowProcessorFactory.java | 8 +- 9 files changed, 138 insertions(+), 8 deletions(-) diff --git a/org.adempiere.replication.server/src/org/adempiere/server/rpl/imp/ReplicationServerFactory.java b/org.adempiere.replication.server/src/org/adempiere/server/rpl/imp/ReplicationServerFactory.java index 59ba473e00..e2c564e606 100644 --- a/org.adempiere.replication.server/src/org/adempiere/server/rpl/imp/ReplicationServerFactory.java +++ b/org.adempiere.replication.server/src/org/adempiere/server/rpl/imp/ReplicationServerFactory.java @@ -32,7 +32,7 @@ public class ReplicationServerFactory implements IServerFactory, IServerFactory> serviceTracker; + public static int SERVER_STATE_NOT_SCHEDULE = 0; + public static int SERVER_STATE_STARTED = 1; + public static int SERVER_STATE_STOPPED = 2; + /** * Get Adempiere Server Manager * @return mgr */ public synchronized static AdempiereServerMgr get() { - if (m_serverMgr == null) + return get(true); + } + + /** + * Get Adempiere Server Manager + * @return mgr + */ + public synchronized static AdempiereServerMgr get(boolean createNew) + { + if (m_serverMgr == null && createNew) { m_serverMgr = new AdempiereServerMgr(); serviceTracker = new ServiceTracker, IServerFactory>(AdempiereServerActivator.getBundleContext(), @@ -157,6 +171,34 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer serverFactoryList = Service.locator().list(IServerFactory.class).getServices(); + if (serverFactoryList != null && !serverFactoryList.isEmpty()) + { + for(IServerFactory factory : serverFactoryList ) + { + if (factory.getProcessorClass().getName().equals(scheduler.getClass().getName())) { + AdempiereServer server = factory.create(m_ctx, scheduler); + if (server != null && AdempiereServer.isOKtoRunOnIP(scheduler)) { + m_servers.add(new ServerWrapper(server)); + return start(serverId); + } + } + } + } + + return false; + } /** * Get Server Context @@ -413,6 +455,28 @@ public class AdempiereServerMgr implements ServiceTrackerCustomizer list = new ArrayList(); for (MAcctProcessor pModel : acctModels) { - AcctProcessor processor = new AcctProcessor(pModel); + AcctProcessor processor = create(ctx, pModel); list.add(processor); } return list.toArray(new AcctProcessor[0]); @@ -53,4 +53,9 @@ public class DefaultAcctProcessorFactory implements IServerFactory list = new ArrayList(); for (MAlertProcessor pModel : alertModels) { - AlertProcessor server = new AlertProcessor(pModel); + AlertProcessor server = create(ctx, pModel); list.add(server); } return list.toArray(new AlertProcessor[0]); @@ -50,4 +50,9 @@ public class DefaultAlertProcessorFactory implements IServerFactory list = new ArrayList(); for (MLdapProcessor lp : ldapModels) { - LdapProcessor server = new LdapProcessor(lp); + LdapProcessor server = create(ctx, lp); list.add(server); } return list.toArray(new LdapProcessor[0]); @@ -49,4 +49,9 @@ public class DefaultLDAPProcessorFactory implements IServerFactory getProcessorClass() { return MLdapProcessor.class; } + + @Override + public LdapProcessor create(Properties ctx, MLdapProcessor serverModel) { + return new LdapProcessor(serverModel); + } } diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultRequestProcessorFactory.java b/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultRequestProcessorFactory.java index 0801a62a19..979536fcd4 100644 --- a/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultRequestProcessorFactory.java +++ b/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultRequestProcessorFactory.java @@ -42,7 +42,7 @@ public class DefaultRequestProcessorFactory implements IServerFactory list = new ArrayList(); for (MRequestProcessor pModel : requestModels) { - RequestProcessor processor = new RequestProcessor(pModel); + RequestProcessor processor = create(ctx, pModel); list.add(processor); } return list.toArray(new RequestProcessor[0]); @@ -52,4 +52,9 @@ public class DefaultRequestProcessorFactory implements IServerFactory getProcessorClass() { return MRequestProcessor.class; } + + @Override + public RequestProcessor create(Properties ctx, MRequestProcessor serverModel) { + return new RequestProcessor(serverModel); + } } diff --git a/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultSchedulerFactory.java b/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultSchedulerFactory.java index 052f28e5be..b10c8defdb 100644 --- a/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultSchedulerFactory.java +++ b/org.adempiere.server/src/main/server/org/idempiere/server/factory/DefaultSchedulerFactory.java @@ -39,7 +39,7 @@ public class DefaultSchedulerFactory implements IServerFactory list = new ArrayList(); for (MScheduler pModel : schedulerModels) { - Scheduler server = new Scheduler(pModel); + Scheduler server = create(ctx, pModel); list.add(server); } return list.toArray(new Scheduler[0]); @@ -50,4 +50,9 @@ public class DefaultSchedulerFactory implements IServerFactory list = new ArrayList(); for (MWorkflowProcessor pModel : workflowModels) { - WorkflowProcessor server = new WorkflowProcessor(pModel); + WorkflowProcessor server = create(ctx, pModel); list.add(server); } return list.toArray(new WorkflowProcessor[0]); @@ -55,4 +55,10 @@ public class DefaultWorkflowProcessorFactory implements IServerFactory getProcessorClass() { return MWorkflowProcessor.class; } + + @Override + public WorkflowProcessor create(Properties ctx, + MWorkflowProcessor serverModel) { + return new WorkflowProcessor(serverModel); + } }