Search in sources :

Example 1 with NodeCommunication

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

the class NodeCommunicationService method updateBatchToSendCounts.

@Override
public void updateBatchToSendCounts(String nodeId, Map<String, Integer> batchesCountToQueues) {
    List<NodeCommunication> nodeCommunications = this.find(CommunicationType.PULL);
    List<NodeCommunication> updatedNodeCommunications = new ArrayList<NodeCommunication>();
    for (String queue : batchesCountToQueues.keySet()) {
        NodeCommunication match = null;
        for (int i = 0; i < nodeCommunications.size(); i++) {
            NodeCommunication nodeCommunication = nodeCommunications.get(i);
            if (nodeCommunication.getNodeId().equals(nodeId) && nodeCommunication.getQueue().equals(queue)) {
                match = nodeCommunication;
                break;
            }
        }
        if (match == null) {
            NodeCommunication newNodeCommunication = new NodeCommunication();
            newNodeCommunication.setCommunicationType(CommunicationType.PULL);
            newNodeCommunication.setNodeId(nodeId);
            newNodeCommunication.setQueue(queue);
            newNodeCommunication.setBatchToSendCount(batchesCountToQueues.get(queue));
            updatedNodeCommunications.add(newNodeCommunication);
        } else {
            match.setBatchToSendCount(batchesCountToQueues.get(queue));
            updatedNodeCommunications.add(match);
        }
    }
    for (NodeCommunication nodeCommunication : updatedNodeCommunications) {
        save(nodeCommunication, false);
    }
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) ArrayList(java.util.ArrayList)

Example 2 with NodeCommunication

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

the class NodeCommunicationService method persistToTableForSnapshot.

@Override
public synchronized void persistToTableForSnapshot() {
    sqlTemplate.update(getSql("deleteSql"));
    Collection<Map<String, NodeCommunication>> values = lockCache.values();
    for (Map<String, NodeCommunication> map : values) {
        Collection<NodeCommunication> nodeCommies = map.values();
        for (NodeCommunication nodeCommunication : nodeCommies) {
            save(nodeCommunication, true);
        }
    }
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with NodeCommunication

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

the class NodeCommunicationService method find.

public NodeCommunication find(String nodeId, String queue, CommunicationType communicationType) {
    NodeCommunication lock = null;
    if (clusterService.isClusteringEnabled()) {
        lock = sqlTemplate.queryForObject(getSql("selectNodeCommunicationByNodeAndChannelSql"), new NodeCommunicationMapper(), nodeId, queue, communicationType.name());
    } else {
        Map<String, NodeCommunication> locks = lockCache.get(communicationType);
        lock = locks.get(nodeId + "-" + queue);
    }
    if (lock == null) {
        lock = new NodeCommunication();
        lock.setNodeId(nodeId);
        lock.setCommunicationType(communicationType);
        lock.setQueue(queue);
        save(lock, false);
    }
    return lock;
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication)

Example 4 with NodeCommunication

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

the class OfflinePullService method pullData.

public synchronized RemoteNodeStatuses pullData(boolean force) {
    RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
    Node identity = nodeService.findIdentity();
    if (identity != null && identity.isSyncEnabled()) {
        if (force || !clusterService.isInfiniteLocked(ClusterConstants.OFFLINE_PULL)) {
            List<NodeCommunication> nodes = nodeCommunicationService.list(CommunicationType.OFFLN_PULL);
            int availableThreads = nodeCommunicationService.getAvailableThreads(CommunicationType.OFFLN_PULL);
            for (NodeCommunication nodeCommunication : nodes) {
                if (availableThreads > 0) {
                    if (nodeCommunicationService.execute(nodeCommunication, statuses, this)) {
                        availableThreads--;
                    }
                }
            }
        } else {
            log.debug("Did not run the offline pull process because it has been stopped");
        }
    }
    return statuses;
}
Also used : RemoteNodeStatuses(org.jumpmind.symmetric.model.RemoteNodeStatuses) NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) Node(org.jumpmind.symmetric.model.Node)

Example 5 with NodeCommunication

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

the class FileSyncExtractorService method queue.

@Override
protected void queue(String nodeId, String queue, RemoteNodeStatuses statuses) {
    if (parameterService.is(ParameterConstants.FILE_SYNC_ENABLE)) {
        final NodeCommunication.CommunicationType TYPE = NodeCommunication.CommunicationType.FILE_XTRCT;
        int availableThreads = nodeCommunicationService.getAvailableThreads(TYPE);
        NodeCommunication lock = nodeCommunicationService.find(nodeId, queue, TYPE);
        if (availableThreads > 0) {
            nodeCommunicationService.execute(lock, statuses, this);
        }
    }
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) CommunicationType(org.jumpmind.symmetric.model.NodeCommunication.CommunicationType)

Aggregations

NodeCommunication (org.jumpmind.symmetric.model.NodeCommunication)13 Node (org.jumpmind.symmetric.model.Node)7 RemoteNodeStatuses (org.jumpmind.symmetric.model.RemoteNodeStatuses)5 ArrayList (java.util.ArrayList)2 CommunicationType (org.jumpmind.symmetric.model.NodeCommunication.CommunicationType)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)1 Channel (org.jumpmind.symmetric.model.Channel)1 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)1 INodeCommunicationService (org.jumpmind.symmetric.service.INodeCommunicationService)1