Index: trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java
===================================================================
--- trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java	(revision 1614)
+++ trunk/autoquest-httpmonitor/src/main/java/de/ugoe/cs/autoquest/httpmonitor/proxy/HttpMonitorRemoteExchangeHandler.java	(revision 1991)
@@ -17,6 +17,4 @@
 import java.io.IOException;
 import java.io.OutputStreamWriter;
-import java.util.HashSet;
-import java.util.Set;
 import java.util.logging.Level;
 
@@ -25,16 +23,11 @@
 import javax.xml.bind.Marshaller;
 
-import org.eclipse.jetty.client.HttpClient;
 import org.eclipse.jetty.client.api.Request;
-import org.eclipse.jetty.client.api.Response.CompleteListener;
 import org.eclipse.jetty.client.api.Result;
 import org.eclipse.jetty.client.util.OutputStreamContentProvider;
 import org.eclipse.jetty.http.HttpMethod;
 import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.util.thread.QueuedThreadPool;
 
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitor;
-import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent;
-import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorException;
 import de.ugoe.cs.autoquest.httpmonitor.HttpMonitorExchangeHandler;
 import de.ugoe.cs.autoquest.plugin.http.logdata.HttpExchange;
@@ -48,5 +41,5 @@
  * request/response. It then creates an HTTP request to the central monitor and sends it there.
  * It is initialized with the name of the server and the port on which the central monitor runs.
- * If the exchanges can not be forwarded to the central server, they are discarded.
+ * If the exchanges cannot be forwarded to the central server, they are discarded.
  * </p>
  * 
@@ -54,34 +47,7 @@
  */
 public class HttpMonitorRemoteExchangeHandler
-    implements CompleteListener, HttpMonitorExchangeHandler, HttpMonitorComponent
+    extends HttpMonitorRemoteConnection
+    implements HttpMonitorExchangeHandler
 {
-
-    /**
-     * <p>
-     * the HTTP client used internally to send data to the central server
-     * </p>
-     */
-    private HttpClient httpClient;
-    
-    /**
-     * <p>
-     * the host name of the central server
-     * </p>
-     */
-    private String httpMonitorServer;
-    
-    /**
-     * <p>
-     * the port of the central server
-     * </p>
-     */
-    private int httpMonitorPort;
-
-    /**
-     * <p>
-     * a set of requests send to the central server for which the response was not received yet
-     * </p>
-     */
-    private Set<Request> openRequests = new HashSet<Request>();
     
     /**
@@ -94,46 +60,5 @@
      */
     public HttpMonitorRemoteExchangeHandler(String httpMonitorServer, int httpMonitorPort) {
-        this.httpMonitorServer = httpMonitorServer;
-        this.httpMonitorPort = httpMonitorPort;
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#init()
-     */
-    @Override
-    public void init() throws IllegalStateException, HttpMonitorException {
-        httpClient = createHttpClient();
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#start()
-     */
-    @Override
-    public void start() throws IllegalStateException, HttpMonitorException {
-        try {
-            httpClient.start();
-            httpClient.getContentDecoderFactories().clear();
-        }
-        catch (Exception e) {
-            throw new HttpMonitorException("could not start client for HTTP-Monitor", e);
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see de.ugoe.cs.autoquest.httpmonitor.HttpMonitorComponent#stop()
-     */
-    @Override
-    public void stop() {
-        if (httpClient != null) {
-            try {
-                httpClient.stop();
-            }
-            catch (Exception e) {
-                Console.traceln(Level.WARNING, "could not stop client for HTTP-Monitor");
-                Console.logException(e);
-            }
-        }
-        
-        httpClient = null;
+        super(httpMonitorServer, httpMonitorPort);
     }
 
@@ -144,5 +69,5 @@
     public synchronized void handleHttpExchange(HttpExchange httpExchange) {
         // send the exchange to the server and wait for completion
-        Request httpMonitorRequest = httpClient.newRequest(httpMonitorServer, httpMonitorPort);
+        Request httpMonitorRequest = super.newRequest();
         httpMonitorRequest.method(HttpMethod.POST);
         httpMonitorRequest.version(HttpVersion.HTTP_1_1);
@@ -151,6 +76,5 @@
         httpMonitorRequest.content(out);
         
-        openRequests.add(httpMonitorRequest);
-        httpMonitorRequest.send(this);
+        super.sendRequest(httpMonitorRequest);
 
         try {
@@ -173,28 +97,8 @@
             Console.logException(e);
         }
-
-        try {
-            // wait for the request to be removed from the list asynchronously
-            int count = 30;
-            while (openRequests.contains(httpMonitorRequest)) {
-                this.wait(1000);
-                
-                if (--count == 0) {
-                    // after 30 seconds, cancel the sending of the loggin request
-                    openRequests.remove(httpMonitorRequest);
-                    break;
-                }
-            }
-        }
-        catch (InterruptedException e) {
-            // ignore, as this may only happen on system shutdown
-        }
-    }
-
-    /* (non-Javadoc)
-     * @see org.eclipse.jetty.client.api.Response.CompleteListener#onComplete(Result)
-     */
-    @Override
-    public synchronized void onComplete(Result result) {
+        
+        // wait to ensure that the request was received
+        Result result = super.getResult(httpMonitorRequest);
+        
         if (result.isFailed()) {
             Console.traceln
@@ -202,29 +106,4 @@
             Console.logException((Exception) result.getFailure());
         }
-        
-        openRequests.remove(result.getRequest());
-        this.notify();
-    }
-
-    /**
-     * <p>
-     * convenience method to create an initialize the utilized HTTP client
-     * </p>
-     */
-    private HttpClient createHttpClient() {
-        HttpClient client = new HttpClient();
-        
-        QueuedThreadPool executor = new QueuedThreadPool(10);
-        executor.setName("HttpMonitorClients");
-        client.setExecutor(executor);
-
-        client.setMaxConnectionsPerDestination(10000);
-        client.setIdleTimeout(30000);
-        client.setConnectTimeout(30000);
-        client.setStopTimeout(30000);
-        client.setRequestBufferSize(1024*1024);
-        client.setResponseBufferSize(1024*1024);
-        
-        return client;
     }
 }
