Search in sources :

Example 11 with NodeCommunication

use of org.jumpmind.symmetric.model.NodeCommunication 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 12 with NodeCommunication

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

the class NodeCommunicationService method list.

public List<NodeCommunication> list(CommunicationType communicationType) {
    initialize();
    List<NodeCommunication> communicationRows = find(communicationType);
    List<Node> nodesToCommunicateWith = null;
    switch(communicationType) {
        case PULL:
        case FILE_PULL:
            nodesToCommunicateWith = removeOfflineNodes(nodeService.findNodesToPull());
            break;
        case FILE_PUSH:
        case PUSH:
            nodesToCommunicateWith = removeOfflineNodes(nodeService.findNodesToPushTo());
            break;
        case OFFLN_PUSH:
        case OFF_FSPUSH:
            nodesToCommunicateWith = getNodesToCommunicateWithOffline(CommunicationType.PUSH);
            break;
        case OFFLN_PULL:
        case OFF_FSPULL:
            nodesToCommunicateWith = getNodesToCommunicateWithOffline(CommunicationType.PULL);
            break;
        default:
            nodesToCommunicateWith = new ArrayList<Node>(0);
            break;
    }
    List<NodeCommunication> nodesToCommunicateWithList = filterForChannelThreading(nodesToCommunicateWith);
    for (NodeCommunication nodeToCommunicateWith : nodesToCommunicateWithList) {
        NodeCommunication comm = null;
        for (NodeCommunication nodeCommunication : communicationRows) {
            if (nodeCommunication.getIdentifier().equals(nodeToCommunicateWith.getIdentifier())) {
                comm = nodeCommunication;
                break;
            }
        }
        if (comm == null) {
            comm = new NodeCommunication();
            comm.setNodeId(nodeToCommunicateWith.getNodeId());
            comm.setQueue(nodeToCommunicateWith.getQueue());
            comm.setCommunicationType(communicationType);
            save(comm, false);
            communicationRows.add(comm);
        }
        comm.setNode(nodeToCommunicateWith.getNode());
    }
    Iterator<NodeCommunication> it = communicationRows.iterator();
    while (it.hasNext()) {
        NodeCommunication nodeCommunication = it.next();
        Node node = null;
        for (NodeCommunication nodeToCommunicateWith : nodesToCommunicateWithList) {
            if (nodeCommunication.getNodeId().equals(nodeToCommunicateWith.getNodeId())) {
                node = nodeToCommunicateWith.getNode();
                break;
            }
        }
        if (node == null) {
            delete(nodeCommunication);
            it.remove();
        }
    }
    if (communicationType == CommunicationType.PULL || communicationType == CommunicationType.FILE_PULL) {
        communicationRows = removeNodesWithNoBatchesToSend(communicationRows);
    }
    return communicationRows;
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) Node(org.jumpmind.symmetric.model.Node)

Example 13 with NodeCommunication

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

the class NodeCommunicationService method sortNodeCommunications.

protected void sortNodeCommunications(List<NodeCommunication> list, final CommunicationType communicationType) {
    final Date FAR_PAST_DATE = new Date(0);
    final Date FAR_FUTURE_DATE = new Date(Long.MAX_VALUE);
    Collections.sort(list, new Comparator<NodeCommunication>() {

        public int compare(NodeCommunication o1, NodeCommunication o2) {
            // 1. Node priority
            int compareTo = Integer.compare(o1.getNodePriority(), o2.getNodePriority());
            if (compareTo != 0) {
                return compareTo;
            }
            // 2. If it's a pull, look at batch_to_send_count.
            if (CommunicationType.isPullType(communicationType)) {
                compareTo = Long.compare(o1.getBatchToSendCount(), o2.getBatchToSendCount());
                if (compareTo != 0) {
                    return compareTo;
                }
            }
            // 3. last_lock_time.                
            Date o1LockTime = o1.getLastLockTime() != null ? o1.getLastLockTime() : FAR_PAST_DATE;
            Date o2LockTime = o2.getLastLockTime() != null ? o2.getLastLockTime() : FAR_FUTURE_DATE;
            compareTo = o1LockTime.compareTo(o2LockTime);
            if (compareTo != 0) {
                return compareTo;
            }
            return compareTo;
        }
    });
}
Also used : NodeCommunication(org.jumpmind.symmetric.model.NodeCommunication) Date(java.util.Date)

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