Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) Adding additional functions to serverByteBuffer so that it can be used instead of a ByteArrayOutputStream *) Using a serverByteBuffer for lineBuffering in class httpc instead of a ByteArrayOutputStream

(no author)942914ffd270
diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java
index 3fa30d1b7..cc3dea88d 100644
--- a/source/de/anomic/http/httpc.java
+++ b/source/de/anomic/http/httpc.java
@@ -87,8 +87,8 @@ public final class httpc {
private long handle;
// output and input streams for client control connection
- public PushbackInputStream clientInput = null;
- public OutputStream clientOutput = null;
+ PushbackInputStream clientInput = null;
+ OutputStream clientOutput = null;
private boolean remoteProxyUse = false;
private String savedRemoteHost = null;
@@ -104,8 +104,19 @@ public final class httpc {
java.security.Security.setProperty("networkaddress.cache.negative.ttl" , "0");
}
+ /**
+ * A Object Pool containing all pooled httpc-objects.
+ * @see httpcPool
+ */
private static final httpcPool theHttpcPool;
+
+ /**
+ * Indicates if the current object was removed from pool because the maximum limit
+ * was exceeded.
+ */
boolean removedFromPool = false;
+
+ // Configuring the httpc object pool
static {
// implementation of session thread pool
GenericObjectPool.Config config = new GenericObjectPool.Config();
@@ -125,16 +136,25 @@ public final class httpc {
theHttpcPool = new httpcPool(new httpcFactory(),config);
}
- private static final ByteArrayOutputStream readLineBuffer = new ByteArrayOutputStream();
+ /**
+ * A reusable readline buffer
+ * @see serverByteBuffer
+ */
+ final serverByteBuffer readLineBuffer = new serverByteBuffer();
- public static httpc getInstance(String server, int port, int timeout, boolean ssl,
- String remoteProxyHost, int remoteProxyPort) throws IOException {
+ public static httpc getInstance(
+ String server,
+ int port,
+ int timeout,
+ boolean ssl,
+ String remoteProxyHost,
+ int remoteProxyPort
+ ) throws IOException {
httpc newHttpc;
try {
// fetching a new httpc from the object pool
- newHttpc = (httpc) httpc.theHttpcPool.borrowObject();
-
+ newHttpc = (httpc) httpc.theHttpcPool.borrowObject();
} catch (Exception e) {
throw new IOException("Unable to initialize a new httpc. " + e.getMessage());
}
diff --git a/source/de/anomic/http/httpd.java b/source/de/anomic/http/httpd.java
index fe7fa544d..1971ae600 100644
--- a/source/de/anomic/http/httpd.java
+++ b/source/de/anomic/http/httpd.java
@@ -643,22 +643,23 @@ public final class httpd implements serverHandler {
}
private static String parseArg(String s) {
- // this parses a given value-string from a http property
- // we replace all "+" by spaces
- // and resolve %-escapes with two-digit hex attributes
- int pos = 0;
- String result = "";
- while (pos < s.length()) {
- if (s.charAt(pos) == '+') {
- result += " "; pos++;
- } else if (s.charAt(pos) == '%') {
- result += (char) Integer.parseInt(s.substring(pos + 1, pos + 3), 16);
- pos += 3;
- } else {
- result += s.charAt(pos++);
- }
- }
- return result;
+ // this parses a given value-string from a http property
+ // we replace all "+" by spaces
+ // and resolve %-escapes with two-digit hex attributes
+ int pos = 0;
+ StringBuffer result = new StringBuffer();
+ while (pos < s.length()) {
+ if (s.charAt(pos) == '+') {
+ result.append(" ");
+ pos++;
+ } else if (s.charAt(pos) == '%') {
+ result.append((char) Integer.parseInt(s.substring(pos + 1, pos + 3), 16));
+ pos += 3;
+ } else {
+ result.append(s.charAt(pos++));
+ }
+ }
+ return result.toString();
}
diff --git a/source/de/anomic/server/serverByteBuffer.java b/source/de/anomic/server/serverByteBuffer.java
index 3ce4e258b..07ab71251 100644
--- a/source/de/anomic/server/serverByteBuffer.java
+++ b/source/de/anomic/server/serverByteBuffer.java
@@ -59,6 +59,12 @@ public final class serverByteBuffer extends OutputStream {
offset = 0;
}
+ public serverByteBuffer(int initLength) {
+ this.buffer = new byte[initLength];
+ this.length = 0;
+ this.offset = 0;
+ }
+
public serverByteBuffer(byte[] bb) {
buffer = bb;
length = bb.length;
@@ -291,5 +297,16 @@ public final class serverByteBuffer extends OutputStream {
for (int i = 0; i < pattern.length; i++) if (buffer[offset + i] != pattern[i]) return false;
return true;
}
+
+ public void reset() {
+ this.length = 0;
+ this.offset = 0;
+ }
+ public byte toByteArray()[] {
+ byte newbuf[] = new byte[this.length];
+ System.arraycopy(this.buffer, 0, newbuf, 0, this.length);
+ return newbuf;
+ }
+
}
\ No newline at end of file
diff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.java
index 5d96f5044..bc02ade5b 100644
--- a/source/de/anomic/server/serverCore.java
+++ b/source/de/anomic/server/serverCore.java
@@ -504,7 +504,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
public PushbackInputStream in; // on control input stream
public OutputStream out; // on control output stream, autoflush
- private final ByteArrayOutputStream readLineBuffer = new ByteArrayOutputStream(256);
+ private final serverByteBuffer readLineBuffer = new serverByteBuffer(256);
public Session(ThreadGroup theThreadGroup) {
super(theThreadGroup,"Session");
@@ -785,7 +785,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
}
- public static byte[] receive(PushbackInputStream pbis, ByteArrayOutputStream readLineBuffer, long timeout, int maxSize, boolean logerr) {
+ public static byte[] receive(PushbackInputStream pbis, serverByteBuffer readLineBuffer, long timeout, int maxSize, boolean logerr) {
// this is essentially a readln on a PushbackInputStream
int bufferSize = 0;
@@ -793,7 +793,7 @@ public final class serverCore extends serverAbstractThread implements serverThre
// reuse an existing linebuffer or create a new one ...
if (readLineBuffer == null) {
- readLineBuffer = new ByteArrayOutputStream(256);
+ readLineBuffer = new serverByteBuffer(256);
} else {
readLineBuffer.reset();
}