use of org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount in project symmetric-ds by JumpMind.
the class PushService method push.
public synchronized RemoteNodeStatuses push(boolean force) {
IConfigurationService configurationService = engine.getConfigurationService();
IOutgoingBatchService outgoingBatchService = engine.getOutgoingBatchService();
INodeService nodeService = engine.getNodeService();
IClusterService clusterService = engine.getClusterService();
int availableThreadPairs = parameterService.getInt(ParameterConstants.PUSH_THREAD_COUNT_PER_SERVER);
long minimumPeriodBetweenPushesMs = parameterService.getLong(ParameterConstants.PUSH_MINIMUM_PERIOD_MS, -1);
RemoteNodeStatuses statuses = new RemoteNodeStatuses(configurationService.getChannels(false));
Node identityNode = nodeService.findIdentity(false);
if (identityNode != null && identityNode.isSyncEnabled()) {
List<NodeHost> hosts = nodeService.findNodeHosts(identityNode.getNodeId());
int clusterInstanceCount = hosts != null && hosts.size() > 0 ? hosts.size() : 1;
NodeSecurity identitySecurity = nodeService.findNodeSecurity(identityNode.getNodeId());
if (identitySecurity != null && (force || !clusterService.isInfiniteLocked(ClusterConstants.PUSH))) {
Iterator<OutgoingBatchByNodeChannelCount> nodeChannels = outgoingBatchService.getOutgoingBatchByNodeChannelCount(availableThreadPairs * clusterInstanceCount, NodeGroupLinkAction.P, true).iterator();
// based on percentage
while (nodeChannels.hasNext() && pushWorkersWorking.size() < availableThreadPairs) {
OutgoingBatchByNodeChannelCount batchCount = nodeChannels.next();
String nodeId = batchCount.getNodeId();
String channelId = batchCount.getChannelId();
Node remoteNode = nodeService.findNode(nodeId);
NodeChannel nodeChannel = configurationService.getNodeChannel(channelId, nodeId, false);
if (nodeChannel != null && !nodeChannel.isFileSyncFlag() && !pushWorkersWorking.contains(nodeChannel)) {
boolean meetsMinimumTime = true;
// TODO error backoff logic
if (minimumPeriodBetweenPushesMs > 0 && nodeChannel.getLastExtractTime() != null && (System.currentTimeMillis() - nodeChannel.getLastExtractTime().getTime()) < minimumPeriodBetweenPushesMs) {
meetsMinimumTime = false;
}
if (meetsMinimumTime && clusterService.lockNodeChannel(ClusterConstants.PUSH, nodeId, channelId)) {
NodeChannelExtractForPushWorker worker = new NodeChannelExtractForPushWorker(remoteNode, identityNode, identitySecurity, nodeChannel, statuses.add(nodeId, channelId));
pushWorkersWorking.add(nodeChannel);
nodeChannelExtractForPushWorker.execute(worker);
}
}
}
}
}
return statuses;
}
use of org.jumpmind.symmetric.model.OutgoingBatchByNodeChannelCount in project symmetric-ds by JumpMind.
the class OutgoingBatchService method getOutgoingBatchByNodeChannelCount.
public List<OutgoingBatchByNodeChannelCount> getOutgoingBatchByNodeChannelCount(int maxRows, NodeGroupLinkAction linkType, boolean readyToSendOnly) {
List<OutgoingBatchByNodeChannelCount> forReturn = new ArrayList<OutgoingBatchByNodeChannelCount>();
List<OutgoingBatchByNodeChannelCount> allNodeChannels = sqlTemplate.query(getSql("selectPendingOutgoingBatchByChannelCountSql"), maxRows, new OutgoingBatchByNodeChannelCountMapper(), new Object[] { linkType.name() });
if (readyToSendOnly) {
Set<String> nodeIdHasReloadsNotInError = new HashSet<String>();
for (OutgoingBatchByNodeChannelCount outgoingBatchByNodeChannelCount : allNodeChannels) {
Channel channel = configurationService.getChannel(outgoingBatchByNodeChannelCount.getChannelId());
if (channel.isReloadFlag() && !outgoingBatchByNodeChannelCount.isInError()) {
nodeIdHasReloadsNotInError.add(outgoingBatchByNodeChannelCount.getNodeId());
}
}
for (OutgoingBatchByNodeChannelCount outgoingBatchByNodeChannelCount : allNodeChannels) {
Channel channel = configurationService.getChannel(outgoingBatchByNodeChannelCount.getChannelId());
if (!nodeIdHasReloadsNotInError.contains(outgoingBatchByNodeChannelCount.getNodeId()) || channel.isReloadFlag()) {
forReturn.add(outgoingBatchByNodeChannelCount);
}
}
} else {
forReturn.addAll(allNodeChannels);
}
return forReturn;
}
Aggregations