Search in sources :

Example 26 with NodeChannel

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

the class RouterService method routeDataForEachChannel.

/**
     * We route data channel by channel for two reasons. One is that if/when we
     * decide to multi-thread the routing it is a simple matter of inserting a
     * thread pool here and waiting for all channels to be processed. The other
     * reason is to reduce the number of connections we are required to have.
     */
protected int routeDataForEachChannel() {
    int dataCount = 0;
    Node sourceNode = engine.getNodeService().findIdentity();
    ProcessInfo processInfo = engine.getStatisticManager().newProcessInfo(new ProcessInfoKey(sourceNode.getNodeId(), null, ProcessType.ROUTER_JOB));
    processInfo.setStatus(ProcessInfo.Status.PROCESSING);
    try {
        final List<NodeChannel> channels = engine.getConfigurationService().getNodeChannels(false);
        Set<String> readyChannels = null;
        if (parameterService.is(ParameterConstants.ROUTING_QUERY_CHANNELS_FIRST)) {
            readyChannels = getReadyChannels();
        }
        for (NodeChannel nodeChannel : channels) {
            if (nodeChannel.isEnabled() && (readyChannels == null || readyChannels.contains(nodeChannel.getChannelId()))) {
                processInfo.setCurrentChannelId(nodeChannel.getChannelId());
                dataCount += routeDataForChannel(processInfo, nodeChannel, sourceNode);
            } else {
                gapDetector.setIsAllDataRead(false);
                if (log.isDebugEnabled()) {
                    log.debug("Not routing the {} channel.  It is either disabled or suspended.", nodeChannel.getChannelId());
                }
            }
        }
        processInfo.setStatus(ProcessInfo.Status.OK);
    } catch (RuntimeException ex) {
        processInfo.setStatus(ProcessInfo.Status.ERROR);
        firstTimeCheckForAbandonedBatches = true;
        throw ex;
    }
    return dataCount;
}
Also used : Node(org.jumpmind.symmetric.model.Node) ProcessInfoKey(org.jumpmind.symmetric.model.ProcessInfoKey) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 27 with NodeChannel

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

the class StatisticManager method resetChannelStats.

protected void resetChannelStats(boolean force) {
    if (force) {
        channelStats = null;
    }
    if (channelStats == null) {
        List<NodeChannel> channels = configurationService.getNodeChannels(false);
        channelStats = new HashMap<String, ChannelStats>(channels.size());
        for (NodeChannel nodeChannel : channels) {
            getChannelStats(nodeChannel.getChannelId());
        }
    }
}
Also used : NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 28 with NodeChannel

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

the class ColumnMatchDataRouterTest method testExpressionNotEqualsNodeId.

@Test
public void testExpressionNotEqualsNodeId() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("NODE_ID != :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(2, result.size());
    assertEquals(true, result.contains("200"));
    assertEquals(true, result.contains("300"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 29 with NodeChannel

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

the class ColumnMatchDataRouterTest method testExpressionEqualsNodeId.

@Test
public void testExpressionEqualsNodeId() {
    ColumnMatchDataRouter router = new ColumnMatchDataRouter();
    SimpleRouterContext routingContext = new SimpleRouterContext();
    HashSet<Node> nodes = new HashSet<Node>();
    nodes.add(new Node("100", "client"));
    nodes.add(new Node("200", "client"));
    nodes.add(new Node("300", "client"));
    TriggerHistory triggerHist = new TriggerHistory("mytable", "ID", "ID,NODE_ID,COLUMN2");
    Data data = new Data();
    data.setDataId(1);
    data.setDataEventType(DataEventType.INSERT);
    data.setRowData("1,100,Super Dooper");
    data.setTriggerHistory(triggerHist);
    Table table = new Table();
    NodeChannel nodeChannel = new NodeChannel();
    Router route = new Router();
    route.setRouterExpression("NODE_ID = :NODE_ID");
    route.setRouterId("route1");
    DataMetaData dataMetaData = new DataMetaData(data, table, route, nodeChannel);
    Set<String> result = router.routeToNodes(routingContext, dataMetaData, nodes, false, false, null);
    assertEquals(1, result.size());
    assertEquals(true, result.contains("100"));
}
Also used : Table(org.jumpmind.db.model.Table) Node(org.jumpmind.symmetric.model.Node) Router(org.jumpmind.symmetric.model.Router) Data(org.jumpmind.symmetric.model.Data) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) HashSet(java.util.HashSet) DataMetaData(org.jumpmind.symmetric.model.DataMetaData) Test(org.junit.Test)

Example 30 with NodeChannel

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

the class AbstractRouterServiceTest method testSyncOnColumnChange.

public void testSyncOnColumnChange() {
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(10000);
    testChannel.setBatchAlgorithm("transactional");
    getConfigurationService().saveChannel(testChannel, true);
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("bsh");
    trigger1.getRouter().setRouterExpression("ROUTING_INT != null && !ROUTING_INT.equals(OLD_ROUTING_INT)");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    resetBatches();
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    insert(TEST_TABLE_1, 1, true);
    getRouterService().routeData(true);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    int pk = getSqlTemplate().queryForInt("select pk from " + TEST_TABLE_1 + " where routing_varchar='" + NODE_GROUP_NODE_1.getNodeId() + "'");
    getSqlTemplate().update("update " + TEST_TABLE_1 + " set routing_int=1 where pk=?", pk);
    getRouterService().routeData(true);
    Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    getSqlTemplate().update("update " + TEST_TABLE_1 + " set routing_int=1 where pk=?", new Object[] { pk });
    getRouterService().routeData(true);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    getSqlTemplate().update("update " + TEST_TABLE_1 + " set routing_int=10 where pk=?", new Object[] { pk });
    getRouterService().routeData(true);
    Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Aggregations

NodeChannel (org.jumpmind.symmetric.model.NodeChannel)39 Test (org.junit.Test)15 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)14 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)13 Node (org.jumpmind.symmetric.model.Node)12 HashSet (java.util.HashSet)11 Data (org.jumpmind.symmetric.model.Data)10 Table (org.jumpmind.db.model.Table)9 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)9 Router (org.jumpmind.symmetric.model.Router)9 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)9 Date (java.util.Date)7 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)6 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)5 FixMethodOrder (org.junit.FixMethodOrder)5 ArrayList (java.util.ArrayList)4 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)2