From dea7bee0491ba0749ed2648f97c200bf2a23de82 Mon Sep 17 00:00:00 2001 From: orbiter Date: Tue, 2 Oct 2007 23:56:04 +0000 Subject: [PATCH] - increased minimum time before an active connection is interrupted from 1 minute to 10 minutes - added sorting by connection time in client connection tabe of connectionTimeComparatorInstance git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4128 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/Connections_p.java | 3 ++ source/de/anomic/http/httpc.java | 57 ++++++++++++++------------------ 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/htroot/Connections_p.java b/htroot/Connections_p.java index 70bf69484..9d72245df 100644 --- a/htroot/Connections_p.java +++ b/htroot/Connections_p.java @@ -49,6 +49,7 @@ import java.io.UnsupportedEncodingException; import java.net.InetAddress; import java.net.URLEncoder; +import java.util.Arrays; import java.util.Properties; import org.apache.commons.pool.impl.GenericObjectPool; @@ -240,6 +241,7 @@ public final class Connections_p { // client sessions httpc[] a = httpc.allConnections(); + Arrays.sort(a, httpc.connectionTimeComparatorInstance); int c = 0; for (int i = 0; i < a.length; i++) { httpc clientConnection = (httpc) a[i]; @@ -258,4 +260,5 @@ public final class Connections_p { // return rewrite values for templates return prop; } + } diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java index 46a555447..35e2f35d0 100644 --- a/source/de/anomic/http/httpc.java +++ b/source/de/anomic/http/httpc.java @@ -56,6 +56,7 @@ import java.net.SocketException; import java.net.UnknownHostException; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Comparator; import java.util.Date; import java.util.Enumeration; import java.util.GregorianCalendar; @@ -109,6 +110,9 @@ public final class httpc { private static final SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US); private static final HashMap reverseMappingCache = new HashMap(); private static final HashSet activeConnections = new HashSet(); // all connections are stored here and deleted when they are finished + private static final long minimumTime_before_activeConnections_cleanup = 600000; + public static final connectionTimeComparator connectionTimeComparatorInstance = new connectionTimeComparator(); + private static int objCounter = 0; // will be increased with each object and is use to return a hash code // defined during set-up of switchboard @@ -432,7 +436,7 @@ public final class httpc { httpc clientConnection = a[i]; if ((clientConnection != null) && (clientConnection.initTime != Long.MAX_VALUE) && - (clientConnection.initTime + Math.max(60000, clientConnection.timeout) < System.currentTimeMillis())) { + (clientConnection.initTime + Math.max(minimumTime_before_activeConnections_cleanup, clientConnection.timeout) < System.currentTimeMillis())) { // the time-out limit is reached. close the connection clientConnection.close(); c++; @@ -466,7 +470,24 @@ public final class httpc { } return a; } - + + public static class connectionTimeComparator implements Comparator { + + public connectionTimeComparator() { + super(); + } + + public int compare(Object o1, Object o2) { + httpc c1 = (httpc) o1; + httpc c2 = (httpc) o2; + long l1 = System.currentTimeMillis() - c1.initTime; + long l2 = System.currentTimeMillis() - c2.initTime; + if (l1 < l2) return 1; + if (l1 > l2) return -1; + return 0; + } + } + public void finalize() { this.close(); } @@ -1318,33 +1339,6 @@ public final class httpc { return httpc.this.clientInput; } - /** - * This method just outputs the found content into an byte-array and - * returns it. - * - * @return the found content - * @throws IOException - */ /* - public byte[] writeContent() throws IOException { -// int contentLength = (int) this.responseHeader.contentLength(); -// serverByteBuffer sbb = new serverByteBuffer((contentLength==-1)?8192:contentLength); -// writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), null, sbb); -// return sbb.getBytes(); - return serverFileUtils.read(this.getContentInputStream()); - } - public void writeContent(File file) throws IOException { - // this writes the input stream to a file - FileOutputStream bufferOS = null; - try { - if (file != null) bufferOS = new FileOutputStream(file); - serverFileUtils.writeX(this.getContentInputStream(), null, bufferOS); - } finally { - if (bufferOS != null) { - bufferOS.close(); - if (file.length() == 0) file.delete(); - } - } - }*/ /** * This method outputs the found content into an byte-array and * additionally outputs it to procOS. @@ -1362,12 +1356,11 @@ public final class httpc { } if (procOS instanceof OutputStream) { - //writeContentX(httpc.this.clientInput, this.gzip, this.responseHeader.contentLength(), procOS, sbb); - serverFileUtils.writeX(this.getContentInputStream(), (OutputStream)procOS, sbb); + serverFileUtils.writeX(this.getContentInputStream(), (OutputStream) procOS, sbb); } else if (procOS instanceof Writer) { String charSet = this.responseHeader.getCharacterEncoding(); if (charSet == null) charSet = httpHeader.DEFAULT_CHARSET; - serverFileUtils.writeX(this.getContentInputStream(), charSet, (Writer)procOS, sbb, charSet); + serverFileUtils.writeX(this.getContentInputStream(), charSet, (Writer) procOS, sbb, charSet); } else { throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'"); }