Author: ruschein
Date: 2010-08-04 13:20:23 -0700 (Wed, 04 Aug 2010)
New Revision: 21197
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
Log:
Refactored in order to remove ValuedTask and ValuedTaskExecutor.
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
2010-08-04 20:11:21 UTC (rev 21196)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
2010-08-04 20:20:23 UTC (rev 21197)
@@ -1,34 +1,35 @@
package org.cytoscape.task.internal.proxysettings;
+
+import org.cytoscape.io.util.StreamUtil;
+
+import org.cytoscape.work.TaskManager;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.TunableValidator;
import org.cytoscape.work.Tunable.Param;
import org.cytoscape.work.util.ListSingleSelection;
-import org.cytoscape.work.TaskManager;
-import org.cytoscape.work.ValuedTask;
-import org.cytoscape.work.ValuedTaskExecutor;
-import org.cytoscape.work.Task;
-import org.cytoscape.work.TaskMonitor;
+import java.net.URL;
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Properties;
+import java.util.concurrent.Callable;
+import java.util.concurrent.FutureTask;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.CancellationException;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.TimeUnit;
-import java.net.URL;
-import org.cytoscape.io.util.StreamUtil;
-
/**
* Dialog for assigning proxy settings.
* @author Pasteur
*/
-public class ProxySettingsTask implements Task, TunableValidator
-{
+public class ProxySettingsTask implements Task, TunableValidator {
static final List<String> KEYS = Arrays.asList("http.proxyHost",
"http.proxyPort", "socks.proxyHost", "socks.proxyPort");
@Tunable(description="Type")
@@ -46,69 +47,58 @@
final Map<String,String> oldSettings = new HashMap<String,String>();
final Properties properties = System.getProperties();
- public ProxySettingsTask(final TaskManager taskManager, final
StreamUtil streamUtil)
- {
+ public ProxySettingsTask(final TaskManager taskManager, final
StreamUtil streamUtil) {
this.taskManager = taskManager;
this.streamUtil = streamUtil;
}
- public void validate() throws Exception
- {
+ public void validate() throws Exception {
storeProxySettings();
- ValuedTaskExecutor<Exception> executor = new
ValuedTaskExecutor<Exception>(new TestProxySettings(streamUtil));
- taskManager.execute(executor);
-
+ FutureTask<Exception> executor = new FutureTask<Exception>(new
TestProxySettings(streamUtil));
Exception result = null;
- try
- {
- result = executor.get();
+ try {
+ result = executor.get(10, TimeUnit.SECONDS);
+ } catch (final InterruptedException e) {
+ result = e;
+ } catch (final ExecutionException e) {
+ result = e;
+ } catch (final TimeoutException e) {
+ result = e;
}
- catch (InterruptedException e) {}
- catch (ExecutionException e) {}
- catch (CancellationException e) {}
revertProxySettings();
if (result != null)
- {
- throw new Exception(String.format("Cytoscape was unable
to connect to the internet because:\n\n%s", result.getMessage()));
- }
+ throw new Exception("Cytoscape was unable to connect to
the internet because:\n\n" + result.getMessage());
}
-
- public void run(TaskMonitor taskMonitor)
- {
+ public void run(TaskMonitor taskMonitor) {
storeProxySettings();
oldSettings.clear();
}
- public void cancel()
- {
+ public void cancel() {
}
- void storeProxySettings()
- {
+ void storeProxySettings() {
oldSettings.clear();
- for (String key : KEYS)
+ for (String key : KEYS) {
if (properties.getProperty(key) != null)
oldSettings.put(key,
properties.getProperty(key));
+ }
- if (type.getSelectedValue().equals("direct"))
- {
- for (String key : KEYS)
+ if (type.getSelectedValue().equals("direct")) {
+ for (String key : KEYS) {
if (properties.getProperty(key) != null)
properties.remove(key);
- }
- else if (type.getSelectedValue().equals("http"))
- {
+ }
+ } else if (type.getSelectedValue().equals("http")) {
properties.remove("socks.proxyHost");
properties.remove("socks.proxyPort");
properties.setProperty("http.proxyHost", hostname);
properties.setProperty("http.proxyPort",
Integer.toString(port));
- }
- else if (type.getSelectedValue().equals("socks"))
- {
+ } else if (type.getSelectedValue().equals("socks")) {
properties.remove("http.proxyHost");
properties.remove("http.proxyPort");
properties.setProperty("socks.proxyHost", hostname);
@@ -116,10 +106,8 @@
}
}
- void revertProxySettings()
- {
- for (String key : KEYS)
- {
+ void revertProxySettings() {
+ for (String key : KEYS) {
if (properties.getProperty(key) != null)
properties.remove(key);
@@ -129,43 +117,31 @@
oldSettings.clear();
}
- void dumpSettings(String title)
- {
+ void dumpSettings(String title) {
System.out.println(title);
for (String key : KEYS)
System.out.println(String.format("%s: %s", key,
properties.getProperty(key)));
}
}
-class TestProxySettings implements ValuedTask<Exception>
-{
- static final String TEST_URL = "http://www.google.com";
+class TestProxySettings implements Callable<Exception> {
+ static final String TEST_URL = "http://www.google.com";
final StreamUtil streamUtil;
- public TestProxySettings(final StreamUtil streamUtil)
- {
+ public TestProxySettings(final StreamUtil streamUtil) {
this.streamUtil = streamUtil;
}
- public Exception run(TaskMonitor taskMonitor)
- {
- taskMonitor.setTitle("Testing Proxy Settings");
- try
- {
- taskMonitor.setStatusMessage("Attempting to open a
URL...");
- URL url = new URL(TEST_URL);
+ public Exception call() {
+ try {
+ final URL url = new URL(TEST_URL);
streamUtil.getInputStream(url).close();
- }
- catch (Exception ex)
- {
+ } catch (final Exception ex) {
return ex;
}
return null;
}
-
- public void cancel()
- {
- }
}
+
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.