geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pra...@apache.org
Subject svn commit: r599449 - /geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/NIOServlet.java
Date Thu, 29 Nov 2007 14:09:26 GMT
Author: prasad
Date: Thu Nov 29 06:09:25 2007
New Revision: 599449

URL: http://svn.apache.org/viewvc?rev=599449&view=rev
Log:
* thread created in init

Modified:
    geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/NIOServlet.java

Modified: geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/NIOServlet.java
URL: http://svn.apache.org/viewvc/geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/NIOServlet.java?rev=599449&r1=599448&r2=599449&view=diff
==============================================================================
--- geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/NIOServlet.java
(original)
+++ geronimo/samples/trunk/samples/async-http/http-local-app/src/main/java/org/apache/geronimo/NIOServlet.java
Thu Nov 29 06:09:25 2007
@@ -1,23 +1,16 @@
 package org.apache.geronimo;
 
-import java.io.BufferedReader;
+import java.io.InterruptedIOException;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.net.URL;
-import java.util.Random;
 import java.io.OutputStream;
+import java.util.Random;
 import java.util.Date;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import org.apache.http.nio.reactor.SessionRequestCallback;
 
-import java.io.InterruptedIOException;
 import java.net.InetSocketAddress;
 import org.apache.catalina.CometEvent;
 import org.apache.catalina.CometProcessor;
@@ -65,16 +58,14 @@
     static final long serialVersionUID = 1L;
 
     String remoteUrl;
-    private static HttpParams httpParams = new BasicHttpParams(null);
-    private static BasicHttpProcessor httpproc = new BasicHttpProcessor();
     private static ConnectingIOReactor ioReactor;
-    private static IOEventDispatch ioEventDispatch;
 
     public void init() throws ServletException {
         getServletContext().log("getinit init");
         // Get the value of an initialization parameter
         remoteUrl = getServletConfig().getInitParameter("remoteUrl");
 
+        HttpParams httpParams = new BasicHttpParams(null);
         httpParams
         .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
         .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000)
@@ -83,6 +74,7 @@
         .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
         .setParameter(CoreProtocolPNames.USER_AGENT, "HttpComponents/1.1");
 
+        BasicHttpProcessor httpproc = new BasicHttpProcessor();
         httpproc.addInterceptor(new RequestContent());
         httpproc.addInterceptor(new RequestTargetHost());
         httpproc.addInterceptor(new RequestConnControl());
@@ -94,7 +86,7 @@
 
         handler.setEventListener(new EventLogger());
 
-        ioEventDispatch = new DefaultClientIOEventDispatch(handler, httpParams);
+        final IOEventDispatch ioEventDispatch = new DefaultClientIOEventDispatch(handler,
httpParams);
 
         try {
             ioReactor = new DefaultConnectingIOReactor(20, httpParams);
@@ -103,6 +95,24 @@
             throw new ServletException(e);
         }
 
+        Thread t = new Thread(new Runnable() {
+
+                public void run() {
+                    try {
+                        System.out.println("Running...");
+                        ioReactor.execute(ioEventDispatch);
+                    }
+                    catch ( InterruptedIOException ex ) {
+                        System.err.println("Interrupted");
+                    }
+                    catch ( IOException e ) {
+                        System.err.println("I/O error: " + e.getMessage());
+                    }
+                    System.out.println("Shutdown");
+                }
+            });
+
+        t.start();
     }
 
     @Override
@@ -155,26 +165,6 @@
             String url_string = remoteUri + "?sessionId=" + sessionId + "&delay=" + params[0]
+ "&code=" + params[1];       
 
             
-            Thread t = new Thread(new Runnable() {
-
-                                      public void run() {
-                                          try {
-                                              System.out.println("Running...");
-                                              ioReactor.execute(ioEventDispatch);
-                                          }
-                                          catch ( InterruptedIOException ex ) {
-                                              System.err.println("Interrupted");
-                                          }
-                                          catch ( IOException e ) {
-                                              System.err.println("I/O error: " + e.getMessage());
-                                          }
-                                          System.out.println("Shutdown");
-                                      }
-
-                                  });
-            t.start();
-            
-            
             SessionRequest reqs = ioReactor.connect(new InetSocketAddress(remoteUrl, 8080),
null, new MyAttachment(event, sessionId, url_string), null);
 
             System.out.println("event BEGIN processed");
@@ -182,6 +172,8 @@
         else if ( (event.getEventType() == CometEvent.EventType.ERROR)  || (event.getEventType()
== CometEvent.EventType.END) ) {
             event.close();
         }
+
+        
 
     }
 



Mime
View raw message