From aaa4a068590bd5a3328dd807e41706bb2f908d92 Mon Sep 17 00:00:00 2001 From: chenson42 Date: Fri, 28 Oct 2011 21:07:53 +0000 Subject: [PATCH] clean up configurationchangeddatarouter. --- .../route/ConfigurationChangedRouter.java | 55 ++++++++----------- .../src/main/resources/symmetric-routers.xml | 1 + 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/symmetric/symmetric-core/src/main/java/org/jumpmind/symmetric/route/ConfigurationChangedRouter.java b/symmetric/symmetric-core/src/main/java/org/jumpmind/symmetric/route/ConfigurationChangedRouter.java index 00d759536b..be1f43c9fc 100644 --- a/symmetric/symmetric-core/src/main/java/org/jumpmind/symmetric/route/ConfigurationChangedRouter.java +++ b/symmetric/symmetric-core/src/main/java/org/jumpmind/symmetric/route/ConfigurationChangedRouter.java @@ -31,12 +31,14 @@ import org.jumpmind.symmetric.model.NetworkedNode; import org.jumpmind.symmetric.model.Node; import org.jumpmind.symmetric.model.NodeGroupLink; -import org.jumpmind.symmetric.model.OutgoingBatch; import org.jumpmind.symmetric.service.IConfigurationService; import org.jumpmind.symmetric.service.INodeService; +import org.jumpmind.symmetric.service.ITriggerRouterService; public class ConfigurationChangedRouter extends AbstractDataRouter implements IDataRouter { + private static final String CONTEXT_RESYNC_TRIGGERS_NEEDED = "CONTEXT_RESYNC_TRIGGERS_NEEDED"; + public final static String KEY = "symconfig"; protected String tablePrefix; @@ -44,6 +46,8 @@ public class ConfigurationChangedRouter extends AbstractDataRouter implements ID private IConfigurationService configurationService; private INodeService nodeService; + + private ITriggerRouterService triggerRouterService; public Collection routeToNodes(IRouterContext routingContext, DataMetaData dataMetaData, Set possibleTargetNodes, boolean initialLoad) { @@ -74,6 +78,12 @@ public Collection routeToNodes(IRouterContext routingContext, } } else { nodeIds = toNodeIds(possibleTargetNodes, nodeIds); + + if (tableMatches(dataMetaData, TableConstants.SYM_TRIGGER) + || tableMatches(dataMetaData, TableConstants.SYM_TRIGGER_ROUTER) + || tableMatches(dataMetaData, TableConstants.SYM_ROUTER)) { + routingContext.getContextCache().put(CONTEXT_RESYNC_TRIGGERS_NEEDED, Boolean.TRUE); + } } return nodeIds; @@ -152,11 +162,13 @@ private boolean isLinked(String nodeIdInQuestion, Node nodeThatCouldBeRoutedTo, return true; } } - - public void completeBatch(IRouterContext context, OutgoingBatch batch) { - // TODO resync triggers if sym_trigger, sym_trigger_router or sym_router - // has changed we could do a synch triggers call here when we know these are - // changing + + @Override + public void contextCommitted(IRouterContext routingContext) { + if (Boolean.TRUE.equals(routingContext.getContextCache().get(CONTEXT_RESYNC_TRIGGERS_NEEDED))) { + // TODO - Add parameter to turn this on. + //triggerRouterService.syncTriggers(); + } } public void setTablePrefix(String tablePrefix) { @@ -170,6 +182,10 @@ public void setConfigurationService(IConfigurationService configurationService) public void setNodeService(INodeService nodeService) { this.nodeService = nodeService; } + + public void setTriggerRouterService(ITriggerRouterService triggerRouterService) { + this.triggerRouterService = triggerRouterService; + } private boolean tableMatches(DataMetaData dataMetaData, String tableName) { boolean matches = false; @@ -180,31 +196,4 @@ private boolean tableMatches(DataMetaData dataMetaData, String tableName) { return matches; } - // TODO: This guy is going to replace the initial load selects for sym_node - // and sym_node_security found in - // triggerrouter-service.xml. The nodes variable has all eligible nodes that - // can be sync'd to. - // Go through them all and figure out if the sym_node or sym_node_security - // rows should be synced. If so, - // return the nodeid in the returned collection. - same criteira as the - // initial load sql should be implemented in code here - - // DONE - if the configuration table is something other than node or - // security, then return all node ids (configuration - // goes everywhere. - // - // STILL USED IN TRIGGER ROUTER SERVICE - // - this router is configured in symmetric-routers.xml. it will be used in - // TriggerRouterService.buildRegistrationTriggerRouter() - // we can get rid of rootConfigChannelInitialLoadSelect in - // triggerrouter-service.xml - - // TODO: side note: if the external id of a node exists in - // registration_redirect, then we should sync that node only - // to the registration_node_id. - - // TODO: another other side node: we should put some indicator into the - // context if sym_trigger, sym_trigger_router, or sym_router - // changes so we can run syncTriggers when the batch is completed. - } diff --git a/symmetric/symmetric-core/src/main/resources/symmetric-routers.xml b/symmetric/symmetric-core/src/main/resources/symmetric-routers.xml index bcf541015e..dba429f758 100644 --- a/symmetric/symmetric-core/src/main/resources/symmetric-routers.xml +++ b/symmetric/symmetric-core/src/main/resources/symmetric-routers.xml @@ -41,6 +41,7 @@ +