use of org.jumpmind.symmetric.model.OutgoingBatch in project symmetric-ds by JumpMind.
the class OutgoingBatchService method markAllConfigAsSentForNode.
public void markAllConfigAsSentForNode(String nodeId) {
int updateCount;
do {
updateCount = 0;
OutgoingBatches batches = getOutgoingBatches(nodeId, false);
List<OutgoingBatch> list = batches.getBatches();
for (OutgoingBatch outgoingBatch : list) {
if (outgoingBatch.getChannelId().equals(Constants.CHANNEL_CONFIG)) {
outgoingBatch.setStatus(Status.OK);
outgoingBatch.setErrorFlag(false);
outgoingBatch.setIgnoreCount(1);
updateOutgoingBatch(outgoingBatch);
updateCount++;
}
}
} while (updateCount > 0);
}
use of org.jumpmind.symmetric.model.OutgoingBatch in project symmetric-ds by JumpMind.
the class OutgoingBatchService method getOutgoingBatches.
@Override
public OutgoingBatches getOutgoingBatches(String nodeId, String channelThread, NodeGroupLinkAction eventAction, NodeGroupLinkAction defaultEventAction, boolean includeDisabledChannels) {
long ts = System.currentTimeMillis();
final int maxNumberOfBatchesToSelect = parameterService.getInt(ParameterConstants.OUTGOING_BATCH_MAX_BATCHES_TO_SELECT, 1000);
String sql = null;
Object[] params = null;
int[] types = null;
if (eventAction != null) {
if (eventAction.equals(defaultEventAction)) {
sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchChannelActionNullSql");
} else {
sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchChannelActionSql");
}
params = new Object[] { eventAction.name(), nodeId, channelThread, OutgoingBatch.Status.RQ.name(), OutgoingBatch.Status.NE.name(), OutgoingBatch.Status.QY.name(), OutgoingBatch.Status.SE.name(), OutgoingBatch.Status.LD.name(), OutgoingBatch.Status.ER.name(), OutgoingBatch.Status.IG.name(), OutgoingBatch.Status.RS.name() };
types = new int[] { Types.CHAR, Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR };
} else if (channelThread != null) {
sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchChannelSql");
params = new Object[] { nodeId, channelThread, OutgoingBatch.Status.RQ.name(), OutgoingBatch.Status.NE.name(), OutgoingBatch.Status.QY.name(), OutgoingBatch.Status.SE.name(), OutgoingBatch.Status.LD.name(), OutgoingBatch.Status.ER.name(), OutgoingBatch.Status.IG.name(), OutgoingBatch.Status.RS.name() };
types = new int[] { Types.VARCHAR, Types.VARCHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR };
} else {
sql = getSql("selectOutgoingBatchPrefixSql", "selectOutgoingBatchSql");
params = new Object[] { nodeId, OutgoingBatch.Status.RQ.name(), OutgoingBatch.Status.NE.name(), OutgoingBatch.Status.QY.name(), OutgoingBatch.Status.SE.name(), OutgoingBatch.Status.LD.name(), OutgoingBatch.Status.ER.name(), OutgoingBatch.Status.IG.name(), OutgoingBatch.Status.RS.name() };
types = new int[] { Types.VARCHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR, Types.CHAR };
}
List<OutgoingBatch> list = (List<OutgoingBatch>) sqlTemplate.query(sql, maxNumberOfBatchesToSelect, new OutgoingBatchMapper(includeDisabledChannels), params, types);
OutgoingBatches batches = new OutgoingBatches(list);
List<NodeChannel> channels = new ArrayList<NodeChannel>(configurationService.getNodeChannels(nodeId, true));
batches.sortChannels(channels);
List<IOutgoingBatchFilter> filters = extensionService.getExtensionPointList(IOutgoingBatchFilter.class);
List<OutgoingBatch> keepers = new ArrayList<OutgoingBatch>();
for (NodeChannel channel : channels) {
List<OutgoingBatch> batchesForChannel = getBatchesForChannelWindows(batches, nodeId, channel, configurationService.getNodeGroupChannelWindows(parameterService.getNodeGroupId(), channel.getChannelId()));
if (filters != null) {
for (IOutgoingBatchFilter filter : filters) {
batchesForChannel = filter.filter(channel, batchesForChannel);
}
}
if (parameterService.is(ParameterConstants.DATA_EXTRACTOR_ENABLED) || channel.getChannelId().equals(Constants.CHANNEL_CONFIG)) {
keepers.addAll(batchesForChannel);
}
}
batches.setBatches(keepers);
long executeTimeInMs = System.currentTimeMillis() - ts;
if (executeTimeInMs > Constants.LONG_OPERATION_THRESHOLD) {
log.info("Selecting {} outgoing batch rows for node {} on queue '{}' took {} ms", list.size(), nodeId, channelThread, executeTimeInMs);
}
return batches;
}
use of org.jumpmind.symmetric.model.OutgoingBatch in project symmetric-ds by JumpMind.
the class FileOutgoingTransport method readResponse.
@Override
public BufferedReader readResponse() throws IOException {
List<Long> batchIds = new ArrayList<Long>();
if (processedBatches != null) {
for (OutgoingBatch processedBatch : processedBatches) {
batchIds.add(processedBatch.getBatchId());
}
} else if (writer != null) {
batchIds = writer.getBatchIds();
}
StringBuilder resp = new StringBuilder();
for (Long batchId : batchIds) {
resp.append(WebConstants.ACK_BATCH_NAME).append(batchId).append("=").append(WebConstants.ACK_BATCH_OK).append("&");
resp.append(WebConstants.ACK_NODE_ID).append(batchId).append("=").append(remoteNode.getNodeId()).append("&");
}
return new BufferedReader(new StringReader(resp.toString()));
}
use of org.jumpmind.symmetric.model.OutgoingBatch in project symmetric-ds by JumpMind.
the class AbstractDataExtractorServiceTest method extract.
protected ExtractResults extract() {
IDataExtractorService service = getDataExtractorService();
StringWriter writer = new StringWriter();
InternalOutgoingTransport transport = new InternalOutgoingTransport(new BufferedWriter(writer));
List<OutgoingBatch> batches = service.extract(new ProcessInfo(), TestConstants.TEST_CLIENT_NODE, transport);
transport.close();
return new ExtractResults(batches, writer.getBuffer().toString());
}
use of org.jumpmind.symmetric.model.OutgoingBatch in project symmetric-ds by JumpMind.
the class AbstractRouterServiceTest method countBatchesForChannel.
protected int countBatchesForChannel(OutgoingBatches batches, NodeChannel channel) {
int count = 0;
for (Iterator<OutgoingBatch> iterator = batches.getBatches().iterator(); iterator.hasNext(); ) {
OutgoingBatch outgoingBatch = iterator.next();
count += outgoingBatch.getChannelId().equals(channel.getChannelId()) ? 1 : 0;
}
return count;
}
Aggregations