Search in sources :

Example 1 with IOutgoingBatchFilter

use of org.jumpmind.symmetric.ext.IOutgoingBatchFilter 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;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) IOutgoingBatchFilter(org.jumpmind.symmetric.ext.IOutgoingBatchFilter) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 IOutgoingBatchFilter (org.jumpmind.symmetric.ext.IOutgoingBatchFilter)1 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)1 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)1 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)1