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;
}
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());
}
}
}
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"));
}
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"));
}
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));
}
Aggregations