From: <jes...@us...> - 2011-01-10 11:16:05
|
Revision: 7104 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=7104&view=rev Author: jesseeichar Date: 2011-01-10 11:15:58 +0000 (Mon, 10 Jan 2011) Log Message: ----------- added better logging to debug failing xlinks Modified Paths: -------------- sandbox/geocat.ch/trunk/jeeves/src/jeeves/xlink/Processor.java Modified: sandbox/geocat.ch/trunk/jeeves/src/jeeves/xlink/Processor.java =================================================================== --- sandbox/geocat.ch/trunk/jeeves/src/jeeves/xlink/Processor.java 2011-01-10 10:28:35 UTC (rev 7103) +++ sandbox/geocat.ch/trunk/jeeves/src/jeeves/xlink/Processor.java 2011-01-10 11:15:58 UTC (rev 7104) @@ -1,9 +1,6 @@ package jeeves.xlink; -import java.io.BufferedInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintWriter; +import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; @@ -33,9 +30,49 @@ * @author fxprunayre */ public class Processor { + private static class Failure implements Comparable<Failure> { + public final String uri; + public final Throwable t; + public final long timeout; - private static TreeSet<Long> failures = new TreeSet<Long>(); + Failure(String uri, Throwable t, long timeout) { + this.uri = uri; + this.t = t; + this.timeout = timeout; + } + @Override + public int compareTo(Failure o) { + long diff = timeout - o.timeout; + if(diff == 0) { + return 0; + } else { + return diff > 0? 1 : -1; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Failure failure = (Failure) o; + + if (timeout != failure.timeout) return false; + if (uri != null ? !uri.equals(failure.uri) : failure.uri != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = uri != null ? uri.hashCode() : 0; + result = 31 * result + (int) (timeout ^ (timeout >>> 32)); + return result; + } + } + private static TreeSet<Failure> failures = new TreeSet<Failure>(); + private static int MAX_FAILURES = 50; private static final long ELAPSE_TIME = 30000; @@ -207,9 +244,6 @@ JDOMException, CacheException { cleanFailures(); - if( failures.size()>MAX_FAILURES ){ - throw new RuntimeException("There have been "+failures.size()+" timeouts resolving xlinks in the last "+ELAPSE_TIME+" ms"); - } JeevesJCS xlinkCache = JeevesJCS.getInstance(XLINK_JCS); Element remoteFragment = (Element) xlinkCache.get(uri); @@ -232,7 +266,25 @@ } }catch (IOException e) { synchronized(Processor.class){ - failures.add (System.currentTimeMillis()); + failures.add(new Failure(uri,e,System.currentTimeMillis())); + if( failures.size() > MAX_FAILURES ){ + StringBuilder builder = new StringBuilder("There have been "+failures.size()+" timeouts resolving xlinks in the last "+ELAPSE_TIME+" ms\n"); + for (Failure failure : failures) { + if(LOGGER.isDebugEnabled()) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + PrintWriter writer = new PrintWriter(out); + failure.t.printStackTrace(writer); + writer.close(); + builder.append('\n').append(failure.uri).append(" -> ").append(out).append("\n================"); + } else { + builder.append('\n').append(failure.uri).append(" -> "+failure.t.getMessage()); + } + } + + builder.append('\n'); + failures.clear(); + throw new RuntimeException(builder.toString(),e); + } } } @@ -252,9 +304,9 @@ { long now = System.currentTimeMillis(); - for (Iterator<Long> iter = failures.iterator(); iter.hasNext();) { - long next = iter.next(); - if( now-next > ELAPSE_TIME ){ + for (Iterator<Failure> iter = failures.iterator(); iter.hasNext();) { + Failure next = iter.next(); + if( now - next.timeout > ELAPSE_TIME ){ iter.remove(); } else { break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |