Search in sources :

Example 1 with Channel

use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.

the class ConfigurationService method createDefaultChannels.

protected void createDefaultChannels() {
    Map<String, Channel> updatedDefaultChannels = new LinkedHashMap<String, Channel>();
    updatedDefaultChannels.put(Constants.CHANNEL_CONFIG, new Channel(Constants.CHANNEL_CONFIG, 0, 2000, 100, true, 0, true));
    if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
        updatedDefaultChannels.put(Constants.CHANNEL_RELOAD, new Channel(Constants.CHANNEL_RELOAD, 1, 10000, 100, true, 0, false, true, false));
    } else {
        updatedDefaultChannels.put(Constants.CHANNEL_RELOAD, new Channel(Constants.CHANNEL_RELOAD, 1, 1, 1, true, 0, false, true, false));
    }
    updatedDefaultChannels.put(Constants.CHANNEL_HEARTBEAT, new Channel(Constants.CHANNEL_HEARTBEAT, 2, 100, 100, true, 0, false));
    updatedDefaultChannels.put(Constants.CHANNEL_DEFAULT, new Channel(Constants.CHANNEL_DEFAULT, 99999, 1000, 100, true, 0, false));
    updatedDefaultChannels.put(Constants.CHANNEL_DYNAMIC, new Channel(Constants.CHANNEL_DYNAMIC, 99999, 1000, 100, true, 0, false));
    if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE)) {
        updatedDefaultChannels.put(Constants.CHANNEL_FILESYNC, new Channel(Constants.CHANNEL_FILESYNC, 3, 100, 100, true, 0, false, "nontransactional", false, true));
        updatedDefaultChannels.put(Constants.CHANNEL_FILESYNC_RELOAD, new Channel(Constants.CHANNEL_FILESYNC_RELOAD, 1, 100, 100, true, 0, false, "nontransactional", true, true));
    }
    this.defaultChannels = updatedDefaultChannels;
}
Also used : NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Channel(org.jumpmind.symmetric.model.Channel) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Channel

use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.

the class DataExtractorService method filterBatchesForExtraction.

private List<OutgoingBatch> filterBatchesForExtraction(OutgoingBatches batches, ChannelMap suspendIgnoreChannelsList) {
    if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE)) {
        List<Channel> fileSyncChannels = configurationService.getFileSyncChannels();
        for (Channel channel : fileSyncChannels) {
            batches.filterBatchesForChannel(channel);
        }
    }
    // We now have either our local suspend/ignore list, or the combined
    // remote send/ignore list and our local list (along with a
    // reservation, if we go this far...)
    // Now, we need to skip the suspended channels and ignore the
    // ignored ones by ultimately setting the status to ignored and
    // updating them.
    List<OutgoingBatch> ignoredBatches = batches.filterBatchesForChannels(suspendIgnoreChannelsList.getIgnoreChannels());
    // will be skipped in the future.
    for (OutgoingBatch batch : ignoredBatches) {
        batch.setStatus(OutgoingBatch.Status.OK);
        batch.incrementIgnoreCount();
        if (log.isDebugEnabled()) {
            log.debug("Batch {} is being ignored", batch.getBatchId());
        }
    }
    outgoingBatchService.updateOutgoingBatches(ignoredBatches);
    batches.filterBatchesForChannels(suspendIgnoreChannelsList.getSuspendChannels());
    // any other batches are loaded.
    if (parameterService.is(ParameterConstants.INITIAL_LOAD_BLOCK_CHANNELS, true)) {
        if (!batches.containsBatchesInError() && batches.containsLoadBatches()) {
            batches.removeNonLoadBatches();
        }
    }
    return batches.getBatches();
}
Also used : NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Channel(org.jumpmind.symmetric.model.Channel) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch)

Example 3 with Channel

use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.

the class DataExtractorService method sendOutgoingBatch.

protected OutgoingBatch sendOutgoingBatch(ProcessInfo processInfo, Node targetNode, OutgoingBatch currentBatch, boolean isRetry, IDataWriter dataWriter, BufferedWriter writer, ExtractMode mode) {
    if (currentBatch.getStatus() != Status.OK || ExtractMode.EXTRACT_ONLY == mode) {
        currentBatch.setSentCount(currentBatch.getSentCount() + 1);
        long ts = System.currentTimeMillis();
        IStagedResource extractedBatch = getStagedResource(currentBatch);
        if (extractedBatch != null) {
            if (mode == ExtractMode.FOR_SYM_CLIENT && writer != null) {
                if (!isRetry && parameterService.is(ParameterConstants.OUTGOING_BATCH_COPY_TO_INCOMING_STAGING) && !parameterService.is(ParameterConstants.NODE_OFFLINE, false)) {
                    ISymmetricEngine targetEngine = AbstractSymmetricEngine.findEngineByUrl(targetNode.getSyncUrl());
                    if (targetEngine != null && extractedBatch.isFileResource()) {
                        try {
                            Node sourceNode = nodeService.findIdentity();
                            IStagedResource targetResource = targetEngine.getStagingManager().create(Constants.STAGING_CATEGORY_INCOMING, Batch.getStagedLocation(false, sourceNode.getNodeId()), currentBatch.getBatchId());
                            SymmetricUtils.copyFile(extractedBatch.getFile(), targetResource.getFile());
                            targetResource.setState(State.DONE);
                            isRetry = true;
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
                Channel channel = configurationService.getChannel(currentBatch.getChannelId());
                DataContext ctx = new DataContext();
                transferFromStaging(mode, BatchType.EXTRACT, currentBatch, isRetry, extractedBatch, writer, ctx, channel.getMaxKBytesPerSecond());
            } else {
                IDataReader dataReader = new ProtocolDataReader(BatchType.EXTRACT, currentBatch.getNodeId(), extractedBatch);
                DataContext ctx = new DataContext();
                ctx.put(Constants.DATA_CONTEXT_TARGET_NODE, targetNode);
                ctx.put(Constants.DATA_CONTEXT_SOURCE_NODE, nodeService.findIdentity());
                new DataProcessor(dataReader, new ProcessInfoDataWriter(dataWriter, processInfo), "send from stage").process(ctx);
                if (dataReader.getStatistics().size() > 0) {
                    Statistics stats = dataReader.getStatistics().values().iterator().next();
                    statisticManager.incrementDataSent(currentBatch.getChannelId(), stats.get(DataReaderStatistics.READ_RECORD_COUNT));
                    long byteCount = stats.get(DataReaderStatistics.READ_BYTE_COUNT);
                    statisticManager.incrementDataBytesSent(currentBatch.getChannelId(), byteCount);
                } else {
                    log.warn("Could not find recorded statistics for batch {}", currentBatch.getNodeBatchId());
                }
            }
        } else {
            throw new IllegalStateException(String.format("Could not find the staged resource for batch %s", currentBatch.getNodeBatchId()));
        }
        currentBatch = requeryIfEnoughTimeHasPassed(ts, currentBatch);
    }
    return currentBatch;
}
Also used : IDataReader(org.jumpmind.symmetric.io.data.IDataReader) Node(org.jumpmind.symmetric.model.Node) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Channel(org.jumpmind.symmetric.model.Channel) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) DataProcessor(org.jumpmind.symmetric.io.data.DataProcessor) Statistics(org.jumpmind.util.Statistics) DataReaderStatistics(org.jumpmind.symmetric.io.data.reader.DataReaderStatistics) CancellationException(java.util.concurrent.CancellationException) SymmetricException(org.jumpmind.symmetric.SymmetricException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ProtocolException(org.jumpmind.symmetric.io.data.ProtocolException) TimeoutException(java.util.concurrent.TimeoutException) IoException(org.jumpmind.exception.IoException) DataContext(org.jumpmind.symmetric.io.data.DataContext) IStagedResource(org.jumpmind.symmetric.io.stage.IStagedResource) ProtocolDataReader(org.jumpmind.symmetric.io.data.reader.ProtocolDataReader) ProcessInfoDataWriter(org.jumpmind.symmetric.model.ProcessInfoDataWriter)

Example 4 with Channel

use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.

the class DataService method insertFileSyncBatchForReload.

private void insertFileSyncBatchForReload(Node targetNode, long loadId, String createBy, boolean transactional, ISqlTransaction transaction, ProcessInfo processInfo) {
    if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE) && !Constants.DEPLOYMENT_TYPE_REST.equals(targetNode.getDeploymentType())) {
        ITriggerRouterService triggerRouterService = engine.getTriggerRouterService();
        IFileSyncService fileSyncService = engine.getFileSyncService();
        if (fileSyncService.getFileTriggerRoutersForCurrentNode().size() > 0) {
            TriggerHistory fileSyncSnapshotHistory = triggerRouterService.findTriggerHistory(null, null, TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT));
            String routerid = triggerRouterService.buildSymmetricTableRouterId(fileSyncSnapshotHistory.getTriggerId(), parameterService.getNodeGroupId(), targetNode.getNodeGroupId());
            TriggerRouter fileSyncSnapshotTriggerRouter = triggerRouterService.getTriggerRouterForCurrentNode(fileSyncSnapshotHistory.getTriggerId(), routerid, true);
            List<TriggerHistory> triggerHistories = Arrays.asList(fileSyncSnapshotHistory);
            List<TriggerRouter> triggerRouters = Arrays.asList(fileSyncSnapshotTriggerRouter);
            Map<Integer, List<TriggerRouter>> triggerRoutersByHistoryId = new HashMap<Integer, List<TriggerRouter>>();
            triggerRoutersByHistoryId.put(fileSyncSnapshotHistory.getTriggerHistoryId(), triggerRouters);
            if (parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
                insertLoadBatchesForReload(targetNode, loadId, createBy, triggerHistories, triggerRoutersByHistoryId, transactional, transaction, null, processInfo);
            } else {
                List<Channel> channels = engine.getConfigurationService().getFileSyncChannels();
                for (Channel channel : channels) {
                    if (channel.isReloadFlag()) {
                        insertReloadEvent(transaction, targetNode, fileSyncSnapshotTriggerRouter, fileSyncSnapshotHistory, "reload_channel_id='" + channel.getChannelId() + "'", true, loadId, createBy, Status.NE, channel.getChannelId());
                        if (!transactional) {
                            transaction.commit();
                        }
                    }
                }
            }
        }
    }
}
Also used : ITriggerRouterService(org.jumpmind.symmetric.service.ITriggerRouterService) HashMap(java.util.HashMap) Channel(org.jumpmind.symmetric.model.Channel) IFileSyncService(org.jumpmind.symmetric.service.IFileSyncService) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with Channel

use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.

the class FileSyncService method isWaitForExtractionRequired.

private boolean isWaitForExtractionRequired(OutgoingBatch currentBatch, IStagedResource previouslyStagedResource) {
    Channel channel = this.engine.getConfigurationService().getChannel(currentBatch.getChannelId());
    if (previouslyStagedResource == null && channel.isReloadFlag() && parameterService.is(ParameterConstants.INITIAL_LOAD_USE_EXTRACT_JOB)) {
        if (currentBatch.getStatus() == OutgoingBatch.Status.RQ) {
            // if this is a reload that isn't extracted yet, we need to defer to the extract job.
            log.info("Batch needs to be extracted by the extact job {}", currentBatch.getNodeBatchId());
        } else {
            // it's possible there was an error and staging was cleared, so we need to re-request extraction here.
            log.info("Batch has status of '{}' but is not extracted. Requesting re-extract for batch: {}", currentBatch.getStatus(), currentBatch.getNodeBatchId());
            engine.getDataExtractorService().resetExtractRequest(currentBatch);
        }
        return true;
    } else {
        return false;
    }
}
Also used : Channel(org.jumpmind.symmetric.model.Channel)

Aggregations

Channel (org.jumpmind.symmetric.model.Channel)19 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)8 ArrayList (java.util.ArrayList)4 Node (org.jumpmind.symmetric.model.Node)4 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)4 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)3 HashMap (java.util.HashMap)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)2 SymmetricException (org.jumpmind.symmetric.SymmetricException)2 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)2 IStagedResource (org.jumpmind.symmetric.io.stage.IStagedResource)2 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1