00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 package org.openmobileis.embedded.webserver;
00031
00032 import org.openmobileis.common.util.ObjectPool;
00033 import org.openmobileis.common.util.log.*;
00034 import org.openmobileis.common.util.exception.ServerException;
00035 import java.net.*;
00036
00037 import javax.servlet.ServletContext;
00038
00046 public class ServerThreadPool extends ObjectPool {
00047 class HTTPConnexionMaintener implements Runnable {
00048 public java.util.ArrayList connList;
00049
00050 HTTPConnexionMaintener() {
00051 connList = new java.util.ArrayList(5);
00052 }
00053
00054 public void run() {
00055 while (true) {
00056 try {
00057 Thread.currentThread().sleep(60000);
00058 } catch (Throwable ex) {
00059 LogManager.trace(new ServerException("Error in Thread that maintain ServletConnexion open", ex));
00060 }
00061 long timeout = System.currentTimeMillis() - 60000;
00062 WebServerConnection conn = null;
00063 java.io.OutputStream stream = null;
00064 for (int i=0; i<connList.size(); i++) {
00065 conn = (WebServerConnection)connList.get(i);
00066 if(conn.connexionLifeTime < timeout) {
00067 try {
00068 stream = conn.getOutputStream();
00069 stream.write(' ');
00070 } catch (Throwable ex) {
00071 this.unregisterConnexion(conn);
00072 }
00073 }
00074 }
00075 }
00076 }
00077
00078 public void registerConnexion(WebServerConnection connexion) {
00079 connList.add(connexion);
00080 }
00081
00082 public void unregisterConnexion(WebServerConnection connexion) {
00083 connList.remove(connexion);
00084 }
00085
00086 }
00087
00088
00089
00090 public ServerThreadPool() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
00091 super("org.openmobileis.embedded.webserver.ServerThread", 5, 5);
00092
00093 }
00094
00095 public synchronized void disposeObject(Object object) {
00096
00097 super.disposeObject(object);
00098 }
00099
00100 public void runServerConnexion(WebServer webserver, Socket socket) {
00101 ServerThread thread = (ServerThread) super.getObject();
00102 if (thread == null) {
00103 LogManager.traceEmergency(LogServices.SYNCHROSERVICE, "Object pool error ServerThread from pool NULL. Create one. System must be repared.");
00104 thread = new ServerThread();
00105 }
00106
00107 try {
00108
00109 thread.init(webserver, socket, this);
00110 } catch (Exception ex) {
00111 LogManager.trace(new ServerException("Error during threadPool init", ex));
00112 LogManager.traceError(0, ex);
00113 }
00114 }
00115 }