use of org.jumpmind.symmetric.SyntaxParsingException in project symmetric-ds by JumpMind.
the class RouterService method routeDataForChannel.
protected int routeDataForChannel(ProcessInfo processInfo, final NodeChannel nodeChannel, final Node sourceNode) {
ChannelRouterContext context = null;
long ts = System.currentTimeMillis();
int dataCount = -1;
try {
List<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouters(false);
boolean producesCommonBatches = producesCommonBatches(nodeChannel.getChannel(), parameterService.getNodeGroupId(), triggerRouters);
boolean onlyDefaultRoutersAssigned = onlyDefaultRoutersAssigned(nodeChannel.getChannel(), parameterService.getNodeGroupId(), triggerRouters);
context = new ChannelRouterContext(sourceNode.getNodeId(), nodeChannel, symmetricDialect.getPlatform().getSqlTemplate().startSqlTransaction());
context.setProduceCommonBatches(producesCommonBatches);
context.setOnlyDefaultRoutersAssigned(onlyDefaultRoutersAssigned);
context.setDataGaps(gapDetector.getDataGaps());
dataCount = selectDataAndRoute(processInfo, context);
return dataCount;
} catch (DelayRoutingException ex) {
log.info("The routing process for the {} channel is being delayed. {}", nodeChannel.getChannelId(), isNotBlank(ex.getMessage()) ? ex.getMessage() : "");
if (context != null) {
context.rollback();
}
return 0;
} catch (InterruptedException ex) {
log.warn("The routing process was interrupted. Rolling back changes");
if (context != null) {
context.rollback();
}
return 0;
} catch (SyntaxParsingException ex) {
log.error(String.format("Failed to route and batch data on '%s' channel due to an invalid router expression", nodeChannel.getChannelId()), ex);
if (context != null) {
context.rollback();
}
return 0;
} catch (Throwable ex) {
log.error(String.format("Failed to route and batch data on '%s' channel", nodeChannel.getChannelId()), ex);
if (context != null) {
context.rollback();
}
return 0;
} finally {
try {
if (dataCount > 0) {
long insertTs = System.currentTimeMillis();
engine.getDataService().insertDataEvents(context.getSqlTransaction(), context.getDataEventList());
context.clearDataEventsList();
completeBatchesAndCommit(context);
gapDetector.addDataIds(context.getDataIds());
gapDetector.setIsAllDataRead(context.getDataIds().size() < context.getChannel().getMaxDataToRoute());
context.incrementStat(System.currentTimeMillis() - insertTs, ChannelRouterContext.STAT_INSERT_DATA_EVENTS_MS);
if (parameterService.is(ParameterConstants.ROUTING_COLLECT_STATS_UNROUTED)) {
Data lastDataProcessed = context.getLastDataProcessed();
if (lastDataProcessed != null && lastDataProcessed.getDataId() > 0) {
String channelId = nodeChannel.getChannelId();
long queryTs = System.currentTimeMillis();
long dataLeftToRoute = sqlTemplate.queryForInt(getSql("selectUnroutedCountForChannelSql"), channelId, lastDataProcessed.getDataId());
queryTs = System.currentTimeMillis() - queryTs;
if (queryTs > Constants.LONG_OPERATION_THRESHOLD) {
log.warn("Unrouted query for channel {} took longer than expected. The query took {} ms.", channelId, queryTs);
}
engine.getStatisticManager().setDataUnRouted(channelId, dataLeftToRoute);
}
}
}
} catch (Exception e) {
if (context != null) {
context.rollback();
}
log.error("", e);
} finally {
long totalTime = System.currentTimeMillis() - ts;
context.incrementStat(totalTime, ChannelRouterContext.STAT_ROUTE_TOTAL_TIME);
context.logStats(log, totalTime);
context.cleanup();
}
}
}
use of org.jumpmind.symmetric.SyntaxParsingException in project symmetric-ds by JumpMind.
the class RouterService method routeDataForChannel.
protected int routeDataForChannel(ProcessInfo processInfo, final NodeChannel nodeChannel, final Node sourceNode, DataGapDetector gapDetector) {
ChannelRouterContext context = null;
long ts = System.currentTimeMillis();
int dataCount = -1;
try {
List<TriggerRouter> triggerRouters = engine.getTriggerRouterService().getTriggerRouters(true, false);
boolean producesCommonBatches = producesCommonBatches(nodeChannel.getChannel(), parameterService.getNodeGroupId(), triggerRouters);
boolean onlyDefaultRoutersAssigned = onlyDefaultRoutersAssigned(nodeChannel.getChannel(), parameterService.getNodeGroupId(), triggerRouters);
context = new ChannelRouterContext(sourceNode.getNodeId(), nodeChannel, symmetricDialect.getPlatform().getSqlTemplate().startSqlTransaction());
context.setProduceCommonBatches(producesCommonBatches);
context.setOnlyDefaultRoutersAssigned(onlyDefaultRoutersAssigned);
dataCount = selectDataAndRoute(processInfo, context);
return dataCount;
} catch (DelayRoutingException ex) {
log.info("The routing process for the {} channel is being delayed. {}", nodeChannel.getChannelId(), isNotBlank(ex.getMessage()) ? ex.getMessage() : "");
if (context != null) {
context.rollback();
}
return 0;
} catch (InterruptedException ex) {
log.warn("The routing process was interrupted. Rolling back changes");
if (context != null) {
context.rollback();
}
return 0;
} catch (SyntaxParsingException ex) {
log.error(String.format("Failed to route and batch data on '%s' channel due to an invalid router expression", nodeChannel.getChannelId()), ex);
if (context != null) {
context.rollback();
}
return 0;
} catch (Throwable ex) {
log.error(String.format("Failed to route and batch data on '%s' channel", nodeChannel.getChannelId()), ex);
if (context != null) {
context.rollback();
}
return 0;
} finally {
try {
if (dataCount > 0) {
long insertTs = System.currentTimeMillis();
engine.getDataService().insertDataEvents(context.getSqlTransaction(), context.getDataEventList());
context.clearDataEventsList();
completeBatchesAndCommit(context);
context.incrementStat(System.currentTimeMillis() - insertTs, ChannelRouterContext.STAT_INSERT_DATA_EVENTS_MS);
Data lastDataProcessed = context.getLastDataProcessed();
if (lastDataProcessed != null && lastDataProcessed.getDataId() > 0) {
String channelId = nodeChannel.getChannelId();
long queryTs = System.currentTimeMillis();
long dataLeftToRoute = sqlTemplate.queryForInt(getSql("selectUnroutedCountForChannelSql"), channelId, lastDataProcessed.getDataId());
queryTs = System.currentTimeMillis() - queryTs;
if (queryTs > Constants.LONG_OPERATION_THRESHOLD) {
log.warn("Unrouted query for channel {} took longer than expected", channelId, queryTs);
log.info("The query took {} ms", queryTs);
}
engine.getStatisticManager().setDataUnRouted(channelId, dataLeftToRoute);
}
}
} catch (Exception e) {
if (context != null) {
context.rollback();
}
log.error("", e);
} finally {
long totalTime = System.currentTimeMillis() - ts;
context.incrementStat(totalTime, ChannelRouterContext.STAT_ROUTE_TOTAL_TIME);
context.logStats(log, totalTime);
boolean detectGaps = context.isRequestGapDetection();
context.cleanup();
if (detectGaps) {
gapDetector.beforeRouting();
}
}
}
}
Aggregations