Search in sources :

Example 16 with Channel

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;
}
Also used : Channel(org.jumpmind.symmetric.model.Channel) ArrayList(java.util.ArrayList) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches)

Example 17 with Channel

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;
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) Node(org.jumpmind.symmetric.model.Node) Channel(org.jumpmind.symmetric.model.Channel) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 18 with Channel

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Channel(org.jumpmind.symmetric.model.Channel)

Example 19 with Channel

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);
        }
    }
}
Also used : Column(org.jumpmind.db.model.Column) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) Channel(org.jumpmind.symmetric.model.Channel) ITriggerCreationListener(org.jumpmind.symmetric.config.ITriggerCreationListener) TriggerReBuildReason(org.jumpmind.symmetric.model.TriggerReBuildReason) SymmetricException(org.jumpmind.symmetric.SymmetricException) ExecutionException(java.util.concurrent.ExecutionException)

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