perfsonar-dev - perfsonar: r5362 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1
Subject: perfsonar development work
List archive
perfsonar: r5362 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1
Chronological Thread
- From:
- To:
- Subject: perfsonar: r5362 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1
- Date: Mon, 30 Nov 2009 09:02:05 -0500
Author: krzjed
Date: 2009-11-30 09:02:05 -0500 (Mon, 30 Nov 2009)
New Revision: 5362
Modified:
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
Log:
old code removed
some refactoring
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-30 13:17:51 UTC (rev 5361)
+++
trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1/RootGlses.java
2009-11-30 14:02:05 UTC (rev 5362)
@@ -17,13 +17,11 @@
public class RootGlses implements Iterable<LookupService> {
private final ConcurrentLinkedQueue<LookupService> data = new
ConcurrentLinkedQueue<LookupService>();
private final Object timerMutex;
- private final Object mutex;
protected volatile Timer timer;
protected final Logger logger = Logger.getLogger(getClass());
- private static final int TIMEOUT = 2000;
+ private static final int TIMEOUT = 20000;
public RootGlses() {
- this.mutex = this;
this.timerMutex = new Object();
}
@@ -32,76 +30,40 @@
}
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();
- // connection.setConnectTimeout(TIMEOUT); // 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);
- // } catch (MalformedURLException 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());
- // }
- // }
- // if (timedServices.isEmpty()) {
- // logger.error("None of the supplied root services where
accepted. falling back to old values");
- // return;
- // }
- // data.clear();
- // data.addAll(timedServices.values());
-
- final SortedResultCollector<Long, LookupService> collector = new
SortedResultCollector<Long, LookupService>();
- for (final LookupService service : values) {
- collector.signalMoreElements();
- Thread t = new Thread() {
- public void run() {
- try {
- URLConnection connection =
service.getEndPoint().toURL().openConnection();
- connection.setConnectTimeout(TIMEOUT); // We
should
- // be
- // able
- // to be strict here
- connection.setUseCaches(false);
- long startTime = System.nanoTime();
- connection.connect();
- collector.addPair(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);
- collector.signalLackOfElement();
- } catch (IOException e) {
- logger.warn("Error occoured while trying to time
gls('" + service.getEndPoint() + "')", e);
- logger.info("Dropping supplied entry: " +
service.getEndPoint());
- collector.signalLackOfElement();
- }
+ final SortedResultCollector<Long, LookupService> collector = new
SortedResultCollector<Long, LookupService>();
+ for (final LookupService service : values) {
+ collector.signalMoreElements();
+ Thread t = new Thread() {
+ public void run() {
+ try {
+ URLConnection connection =
service.getEndPoint().toURL().openConnection();
+ // We should be able to be strict here
+ connection.setConnectTimeout(TIMEOUT);
+ connection.setUseCaches(false);
+ long startTime = System.nanoTime();
+ connection.connect();
+ collector.addPair(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);
+ collector.signalLackOfElement();
+ } catch (IOException e) {
+ logger.warn("Error occoured while trying to time
gls('" + service.getEndPoint() + "')", e);
+ logger.info("Dropping supplied entry: " +
service.getEndPoint());
+ collector.signalLackOfElement();
}
- };
- t.start();
- }
- if (collector.isEmpty()) {
- logger.error("None of the supplied root services where
accepted. falling back to old values");
- return;
- }
-
- data.clear();
- data.addAll(collector.getValues());
+ }
+ };
+ t.start();
}
+ if (collector.isEmpty()) {
+ logger.error("None of the supplied root services where accepted.
falling back to old values");
+ return;
+ }
+
+ data.clear();
+ logger.info("gLS' added " + collector.getValues());
+ data.addAll(collector.getValues());
}
public synchronized Iterator<LookupService> iterator() {
@@ -115,22 +77,18 @@
* @param e
*/
public synchronized void demote(LookupService service, Exception e) {
- synchronized (mutex) {
- logger.warn("Demoting Lookup service('" + service.getEndPoint()
+ "')", e);
- if (!data.contains(service))
- return;
- if (data.peek() == service) {
- data.add(data.poll());
- }
+ logger.warn("Demoting Lookup service('" + service.getEndPoint() +
"')", e);
+ if (!data.contains(service))
+ return;
+ if (data.peek() == service) {
+ data.add(data.poll());
}
}
public synchronized void ensureFilled() {
if (data.isEmpty())
- synchronized (mutex) {
- if (data.isEmpty()) {
- fill();
- }
+ if (data.isEmpty()) {
+ fill();
}
}
- perfsonar: r5362 - trunk/ps-mdm-lsclient-impl/src/main/java/org/perfsonar/ri/lsclient/level1, svnlog, 11/30/2009
Archive powered by MHonArc 2.6.16.