perfsonar-dev - perfsonar: r5348 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level1 utils
Subject: perfsonar development work
List archive
perfsonar: r5348 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level1 utils
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5348 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level1 utils
- Date: Tue, 17 Nov 2009 05:10:17 -0500
Author: krzjed
Date: 2009-11-17 05:10:17 -0500 (Tue, 17 Nov 2009)
New Revision: 5348
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultContainer.java
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryStepImpl.java
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
Log:
discovery query executed in parallel
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
2009-11-16 14:31:03 UTC (rev 5347)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryProcessImpl.java
2009-11-17 10:10:17 UTC (rev 5348)
@@ -2,8 +2,10 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
@@ -20,6 +22,7 @@
import org.perfsonar.lsclient.data.TopologyElement;
import org.perfsonar.ri.lsclient.data.implementation.ServiceImpl;
import org.perfsonar.ri.lsclient.handlers.ServiceCollectionHandler;
+import org.perfsonar.ri.lsclient.utils.ResultContainer;
import org.perfsonar.ri.lsclient.xml.ResponseParser;
import org.xml.sax.SAXException;
@@ -32,12 +35,10 @@
private final Set<EventType> eventTypes;
private final Set<ServiceType> type;
- public DiscoveryProcessImpl(Level0LsClientInterface level0,
- RootGlses rootGlses, Set<TopologyElement> elements,
+ public DiscoveryProcessImpl(Level0LsClientInterface level0, RootGlses
rootGlses, Set<TopologyElement> elements,
Set<EventType> eventTypes, Set<ServiceType> type) {
if (rootGlses == null || rootGlses.isEmpty())
- throw new IllegalArgumentException(
- "rootServices must be a non-null non-empty set.");
+ throw new IllegalArgumentException("rootServices must be a
non-null non-empty set.");
this.level0 = level0;
this.rootServices = rootGlses;
this.elements = elements;
@@ -51,8 +52,7 @@
Set<LookupService> referralLookupservices;
public boolean hasNext() {
- return referralLookupservices == null
- || !referralLookupservices.isEmpty();
+ return referralLookupservices == null ||
!referralLookupservices.isEmpty();
}
public DiscoveryStep next() {
@@ -76,42 +76,46 @@
}
protected DiscoveryStep firstStep(Set<LookupService>
referralLookupservices) {
- DiscoveryQuery query = new DiscoveryQuery(elements, eventTypes,
type);
- for (LookupService service : rootServices) {
- logger.debug("Using Gls: " + service);
+ final DiscoveryQuery query = new DiscoveryQuery(elements,
eventTypes, type);
+ final ResultContainer<InputStream> sc = new
ResultContainer<InputStream>();
- InputStream inputStream = null;
- try {
- inputStream = level0.getRawDiscoveryResponse(service, query
- .toString());
- } catch (LsQueryException e) {
- rootServices.demote(service, e);
- continue;
+ List<Thread> threads = new ArrayList<Thread>();
+
+ for (final LookupService service : rootServices) {
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ logger.debug("Using Gls: " + service);
+ try {
+ sc.setValue(level0.getRawDiscoveryResponse(service,
query.toString()));
+ } catch (LsQueryException e) {
+ rootServices.demote(service, e);
+ }
+ }
+ };
+ threads.add(t);
+ t.start();
+ }
+ try {
+ ServiceCollectionHandler sch = new ServiceCollectionHandler();
+ ResponseParser.parseDiscoveryResponse(sc.getValue(), sch);
+ for (Thread t : threads) {
+ t.destroy();
}
- try {
- ServiceCollectionHandler sch = new
ServiceCollectionHandler();
- ResponseParser.parseDiscoveryResponse(inputStream, sch);
- Set<ServiceImpl> services = sch.getMetadataSet();
- logger.debug("First step succeded without error. Result: ["
- + services + "]");
- return new DiscoveryStepImpl(
- new HashSet<AuthorativeLookupservice>(services));
- } catch (LsQueryException e) {
- logger.warn(e);
- rootServices.demote(service, e);
- } catch (ParserConfigurationException e) {
- // Impossible
- logger.warn("Impossible is nothing", e);
- } catch (SAXException e) {
- logger.warn(e);
- rootServices.demote(service, e);
- } catch (IOException e) {
- logger.warn(e);
- rootServices.demote(service, e);
- }
+ Set<ServiceImpl> services = sch.getMetadataSet();
+ logger.debug("First step succeded without error. Result: [" +
services + "]");
+ return new DiscoveryStepImpl(new
HashSet<AuthorativeLookupservice>(services));
+ } catch (LsQueryException e) {
+ logger.warn(e);
+ } catch (ParserConfigurationException e) {
+ // Impossible
+ logger.warn("Impossible is nothing", e);
+ } catch (SAXException e) {
+ logger.warn(e);
+ } catch (IOException e) {
+ logger.warn(e);
}
- return new DiscoveryStepImpl(new LsQueryException(
- "None of the root lookupservices could be consulted"));
+ return new DiscoveryStepImpl(new LsQueryException("None of the root
lookupservices could be consulted"));
}
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryStepImpl.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryStepImpl.java
2009-11-16 14:31:03 UTC (rev 5347)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/DiscoveryStepImpl.java
2009-11-17 10:10:17 UTC (rev 5348)
@@ -9,30 +9,32 @@
public class DiscoveryStepImpl implements DiscoveryStep {
- private final Set<AuthorativeLookupservice> services;
- private final Throwable throwable;
-
- public DiscoveryStepImpl(Set<AuthorativeLookupservice> services) {
- this.services = new
HashSet<AuthorativeLookupservice>(services);
- this.throwable = null;
- }
-
- public DiscoveryStepImpl(Throwable e) {
- this.throwable = e;
- this.services = null;
- }
+ private final Set<AuthorativeLookupservice> services;
+ private final Throwable throwable;
- public Throwable getException() {
- return throwable;
- }
+ public DiscoveryStepImpl(Set<AuthorativeLookupservice> services) {
+ this.services = new HashSet<AuthorativeLookupservice>(services);
+ this.throwable = null;
+ }
- public Set<AuthorativeLookupservice> getServices() {
- if(hasFailed()) return null;
- return Collections.unmodifiableSet(services);
- }
+ public DiscoveryStepImpl(Throwable e) {
+ this.throwable = e;
+ this.services = null;
+ }
- public boolean hasFailed() {
- return throwable != null;
- }
+ public Throwable getException() {
+ return throwable;
+ }
+ public Set<AuthorativeLookupservice> getServices() {
+ if (hasFailed()) {
+ return null;
+ }
+ return Collections.unmodifiableSet(services);
+ }
+
+ public boolean hasFailed() {
+ return throwable != null;
+ }
+
}
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
===================================================================
---
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-11-16 14:31:03 UTC (rev 5347)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-11-17 10:10:17 UTC (rev 5348)
@@ -27,43 +27,34 @@
this.timerMutex = new Object();
}
- public boolean isEmpty() {
+ public synchronized boolean isEmpty() {
return data.isEmpty();
}
- public void replace(Collection<LookupService> values) {
+ public synchronized void replace(Collection<LookupService> values) {
synchronized (mutex) {
// TODO speed up by using parallel requests. + add cutoff
// points.
SortedMap<Long, LookupService> timedServices = new TreeMap<Long,
LookupService>();
for (LookupService service : values) {
try {
- URLConnection connection = service.getEndPoint().toURL()
- .openConnection();
+ URLConnection connection =
service.getEndPoint().toURL().openConnection();
connection.setConnectTimeout(2000); // We should be able
// to be strict here
connection.setUseCaches(false);
long startTime = System.nanoTime();
connection.connect();
- timedServices.put(Long.valueOf(System.nanoTime()
- - startTime), service);
+ timedServices.put(Long.valueOf(System.nanoTime() -
startTime), service);
} catch (MalformedURLException e) {
- logger
- .error(
- "Supplied service endpoint('"
- + service.getEndPoint()
- + "') is not a valid URL, this
client only understands http(s)",
- e);
+ logger.error("Supplied service endpoint('" +
service.getEndPoint()
+ + "') is not a valid URL, this client only
understands http(s)", e);
} catch (IOException e) {
- logger.warn("Error occoured while trying to time gls('"
- + service.getEndPoint() + "')", e);
- logger.info("Dropping supplied entry: "
- + service.getEndPoint());
+ logger.warn("Error occoured while trying to time gls('"
+ service.getEndPoint() + "')", e);
+ logger.info("Dropping supplied entry: " +
service.getEndPoint());
}
}
if (timedServices.isEmpty()) {
- logger
- .error("None of the supplied root services where
accepted. falling back to old values");
+ logger.error("None of the supplied root services where
accepted. falling back to old values");
return;
}
data.clear();
@@ -71,7 +62,7 @@
}
}
- public Iterator<LookupService> iterator() {
+ public synchronized Iterator<LookupService> iterator() {
return data.iterator();
}
@@ -81,10 +72,9 @@
* @param service
* @param e
*/
- public void demote(LookupService service, Exception e) {
+ public synchronized void demote(LookupService service, Exception e) {
synchronized (mutex) {
- logger.warn("Demoting Lookup service('" + service.getEndPoint()
- + "')", e);
+ logger.warn("Demoting Lookup service('" + service.getEndPoint()
+ "')", e);
if (!data.contains(service))
return;
if (data.peek() == service) {
@@ -93,7 +83,7 @@
}
}
- public void ensureFilled() {
+ public synchronized void ensureFilled() {
if (data.isEmpty())
synchronized (mutex) {
if (data.isEmpty()) {
@@ -102,11 +92,11 @@
}
}
- protected void fill() {
+ protected synchronized void fill() {
fill(true);
}
- protected void fill(boolean autorefresh) {
+ protected synchronized void fill(boolean autorefresh) {
replace(getDefaultLookupServices());
if (autorefresh && timer == null) {
synchronized (timerMutex) {
@@ -127,7 +117,7 @@
}
}
- public void stopAutoRefresh() {
+ public synchronized void stopAutoRefresh() {
if (timer != null) {
synchronized (timerMutex) {
if (timer != null) {
@@ -139,7 +129,7 @@
}
}
- public Set<LookupService> getDefaultLookupServices() {
+ public synchronized Set<LookupService> getDefaultLookupServices() {
logger.debug("Getting default lookupservices from root.hints");
RootHintsFileDownloader downloader = new RootHintsFileDownloader();
return downloader.getGlobalLookupServices();
Added:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/utils/ResultContainer.java
- perfsonar: r5348 - in trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient: . level1 utils, svnlog, 11/17/2009
Archive powered by MHonArc 2.6.16.