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