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;
}
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();
}
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;
}
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();
}
}
}
}
}
}
}
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;
}
}
Aggregations