use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.
the class FileSyncService method getBatchesToProcess.
protected List<OutgoingBatch> getBatchesToProcess(Node targetNode) {
List<OutgoingBatch> batchesToProcess = new ArrayList<OutgoingBatch>();
List<Channel> fileSyncChannels = engine.getConfigurationService().getFileSyncChannels();
OutgoingBatches batches = engine.getOutgoingBatchService().getOutgoingBatches(targetNode.getNodeId(), false);
for (Channel channel : fileSyncChannels) {
batchesToProcess.addAll(batches.filterBatchesForChannel(channel));
}
return batchesToProcess;
}
use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.
the class NodeCommunicationService method filterForChannelThreading.
protected List<NodeCommunication> filterForChannelThreading(List<Node> nodesToCommunicateWith) {
List<NodeCommunication> nodeCommunications = new ArrayList<NodeCommunication>();
for (Node node : nodesToCommunicateWith) {
if (node.isVersionGreaterThanOrEqualTo(3, 8, 0)) {
Set<String> channelThreads = new HashSet<String>();
for (Channel channel : configurationService.getChannels(false).values()) {
if (!channelThreads.contains(channel.getQueue())) {
NodeCommunication nodeCommunication = new NodeCommunication();
nodeCommunication.setNodeId(node.getNodeId());
nodeCommunication.setQueue(channel.getQueue());
nodeCommunication.setNode(node);
nodeCommunications.add(nodeCommunication);
channelThreads.add(channel.getQueue());
}
}
} else {
NodeCommunication nodeCommunication = new NodeCommunication();
nodeCommunication.setNodeId(node.getNodeId());
nodeCommunication.setNode(node);
nodeCommunications.add(nodeCommunication);
}
}
return nodeCommunications;
}
use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.
the class NodeCommunicationService method parseQueueToBatchCounts.
@Override
public Map<String, Integer> parseQueueToBatchCounts(String channelToBatchCountsString) {
Map<String, Integer> channelsToBatchCount = new HashMap<String, Integer>();
// åchannelName:4,anotherChannelName:6
String[] channelToBatchCounts = channelToBatchCountsString.split(",");
for (String channelToBatchCount : channelToBatchCounts) {
// anotherQueueName:6
String[] queueToBatchCountSplit = channelToBatchCount.split(":");
String queueName = queueToBatchCountSplit[0];
int batchCount = Integer.parseInt(queueToBatchCountSplit[1].trim());
channelsToBatchCount.put(queueName, batchCount);
}
// Convert channels to queues
Map<String, Channel> channels = configurationService.getChannels(false);
Map<String, Integer> queuesToBatchCount = new HashMap<String, Integer>();
for (String channelId : channelsToBatchCount.keySet()) {
Channel channel = channels.get(channelId);
if (channel == null) {
log.warn("Unknown channel: '" + channelId + "'");
continue;
}
String queue = channel.getQueue();
if (!queuesToBatchCount.containsKey(queue)) {
queuesToBatchCount.put(queue, channelsToBatchCount.get(channelId));
} else {
queuesToBatchCount.put(queue, queuesToBatchCount.get(queue) + channelsToBatchCount.get(channelId));
}
}
return queuesToBatchCount;
}
use of org.jumpmind.symmetric.model.Channel in project symmetric-ds by JumpMind.
the class TriggerRouterService method updateOrCreateDatabaseTriggers.
protected void updateOrCreateDatabaseTriggers(Trigger trigger, Table table, StringBuilder sqlBuffer, boolean force, boolean verifyInDatabase, List<TriggerHistory> activeTriggerHistories) {
TriggerHistory newestHistory = null;
TriggerReBuildReason reason = TriggerReBuildReason.NEW_TRIGGERS;
String errorMessage = null;
if (verifyInDatabase) {
Channel channel = configurationService.getChannel(trigger.getChannelId());
if (channel == null) {
errorMessage = String.format("Trigger %s had an unrecognized channel_id of '%s'. Please check to make sure the channel exists. Creating trigger on the '%s' channel", trigger.getTriggerId(), trigger.getChannelId(), Constants.CHANNEL_DEFAULT);
log.error(errorMessage);
trigger.setChannelId(Constants.CHANNEL_DEFAULT);
}
}
try {
boolean foundPk = false;
Column[] columns = trigger.filterExcludedAndIncludedColumns(table.getColumns());
for (Column column : columns) {
foundPk |= column.isPrimaryKey();
if (foundPk) {
break;
}
}
if (!foundPk) {
table = platform.makeAllColumnsPrimaryKeys(table);
}
TriggerHistory latestHistoryBeforeRebuild = getNewestTriggerHistoryForTrigger(trigger.getTriggerId(), trigger.isSourceCatalogNameWildCarded() ? table.getCatalog() : trigger.getSourceCatalogName(), trigger.isSourceSchemaNameWildCarded() ? table.getSchema() : trigger.getSourceSchemaName(), trigger.isSourceTableNameWildCarded() ? table.getName() : trigger.getSourceTableName());
boolean forceRebuildOfTriggers = false;
if (latestHistoryBeforeRebuild == null) {
reason = TriggerReBuildReason.NEW_TRIGGERS;
forceRebuildOfTriggers = true;
} else if (table.calculateTableHashcode() != latestHistoryBeforeRebuild.getTableHash()) {
reason = TriggerReBuildReason.TABLE_SCHEMA_CHANGED;
forceRebuildOfTriggers = true;
} else if (trigger.hasChangedSinceLastTriggerBuild(latestHistoryBeforeRebuild.getCreateTime()) || trigger.toHashedValue() != latestHistoryBeforeRebuild.getTriggerRowHash()) {
reason = TriggerReBuildReason.TABLE_SYNC_CONFIGURATION_CHANGED;
forceRebuildOfTriggers = true;
} else if (symmetricDialect.getTriggerTemplate().toHashedValue() != latestHistoryBeforeRebuild.getTriggerTemplateHash()) {
reason = TriggerReBuildReason.TRIGGER_TEMPLATE_CHANGED;
forceRebuildOfTriggers = true;
} else if (force) {
reason = TriggerReBuildReason.FORCED;
forceRebuildOfTriggers = true;
}
boolean supportsTriggers = symmetricDialect.getPlatform().getDatabaseInfo().isTriggersSupported();
newestHistory = rebuildTriggerIfNecessary(sqlBuffer, forceRebuildOfTriggers, trigger, DataEventType.INSERT, reason, latestHistoryBeforeRebuild, null, trigger.isSyncOnInsert() && supportsTriggers, table, activeTriggerHistories);
newestHistory = rebuildTriggerIfNecessary(sqlBuffer, forceRebuildOfTriggers, trigger, DataEventType.UPDATE, reason, latestHistoryBeforeRebuild, newestHistory, trigger.isSyncOnUpdate() && supportsTriggers, table, activeTriggerHistories);
newestHistory = rebuildTriggerIfNecessary(sqlBuffer, forceRebuildOfTriggers, trigger, DataEventType.DELETE, reason, latestHistoryBeforeRebuild, newestHistory, trigger.isSyncOnDelete() && supportsTriggers, table, activeTriggerHistories);
if (latestHistoryBeforeRebuild != null && newestHistory != null) {
inactivateTriggerHistory(latestHistoryBeforeRebuild);
}
if (newestHistory != null) {
synchronized (activeTriggerHistories) {
activeTriggerHistories.add(newestHistory);
}
newestHistory.setErrorMessage(errorMessage);
if (parameterService.is(ParameterConstants.AUTO_SYNC_TRIGGERS)) {
for (ITriggerCreationListener l : extensionService.getExtensionPointList(ITriggerCreationListener.class)) {
l.triggerCreated(trigger, newestHistory);
}
}
}
} catch (Exception ex) {
log.error(String.format("Failed to create triggers for %s", trigger.qualifiedSourceTableName()), ex);
if (newestHistory != null) {
// Make sure all the triggers are removed from the
// table
symmetricDialect.removeTrigger(null, trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), newestHistory.getNameForInsertTrigger(), trigger.getSourceTableName());
symmetricDialect.removeTrigger(null, trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), newestHistory.getNameForUpdateTrigger(), trigger.getSourceTableName());
symmetricDialect.removeTrigger(null, trigger.getSourceCatalogName(), trigger.getSourceSchemaName(), newestHistory.getNameForDeleteTrigger(), trigger.getSourceTableName());
}
for (ITriggerCreationListener l : extensionService.getExtensionPointList(ITriggerCreationListener.class)) {
l.triggerFailed(trigger, ex);
}
}
}
Aggregations