use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NodeService method insertNodeSecurity.
public void insertNodeSecurity(String id) {
String password = extensionService.getExtensionPoint(INodeIdCreator.class).generatePassword(new Node(id, null, null));
password = filterPasswordOnSaveIfNeeded(password);
sqlTemplate.update(getSql("insertNodeSecuritySql"), new Object[] { id, password, null });
flushNodeAuthorizedCache();
}
use of org.jumpmind.symmetric.model.Node 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.Node in project symmetric-ds by JumpMind.
the class NodeService method findAllNodesAsMap.
public Map<String, Node> findAllNodesAsMap() {
List<Node> nodes = findAllNodes();
Map<String, Node> nodeMap = new HashMap<String, Node>(nodes.size());
for (Node node : nodes) {
nodeMap.put(node.getNodeId(), node);
}
return nodeMap;
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NodeService method getRootNetworkedNode.
public NetworkedNode getRootNetworkedNode() {
Map<String, Node> nodes = findAllNodesAsMap();
Map<String, NetworkedNode> leaves = new HashMap<String, NetworkedNode>(nodes.size());
NetworkedNode nodeLeaf = null;
for (Node node : nodes.values()) {
nodeLeaf = leaves.get(node.getNodeId());
if (nodeLeaf == null) {
nodeLeaf = new NetworkedNode(node);
nodeLeaf.addParents(nodes, leaves);
leaves.put(node.getNodeId(), nodeLeaf);
}
}
nodeLeaf = leaves.get(findIdentityNodeId());
if (nodeLeaf != null) {
NetworkedNode root = nodeLeaf.getRoot();
root.setAllNetworkedNodes(leaves);
return root;
} else {
return null;
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NodeService method findOfflineNodes.
public List<Node> findOfflineNodes(long minutesOffline) {
List<Node> offlineNodeList = new ArrayList<Node>();
Node myNode = findIdentity();
if (myNode != null) {
long offlineNodeDetectionMillis = minutesOffline * 60 * 1000;
List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"));
for (Row node : list) {
String nodeId = node.getString("node_id");
Date time = node.getDateTime("heartbeat_time");
String offset = node.getString("timezone_offset");
// Take the timezone of the client node into account when
// checking the hearbeat time.
Date clientNodeCurrentTime = null;
if (offset != null) {
clientNodeCurrentTime = AppUtils.getLocalDateForOffset(offset);
} else {
clientNodeCurrentTime = new Date();
}
long cutOffTimeMillis = clientNodeCurrentTime.getTime() - offlineNodeDetectionMillis;
if (time == null || time.getTime() < cutOffTimeMillis) {
offlineNodeList.add(findNode(nodeId));
}
}
}
return offlineNodeList;
}
Aggregations