mirror of
https://github.com/yacy/yacy_search_server.git
synced 2024-09-21 00:00:13 +02:00
- 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
This commit is contained in:
parent
f8e69ce4dc
commit
dea7bee049
|
@ -49,6 +49,7 @@
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.apache.commons.pool.impl.GenericObjectPool;
|
import org.apache.commons.pool.impl.GenericObjectPool;
|
||||||
|
@ -240,6 +241,7 @@ public final class Connections_p {
|
||||||
|
|
||||||
// client sessions
|
// client sessions
|
||||||
httpc[] a = httpc.allConnections();
|
httpc[] a = httpc.allConnections();
|
||||||
|
Arrays.sort(a, httpc.connectionTimeComparatorInstance);
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (int i = 0; i < a.length; i++) {
|
for (int i = 0; i < a.length; i++) {
|
||||||
httpc clientConnection = (httpc) a[i];
|
httpc clientConnection = (httpc) a[i];
|
||||||
|
@ -258,4 +260,5 @@ public final class Connections_p {
|
||||||
// return rewrite values for templates
|
// return rewrite values for templates
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.GregorianCalendar;
|
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 SimpleDateFormat HTTPGMTFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
|
||||||
private static final HashMap reverseMappingCache = new HashMap();
|
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 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
|
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
|
// defined during set-up of switchboard
|
||||||
|
@ -432,7 +436,7 @@ public final class httpc {
|
||||||
httpc clientConnection = a[i];
|
httpc clientConnection = a[i];
|
||||||
if ((clientConnection != null) &&
|
if ((clientConnection != null) &&
|
||||||
(clientConnection.initTime != Long.MAX_VALUE) &&
|
(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
|
// the time-out limit is reached. close the connection
|
||||||
clientConnection.close();
|
clientConnection.close();
|
||||||
c++;
|
c++;
|
||||||
|
@ -467,6 +471,23 @@ public final class httpc {
|
||||||
return a;
|
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() {
|
public void finalize() {
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
@ -1318,33 +1339,6 @@ public final class httpc {
|
||||||
return httpc.this.clientInput;
|
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
|
* This method outputs the found content into an byte-array and
|
||||||
* additionally outputs it to procOS.
|
* additionally outputs it to procOS.
|
||||||
|
@ -1362,12 +1356,11 @@ public final class httpc {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (procOS instanceof OutputStream) {
|
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) {
|
} else if (procOS instanceof Writer) {
|
||||||
String charSet = this.responseHeader.getCharacterEncoding();
|
String charSet = this.responseHeader.getCharacterEncoding();
|
||||||
if (charSet == null) charSet = httpHeader.DEFAULT_CHARSET;
|
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 {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");
|
throw new IllegalArgumentException("Invalid procOS object type '" + procOS.getClass().getName() + "'");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user