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