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 import java.net.*;
00032
00033 import org.openmobileis.common.context.SessionContextManager;
00034 import org.openmobileis.common.util.log.*;
00035
00043 public class ServerThread implements Runnable {
00044
00045 private WebServerConnection connexion;
00046 private Object waiter;
00047 private ServerThreadPool threadPool;
00048 private boolean mustStop = false;
00049
00050 public ServerThread() {
00051 waiter = new Object();
00052 connexion = new WebServerConnection();
00053 Thread thread = new Thread( this );
00054 thread.start();
00055 }
00056
00057 public void run() {
00058 while (mustStop == false) {
00059 try {
00060 synchronized (waiter) {
00061 try {
00062 if (threadPool != null) {
00063 threadPool.disposeObject(this);
00064 }
00065 waiter.wait();
00066 } catch (Exception ex) {
00067 LogManager.traceError(0, ex);
00068 }
00069 }
00070 if (mustStop) {
00071 break;
00072 }
00073 connexion.run();
00074 } catch (Throwable ex) {
00075 LogManager.traceError(LogServices.WEBSERVICE,"ServerThread run connexion error");
00076 LogManager.traceError(LogServices.WEBSERVICE,ex);
00077 }
00078 }
00079 }
00080
00081 public void init(WebServer webserver, Socket socket,ServerThreadPool pool) {
00082 threadPool = pool;
00083 connexion.init(webserver, socket);
00084 synchronized (waiter) {
00085 waiter.notify();
00086 }
00087 }
00088
00089 public WebServerConnection getConnexion() {
00090 return connexion;
00091 }
00092
00093 public void notifyStop() {
00094 this.mustStop = true;
00095 synchronized (waiter) {
00096 waiter.notify();
00097 }
00098 }
00099
00100
00101 }