Search in sources :

Example 21 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method buildTriggerRoutersForSymmetricTables.

protected TriggerRouter buildTriggerRoutersForSymmetricTables(String version, Trigger trigger, NodeGroupLink nodeGroupLink) {
    TriggerRouter triggerRouter = new TriggerRouter();
    triggerRouter.setTrigger(trigger);
    Router router = triggerRouter.getRouter();
    router.setRouterId(buildSymmetricTableRouterId(trigger.getTriggerId(), nodeGroupLink.getSourceNodeGroupId(), nodeGroupLink.getTargetNodeGroupId()));
    if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT).equals(trigger.getSourceTableName())) {
        router.setRouterType(FileSyncDataRouter.ROUTER_TYPE);
    } else {
        router.setRouterType(ConfigurationChangedDataRouter.ROUTER_TYPE);
    }
    router.setNodeGroupLink(nodeGroupLink);
    router.setLastUpdateTime(trigger.getLastUpdateTime());
    triggerRouter.setLastUpdateTime(trigger.getLastUpdateTime());
    return triggerRouter;
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) ConfigurationChangedDataRouter(org.jumpmind.symmetric.route.ConfigurationChangedDataRouter) FileSyncDataRouter(org.jumpmind.symmetric.route.FileSyncDataRouter) Router(org.jumpmind.symmetric.model.Router)

Example 22 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method buildTriggerRoutersForSymmetricTables.

public List<TriggerRouter> buildTriggerRoutersForSymmetricTables(String version, NodeGroupLink nodeGroupLink, String... tablesToExclude) {
    int initialLoadOrder = 1;
    List<Trigger> triggers = buildTriggersForSymmetricTables(version, tablesToExclude);
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>(triggers.size());
    for (int j = 0; j < triggers.size(); j++) {
        Trigger trigger = triggers.get(j);
        TriggerRouter triggerRouter = buildTriggerRoutersForSymmetricTables(version, trigger, nodeGroupLink);
        triggerRouter.setInitialLoadOrder(initialLoadOrder++);
        triggerRouters.add(triggerRouter);
    }
    return triggerRouters;
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 23 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method getTriggerRoutersByChannel.

public Map<String, List<TriggerRouter>> getTriggerRoutersByChannel(String nodeGroupId, boolean refreshCache) {
    long triggerRouterCacheTimeoutInMs = parameterService.getLong(ParameterConstants.CACHE_TIMEOUT_TRIGGER_ROUTER_IN_MS);
    Map<String, List<TriggerRouter>> testValue = triggerRouterCacheByChannel;
    if (testValue == null || refreshCache || System.currentTimeMillis() - this.triggerRouterPerChannelCacheTime > triggerRouterCacheTimeoutInMs) {
        synchronized (cacheLock) {
            testValue = triggerRouterCacheByChannel;
            if (testValue == null || refreshCache || System.currentTimeMillis() - this.triggerRouterPerChannelCacheTime > triggerRouterCacheTimeoutInMs) {
                final Map<String, List<TriggerRouter>> newValue = new HashMap<String, List<TriggerRouter>>();
                this.triggerRouterPerChannelCacheTime = System.currentTimeMillis();
                List<TriggerRouter> triggerRouters = enhanceTriggerRouters(sqlTemplate.query(getTriggerRouterSql("selectGroupTriggersSql"), new TriggerRouterMapper(), nodeGroupId, nodeGroupId));
                for (TriggerRouter triggerRouter : triggerRouters) {
                    List<TriggerRouter> list = newValue.get(triggerRouter.getTrigger().getChannelId());
                    if (list == null) {
                        list = new ArrayList<TriggerRouter>();
                        newValue.put(triggerRouter.getTrigger().getChannelId(), list);
                    }
                    list.add(triggerRouter);
                }
                triggerRouterCacheByChannel = newValue;
                testValue = newValue;
            }
        }
    }
    return testValue;
}
Also used : HashMap(java.util.HashMap) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class TriggerRouterService method getTriggerRouterForCurrentNode.

public TriggerRouter getTriggerRouterForCurrentNode(String triggerId, String routerId, boolean refreshCache) {
    TriggerRouter triggerRouter = null;
    List<TriggerRouter> triggerRouters = getTriggerRoutersForCurrentNode(refreshCache).get(triggerId);
    if (triggerRouters != null) {
        for (TriggerRouter testTriggerRouter : triggerRouters) {
            if (ConfigurationChangedDataRouter.ROUTER_TYPE.equals(testTriggerRouter.getRouter().getRouterType()) || testTriggerRouter.getRouter().getRouterId().equals(routerId) || routerId.equals(Constants.UNKNOWN_ROUTER_ID)) {
                triggerRouter = testTriggerRouter;
                break;
            }
        }
    }
    if (triggerRouter == null) {
        log.warn("Could not find trigger router [{}:{}] in list {}", new Object[] { triggerId, routerId, triggerRouters == null ? 0 : triggerRouters.toString() });
    }
    return triggerRouter;
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter)

Example 25 with TriggerRouter

use of org.jumpmind.symmetric.model.TriggerRouter in project symmetric-ds by JumpMind.

the class RouterServiceTest method testNotProducesCommonBatchesOneTableOneChannelNonDefaultRouter.

@Test
public void testNotProducesCommonBatchesOneTableOneChannelNonDefaultRouter() {
    List<TriggerRouter> triggerRouters = new ArrayList<TriggerRouter>();
    triggerRouters.add(new TriggerRouter(new Trigger("a", CHANNEL_2_TEST.getChannelId()), new Router("test", SOURCE_NODE_GROUP, TARGET_NODE_GROUP, "column")));
    assertTrue(!routerService.producesCommonBatches(CHANNEL_2_TEST, SOURCE_NODE_GROUP, triggerRouters));
}
Also used : Trigger(org.jumpmind.symmetric.model.Trigger) ArrayList(java.util.ArrayList) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Router(org.jumpmind.symmetric.model.Router) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) Test(org.junit.Test)

Aggregations

TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)64 ArrayList (java.util.ArrayList)22 Trigger (org.jumpmind.symmetric.model.Trigger)20 Router (org.jumpmind.symmetric.model.Router)18 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)13 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)12 Test (org.junit.Test)12 List (java.util.List)10 Node (org.jumpmind.symmetric.model.Node)8 NodeGroupLink (org.jumpmind.symmetric.model.NodeGroupLink)7 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)7 Table (org.jumpmind.db.model.Table)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 HashMap (java.util.HashMap)5 HashSet (java.util.HashSet)5 Data (org.jumpmind.symmetric.model.Data)5 TableReloadRequest (org.jumpmind.symmetric.model.TableReloadRequest)5 ConfigurationChangedDataRouter (org.jumpmind.symmetric.route.ConfigurationChangedDataRouter)4 FileSyncDataRouter (org.jumpmind.symmetric.route.FileSyncDataRouter)4