Search in sources :

Example 1 with IBatchAlgorithm

use of org.jumpmind.symmetric.route.IBatchAlgorithm in project symmetric-ds by JumpMind.

the class RouterService method insertDataEvents.

protected int insertDataEvents(ProcessInfo processInfo, ChannelRouterContext context, DataMetaData dataMetaData, Collection<String> nodeIds) {
    int numberOfDataEventsInserted = 0;
    if (nodeIds == null || nodeIds.size() == 0) {
        nodeIds = new HashSet<String>(1);
        nodeIds.add(Constants.UNROUTED_NODE_ID);
    }
    long ts = System.currentTimeMillis();
    long batchIdToReuse = -1;
    boolean dataEventAdded = false;
    for (String nodeId : nodeIds) {
        if (nodeId != null) {
            Map<String, OutgoingBatch> batches = context.getBatchesByNodes();
            OutgoingBatch batch = batches.get(nodeId);
            if (batch == null) {
                batch = new OutgoingBatch(nodeId, dataMetaData.getNodeChannel().getChannelId(), Status.RT);
                batch.setBatchId(batchIdToReuse);
                batch.setCommonFlag(context.isProduceCommonBatches());
                log.debug("About to insert a new batch for node {} on the '{}' channel.  Batches in progress are: {}.", new Object[] { nodeId, batch.getChannelId(), context.getBatchesByNodes().values() });
                engine.getOutgoingBatchService().insertOutgoingBatch(batch);
                processInfo.incrementBatchCount();
                context.getBatchesByNodes().put(nodeId, batch);
                // if in reuse mode, then share the batch id
                if (context.isProduceCommonBatches()) {
                    batchIdToReuse = batch.getBatchId();
                }
            }
            if (dataMetaData.getData().getDataEventType() == DataEventType.RELOAD) {
                long loadId = context.getLastLoadId();
                if (loadId < 0) {
                    loadId = engine.getSequenceService().nextVal(context.getSqlTransaction(), Constants.SEQUENCE_OUTGOING_BATCH_LOAD_ID);
                    context.setLastLoadId(loadId);
                }
                batch.setLoadId(loadId);
            } else {
                context.setLastLoadId(-1);
            }
            batch.incrementEventCount(dataMetaData.getData().getDataEventType());
            batch.incrementDataEventCount();
            batch.incrementTableCount(dataMetaData.getTable().getNameLowerCase());
            if (!context.isProduceCommonBatches() || (context.isProduceCommonBatches() && !dataEventAdded)) {
                Router router = dataMetaData.getRouter();
                context.addDataEvent(dataMetaData.getData().getDataId(), batch.getBatchId(), router != null ? router.getRouterId() : Constants.UNKNOWN_ROUTER_ID);
                numberOfDataEventsInserted++;
                dataEventAdded = true;
            }
            Map<String, IBatchAlgorithm> batchAlgorithms = extensionService.getExtensionPointMap(IBatchAlgorithm.class);
            if (batchAlgorithms.get(context.getChannel().getBatchAlgorithm()).isBatchComplete(batch, dataMetaData, context)) {
                context.setNeedsCommitted(true);
            }
        }
    }
    context.incrementStat(System.currentTimeMillis() - ts, ChannelRouterContext.STAT_INSERT_DATA_EVENTS_MS);
    return numberOfDataEventsInserted;
}
Also used : IBatchAlgorithm(org.jumpmind.symmetric.route.IBatchAlgorithm) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) AuditTableDataRouter(org.jumpmind.symmetric.route.AuditTableDataRouter) LookupTableDataRouter(org.jumpmind.symmetric.route.LookupTableDataRouter) AbstractFileParsingRouter(org.jumpmind.symmetric.route.AbstractFileParsingRouter) ConfigurationChangedDataRouter(org.jumpmind.symmetric.route.ConfigurationChangedDataRouter) SubSelectDataRouter(org.jumpmind.symmetric.route.SubSelectDataRouter) FileSyncDataRouter(org.jumpmind.symmetric.route.FileSyncDataRouter) ColumnMatchDataRouter(org.jumpmind.symmetric.route.ColumnMatchDataRouter) Router(org.jumpmind.symmetric.model.Router) DefaultDataRouter(org.jumpmind.symmetric.route.DefaultDataRouter) BshDataRouter(org.jumpmind.symmetric.route.BshDataRouter) IDataRouter(org.jumpmind.symmetric.route.IDataRouter) DBFRouter(org.jumpmind.symmetric.route.DBFRouter) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Aggregations

OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)1 Router (org.jumpmind.symmetric.model.Router)1 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)1 AbstractFileParsingRouter (org.jumpmind.symmetric.route.AbstractFileParsingRouter)1 AuditTableDataRouter (org.jumpmind.symmetric.route.AuditTableDataRouter)1 BshDataRouter (org.jumpmind.symmetric.route.BshDataRouter)1 ColumnMatchDataRouter (org.jumpmind.symmetric.route.ColumnMatchDataRouter)1 ConfigurationChangedDataRouter (org.jumpmind.symmetric.route.ConfigurationChangedDataRouter)1 DBFRouter (org.jumpmind.symmetric.route.DBFRouter)1 DefaultDataRouter (org.jumpmind.symmetric.route.DefaultDataRouter)1 FileSyncDataRouter (org.jumpmind.symmetric.route.FileSyncDataRouter)1 IBatchAlgorithm (org.jumpmind.symmetric.route.IBatchAlgorithm)1 IDataRouter (org.jumpmind.symmetric.route.IDataRouter)1 LookupTableDataRouter (org.jumpmind.symmetric.route.LookupTableDataRouter)1 SubSelectDataRouter (org.jumpmind.symmetric.route.SubSelectDataRouter)1