mirror of https://github.com/BOINC/boinc.git
Simplify some operations in ClientInterfaceImplementation using Eclipse Collections.
Also remove some unused methods and remove unnecessary null check.
This commit is contained in:
parent
c53d0ddd26
commit
99bf46425c
|
@ -1,17 +1,20 @@
|
||||||
package edu.berkeley.boinc.client;
|
package edu.berkeley.boinc.client;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.eclipse.collections.api.block.predicate.Predicate;
|
||||||
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
|
import org.eclipse.collections.api.list.MutableList;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import edu.berkeley.boinc.rpc.AccountIn;
|
import edu.berkeley.boinc.rpc.AccountIn;
|
||||||
import edu.berkeley.boinc.rpc.AccountManager;
|
import edu.berkeley.boinc.rpc.AccountManager;
|
||||||
import edu.berkeley.boinc.rpc.AccountOut;
|
import edu.berkeley.boinc.rpc.AccountOut;
|
||||||
|
@ -287,21 +290,6 @@ public class ClientInterfaceImplementation extends RpcClient {
|
||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets cc_config.xml entries and triggers activation in BOINC client.
|
|
||||||
* Used to set debug log flags.
|
|
||||||
*
|
|
||||||
* @param ccConfig string of all cc_config flags
|
|
||||||
*/
|
|
||||||
public void setCcConfigAndActivate(String ccConfig) {
|
|
||||||
if (Logging.DEBUG)
|
|
||||||
Log.d(Logging.TAG, "Monitor.setCcConfig: current cc_config: " + getCcConfig());
|
|
||||||
if (Logging.DEBUG)
|
|
||||||
Log.d(Logging.TAG, "Monitor.setCcConfig: setting new cc_config: " + ccConfig);
|
|
||||||
setCcConfig(ccConfig);
|
|
||||||
readCcConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs transferOp for a list of given transfers.
|
* Runs transferOp for a list of given transfers.
|
||||||
* E.g. batch pausing of transfers
|
* E.g. batch pausing of transfers
|
||||||
|
@ -311,8 +299,8 @@ public class ClientInterfaceImplementation extends RpcClient {
|
||||||
* @return success
|
* @return success
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public Boolean transferOperation(ArrayList<Transfer> transfers, int operation) {
|
boolean transferOperation(List<Transfer> transfers, int operation) {
|
||||||
Boolean success = true;
|
boolean success = true;
|
||||||
for (Transfer transfer : transfers) {
|
for (Transfer transfer : transfers) {
|
||||||
success = success && transferOp(operation, transfer.getProjectUrl(), transfer.getName());
|
success = success && transferOp(operation, transfer.getProjectUrl(), transfer.getName());
|
||||||
if (Logging.DEBUG) Log.d(Logging.TAG, "transfer: " + transfer.getName() + " " +
|
if (Logging.DEBUG) Log.d(Logging.TAG, "transfer: " + transfer.getName() + " " +
|
||||||
|
@ -516,25 +504,22 @@ public class ClientInterfaceImplementation extends RpcClient {
|
||||||
// less than desired number of messsages available, adapt lower bound
|
// less than desired number of messsages available, adapt lower bound
|
||||||
if (lowerBound < 0)
|
if (lowerBound < 0)
|
||||||
lowerBound = 0;
|
lowerBound = 0;
|
||||||
List<Message> msgs = getMessages(lowerBound); // returns ever messages with seqNo > lowerBound
|
|
||||||
|
// returns every message with seqNo > lowerBound
|
||||||
|
MutableList<Message> messages = Lists.mutable.ofAll(getMessages(lowerBound));
|
||||||
|
|
||||||
if (seqNo > 0) {
|
if (seqNo > 0) {
|
||||||
// remove messages that are >= seqNo
|
// remove messages that are >= seqNo
|
||||||
Iterator<Message> it = msgs.iterator();
|
messages.removeIf(message -> message.getSeqno() >= seqNo);
|
||||||
while (it.hasNext()) {
|
|
||||||
Message tmp = it.next();
|
|
||||||
if (tmp.getSeqno() >= seqNo)
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!msgs.isEmpty() && Logging.DEBUG) {
|
if(!messages.isEmpty() && Logging.DEBUG) {
|
||||||
Log.d(Logging.TAG, "getEventLogMessages: returning array with " + msgs.size()
|
Log.d(Logging.TAG, "getEventLogMessages: returning array with " + messages.size()
|
||||||
+ " entries. for lowerBound: " + lowerBound + " at 0: "
|
+ " entries. for lowerBound: " + lowerBound + " at 0: "
|
||||||
+ msgs.get(0).getSeqno() + " at " + (msgs.size() - 1) + ": "
|
+ messages.get(0).getSeqno() + " at " + (messages.size() - 1) + ": "
|
||||||
+ msgs.get(msgs.size() - 1).getSeqno());
|
+ messages.getLast().getSeqno());
|
||||||
}
|
}
|
||||||
return msgs;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -549,39 +534,24 @@ public class ClientInterfaceImplementation extends RpcClient {
|
||||||
if (Logging.DEBUG)
|
if (Logging.DEBUG)
|
||||||
Log.d(Logging.TAG, "getAttachableProjects for platform: " + boincPlatformName + " or " + boincAltPlatformName);
|
Log.d(Logging.TAG, "getAttachableProjects for platform: " + boincPlatformName + " or " + boincAltPlatformName);
|
||||||
|
|
||||||
List<ProjectInfo> allProjectsList = getAllProjectsList(); // all_projects_list.xml
|
// currently attached projects
|
||||||
List<Project> attachedProjects = getState().getProjects(); // currently attached projects
|
final ImmutableList<Project> attachedProjects = Lists.immutable.ofAll(getState().getProjects());
|
||||||
|
|
||||||
List<ProjectInfo> attachableProjects = new ArrayList<>(); // array to be filled and returned
|
// filter out projects that are already attached
|
||||||
|
final ImmutableList<ProjectInfo> filteredProjectsList = getAllProjectsList() // all_projects_list.xml
|
||||||
if (allProjectsList == null)
|
.select(candidate -> attachedProjects
|
||||||
return Collections.emptyList();
|
.noneSatisfy(attachedProject ->
|
||||||
|
attachedProject.getMasterURL().equals(candidate.getUrl())));
|
||||||
//filter projects that do not support Android
|
|
||||||
for (ProjectInfo candidate : allProjectsList) {
|
|
||||||
// check whether already attached
|
|
||||||
boolean alreadyAttached = false;
|
|
||||||
for (Project attachedProject : attachedProjects) {
|
|
||||||
if (attachedProject.getMasterURL().equals(candidate.getUrl())) {
|
|
||||||
alreadyAttached = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (alreadyAttached)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
|
final Predicate<String> supportedPlatformPredicate = supportedPlatform -> supportedPlatform.contains(boincPlatformName) ||
|
||||||
|
(!boincAltPlatformName.isEmpty()
|
||||||
|
&& supportedPlatform.contains(boincAltPlatformName));
|
||||||
|
final List<ProjectInfo> attachableProjects = filteredProjectsList
|
||||||
|
//filter out projects that do not support Android
|
||||||
|
.select(candidate -> Lists.immutable.ofAll(candidate.getPlatforms())
|
||||||
// project is not yet attached, check whether it supports CPU architecture
|
// project is not yet attached, check whether it supports CPU architecture
|
||||||
for (String supportedPlatform : candidate.getPlatforms()) {
|
.anySatisfy(supportedPlatformPredicate))
|
||||||
if (supportedPlatform.contains(boincPlatformName) ||
|
.distinct().toList();
|
||||||
(!boincAltPlatformName.isEmpty() && supportedPlatform.contains(boincAltPlatformName))) {
|
|
||||||
// project is not yet attached and does support platform
|
|
||||||
// add to list, if not already in it
|
|
||||||
if (!attachableProjects.contains(candidate))
|
|
||||||
attachableProjects.add(candidate);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Logging.DEBUG)
|
if (Logging.DEBUG)
|
||||||
Log.d(Logging.TAG, "getAttachableProjects: number of candidates found: "
|
Log.d(Logging.TAG, "getAttachableProjects: number of candidates found: "
|
||||||
|
@ -604,14 +574,13 @@ public class ClientInterfaceImplementation extends RpcClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectInfo getProjectInfo(String url) {
|
ProjectInfo getProjectInfo(String url) {
|
||||||
List<ProjectInfo> allProjectsList = getAllProjectsList(); // all_projects_list.xml
|
// all_projects_list.xml
|
||||||
for (ProjectInfo tmp : allProjectsList) {
|
ProjectInfo projectInfo = getAllProjectsList().detect(tmp -> tmp.getUrl().equals(url));
|
||||||
if (tmp.getUrl().equals(url))
|
|
||||||
return tmp;
|
if (projectInfo == null && Logging.ERROR)
|
||||||
}
|
|
||||||
if (Logging.ERROR)
|
|
||||||
Log.e(Logging.TAG, "getProjectInfo: could not find info for: " + url);
|
Log.e(Logging.TAG, "getProjectInfo: could not find info for: " + url);
|
||||||
return null;
|
|
||||||
|
return projectInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean setDomainName(String deviceName) {
|
boolean setDomainName(String deviceName) {
|
||||||
|
|
|
@ -1036,7 +1036,7 @@ public class Monitor extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean transferOperation(List<Transfer> list, int op) throws RemoteException {
|
public boolean transferOperation(List<Transfer> list, int op) throws RemoteException {
|
||||||
return clientInterface.transferOperation((ArrayList<Transfer>) list, op);
|
return clientInterface.transferOperation(list, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,6 +25,8 @@ import android.util.Log;
|
||||||
import android.util.Xml;
|
import android.util.Xml;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
|
@ -968,17 +970,17 @@ public class RpcClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized List<ProjectInfo> getAllProjectsList() {
|
protected synchronized ImmutableList<ProjectInfo> getAllProjectsList() {
|
||||||
try {
|
try {
|
||||||
mRequest.setLength(0);
|
mRequest.setLength(0);
|
||||||
mRequest.append("<get_all_projects_list/>");
|
mRequest.append("<get_all_projects_list/>");
|
||||||
|
|
||||||
sendRequest(mRequest.toString());
|
sendRequest(mRequest.toString());
|
||||||
return ProjectInfoParser.parse(receiveReply());
|
return Lists.immutable.ofAll(ProjectInfoParser.parse(receiveReply()));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (Logging.WARNING)
|
if (Logging.WARNING)
|
||||||
Log.w(Logging.TAG, "error in getAllProjectsList()", e);
|
Log.w(Logging.TAG, "error in getAllProjectsList()", e);
|
||||||
return Collections.emptyList();
|
return Lists.immutable.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue