Skip to content

Commit

Permalink
clean up configurationchangeddatarouter.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Oct 28, 2011
1 parent 9ea4eea commit aaa4a06
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
Expand Up @@ -31,19 +31,23 @@
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;

private IConfigurationService configurationService;

private INodeService nodeService;

private ITriggerRouterService triggerRouterService;

public Collection<String> routeToNodes(IRouterContext routingContext,
DataMetaData dataMetaData, Set<Node> possibleTargetNodes, boolean initialLoad) {
Expand Down Expand Up @@ -74,6 +78,12 @@ public Collection<String> 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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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.

}
Expand Up @@ -41,6 +41,7 @@
<bean class="org.jumpmind.symmetric.route.ConfigurationChangedRouter">
<property name="nodeService" ref="nodeService"/>
<property name="configurationService" ref="configurationService"/>
<property name="triggerRouterService" ref=""triggerRouterService""/>
<property name="tablePrefix" value="$[sym.sync.table.prefix]" />
</bean>
</entry>
Expand Down

0 comments on commit aaa4a06

Please sign in to comment.