*) bugfix for wrong proxy traffic accounting

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3484 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 18 years ago
parent 861f41e67e
commit 91c2a042a7

@ -298,8 +298,8 @@ public class Status {
prop.put("processors", rt.availableProcessors());
// proxy traffic
prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
prop.put("trafficOut",bytesToString(httpdByteCountOutputStream.getGlobalCount()));
//prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
prop.put("trafficProxy",bytesToString(httpdByteCountOutputStream.getAccountCount("PROXY")));
prop.put("trafficCrawler",bytesToString(httpdByteCountInputStream.getAccountCount("CRAWLER")));
// connection information

@ -59,7 +59,7 @@
</tr>
<tr class="TableCellDark">
<td>Traffic</td>
<td>Proxy: #[trafficOut]# | Crawler: #[trafficCrawler]#</td>
<td>Proxy: #[trafficProxy]# | Crawler: #[trafficCrawler]#</td>
<td>[<a href="Status.html?ResetTraffic=">Reset</a>]</td>
</tr>
<tr class="TableCellLight">

@ -75,7 +75,7 @@ public class status_p {
// proxy traffic
prop.put("trafficIn", httpdByteCountInputStream.getGlobalCount());
prop.put("trafficOut", httpdByteCountOutputStream.getGlobalCount());
prop.put("trafficProxy", httpdByteCountOutputStream.getAccountCount("PROXY"));
prop.put("trafficCrawler", httpdByteCountInputStream.getAccountCount("CRAWLER"));
// return rewrite properties

@ -14,7 +14,7 @@
<processors>#[processors]#</processors>
<traffic>
<in>#[trafficIn]#</in>
<out>#[trafficOut]#</out>
<proxy>#[trafficProxy]#</proxy>
<crawler>#[trafficCrawler]#</crawler>
</traffic>
</status>

@ -572,6 +572,7 @@ public final class httpc {
/**
* Returns the given date in an HTTP-usable format.
* (according to RFC822)
*
* @param date The Date-Object to be converted.
* @return String with the date.
@ -696,6 +697,10 @@ public final class httpc {
if (incomingByteCountAccounting != null) {
this.clientInputByteCount = new httpdByteCountInputStream(this.socket.getInputStream(),incomingByteCountAccounting);
}
if (outgoingByteCountAccounting != null) {
this.clientOutputByteCount = new httpdByteCountOutputStream(this.socket.getOutputStream(),outgoingByteCountAccounting);
}
// getting input and output streams
this.clientInput = new PushbackInputStream((this.clientInputByteCount!=null)?

@ -55,7 +55,7 @@ public class httpdBoundedSizeOutputStream extends httpdByteCountOutputStream {
}
public httpdBoundedSizeOutputStream(OutputStream outputStream, long initByteCount, long sizeLimit) {
super(outputStream,initByteCount);
super(outputStream,initByteCount,null);
this.maxSize = sizeLimit;
}

@ -70,8 +70,7 @@ public class httpdByteCountInputStream extends FilterInputStream {
* @param inputStream the {@link InputStream} to read from
*/
public httpdByteCountInputStream(InputStream inputStream, String accountName) {
super(inputStream);
this.byteCountAccountName = accountName;
this(inputStream,0,accountName);
}
/**

@ -47,6 +47,7 @@ package de.anomic.http;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
public class httpdByteCountOutputStream extends BufferedOutputStream {
@ -54,24 +55,31 @@ public class httpdByteCountOutputStream extends BufferedOutputStream {
private static long globalByteCount = 0;
private boolean finished = false;
private static final HashMap byteCountInfo = new HashMap(2);
protected long byteCount;
protected String byteCountAccountName = null;
/**
* Constructor of this class
* @param outputStream the {@link OutputStream} to write to
*/
public httpdByteCountOutputStream(OutputStream outputStream) {
this(outputStream,0);
this(outputStream,null);
}
public httpdByteCountOutputStream(OutputStream outputStream, String accountName) {
this(outputStream,0,accountName);
}
/**
* Constructor of this class
* @param outputStream the {@link OutputStream} to write to
* @param initByteCount to initialize the bytecount with a given value
*/
public httpdByteCountOutputStream(OutputStream outputStream, long initByteCount) {
public httpdByteCountOutputStream(OutputStream outputStream, long initByteCount, String accountName) {
super(outputStream);
this.byteCount = initByteCount;
this.byteCountAccountName = accountName;
}
/** @see java.io.OutputStream#write(byte[]) */
@ -100,15 +108,29 @@ public class httpdByteCountOutputStream extends BufferedOutputStream {
return this.byteCount;
}
public String getAccountName() {
return this.byteCountAccountName;
}
public static long getGlobalCount() {
synchronized (syncObject) {
return globalByteCount;
}
}
public static long getAccountCount(String accountName) {
synchronized (syncObject) {
if (byteCountInfo.containsKey(accountName)) {
return ((Long)byteCountInfo.get(accountName)).longValue();
}
return 0;
}
}
public static void resetCount() {
synchronized (syncObject) {
globalByteCount = 0;
byteCountInfo.clear();
}
}
@ -118,7 +140,16 @@ public class httpdByteCountOutputStream extends BufferedOutputStream {
this.finished = true;
synchronized (syncObject) {
globalByteCount += this.byteCount;
}
if (this.byteCountAccountName != null) {
long lastByteCount = 0;
if (byteCountInfo.containsKey(this.byteCountAccountName)) {
lastByteCount = ((Long)byteCountInfo.get(this.byteCountAccountName)).longValue();
}
lastByteCount += this.byteCount;
byteCountInfo.put(this.byteCountAccountName,new Long(lastByteCount));
}
}
}
protected void finalize() throws Throwable {

@ -328,7 +328,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
switchboard.proxyLastAccess = System.currentTimeMillis();
// using an ByteCount OutputStream to count the send bytes (needed for the logfile)
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2);
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY");
String host = conProp.getProperty(httpHeader.CONNECTION_PROP_HOST);
String path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH); // always starts with leading '/'
@ -893,7 +893,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
switchboard.proxyLastAccess = System.currentTimeMillis();
// using an ByteCount OutputStream to count the send bytes
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2);
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY");
String host = conProp.getProperty(httpHeader.CONNECTION_PROP_HOST);
String path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH);
@ -998,7 +998,7 @@ public final class httpdProxyHandler extends httpdAbstractHandler implements htt
switchboard.proxyLastAccess = System.currentTimeMillis();
// using an ByteCount OutputStream to count the send bytes
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2);
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY");
String host = conProp.getProperty(httpHeader.CONNECTION_PROP_HOST);
String path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH);

Loading…
Cancel
Save