use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NodeCommunicationService method getNodesToCommunicateWithOffline.
protected List<Node> getNodesToCommunicateWithOffline(CommunicationType communicationType) {
List<Node> nodesToCommunicateWith = null;
if (parameterService.is(ParameterConstants.NODE_OFFLINE) || (communicationType.equals(CommunicationType.PULL) && parameterService.is(ParameterConstants.NODE_OFFLINE_INCOMING_ACCEPT_ALL))) {
if (communicationType.equals(CommunicationType.PUSH)) {
nodesToCommunicateWith = nodeService.findTargetNodesFor(NodeGroupLinkAction.W);
nodesToCommunicateWith.addAll(nodeService.findNodesToPushTo());
} else if (communicationType.equals(CommunicationType.PULL)) {
nodesToCommunicateWith = nodeService.findSourceNodesFor(NodeGroupLinkAction.P);
nodesToCommunicateWith.addAll(nodeService.findNodesToPull());
}
} else {
List<DatabaseParameter> parms = parameterService.getOfflineNodeParameters();
nodesToCommunicateWith = new ArrayList<Node>(parms.size());
if (parms.size() > 0) {
List<Node> sourceNodes = null;
if (communicationType.equals(CommunicationType.PUSH)) {
sourceNodes = nodeService.findTargetNodesFor(NodeGroupLinkAction.W);
sourceNodes.addAll(nodeService.findNodesToPushTo());
} else if (communicationType.equals(CommunicationType.PULL)) {
sourceNodes = nodeService.findSourceNodesFor(NodeGroupLinkAction.P);
sourceNodes.addAll(nodeService.findNodesToPull());
}
if (sourceNodes != null && sourceNodes.size() > 0) {
for (DatabaseParameter parm : parms) {
for (Node node : sourceNodes) {
if ((parm.getNodeGroupId().equals(ParameterConstants.ALL) || parm.getNodeGroupId().equals(node.getNodeGroupId()) && (parm.getExternalId().equals(ParameterConstants.ALL) || parm.getExternalId().equals(node.getExternalId())))) {
nodesToCommunicateWith.add(node);
}
}
}
}
}
}
return nodesToCommunicateWith;
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class OfflinePushService method pushToNode.
private void pushToNode(Node remote, RemoteNodeStatus status) {
Node identity = nodeService.findIdentity();
FileOutgoingTransport transport = null;
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(identity.getNodeId(), status.getChannelId(), remote.getNodeId(), ProcessType.OFFLINE_PUSH));
List<OutgoingBatch> extractedBatches = null;
try {
transport = (FileOutgoingTransport) transportManager.getPushTransport(remote, identity, null, null);
extractedBatches = dataExtractorService.extract(processInfo, remote, status.getChannelId(), transport);
if (extractedBatches.size() > 0) {
log.info("Offline push data written for {} at {}", remote, transport.getOutgoingDir());
List<BatchAck> batchAcks = readAcks(extractedBatches, transport, transportManager, acknowledgeService);
status.updateOutgoingStatus(extractedBatches, batchAcks);
}
if (processInfo.getStatus() != Status.ERROR) {
processInfo.setStatus(Status.OK);
}
} catch (Exception ex) {
processInfo.setStatus(Status.ERROR);
log.error("Failed to write offline file", ex);
} finally {
transport.close();
transport.complete(processInfo.getStatus() == Status.OK);
}
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class OfflinePushService method execute.
public void execute(NodeCommunication nodeCommunication, RemoteNodeStatus status) {
Node node = nodeCommunication.getNode();
long batchesProcessedCount = 0;
do {
batchesProcessedCount = status.getBatchesProcessed();
log.debug("Offline push requested for {}", node);
pushToNode(node, status);
if (!status.failed() && status.getBatchesProcessed() > batchesProcessedCount) {
log.info("Offline push data written for {}. {} data and {} batches were processed", new Object[] { node, status.getDataProcessed(), status.getBatchesProcessed() });
} else if (status.failed()) {
log.info("There was a failure while writing offline push data for {}. {} data and {} batches were processed", new Object[] { node, status.getDataProcessed(), status.getBatchesProcessed() });
}
log.debug("Offline push completed for {}", node);
} while (!status.failed() && status.getBatchesProcessed() > batchesProcessedCount);
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NodeService method findLastHeartbeats.
public Map<String, Date> findLastHeartbeats() {
Map<String, Date> dates = new HashMap<String, Date>();
Node myNode = findIdentity();
if (myNode != null) {
List<Row> list = sqlTemplate.query(getSql("findNodeHeartbeatsSql"));
for (Row node : list) {
String nodeId = node.getString("node_id");
Date time = node.getDateTime("heartbeat_time");
dates.put(nodeId, time);
}
}
return dates;
}
use of org.jumpmind.symmetric.model.Node in project symmetric-ds by JumpMind.
the class NodeService method findNodesThatOriginatedFromNodeId.
public Set<Node> findNodesThatOriginatedFromNodeId(String originalNodeId, boolean recursive) {
Set<Node> all = new HashSet<Node>();
List<Node> list = sqlTemplate.query(getSql("selectNodePrefixSql", "findNodesCreatedByMeSql"), new NodeRowMapper(), originalNodeId);
if (list.size() > 0) {
all.addAll(list);
if (recursive) {
for (Node node : list) {
all.addAll(findNodesThatOriginatedFromNodeId(node.getNodeId()));
}
}
}
return all;
}
Aggregations