1 5 package com.teamkonzept.web; 6 7 import java.io.*; 8 import java.util.*; 9 import org.apache.log4j.Category; 10 11 import com.teamkonzept.lib.*; 12 15 16 62 public class TKHttpThread implements Runnable 63 { 64 65 68 private static final Category CATEGORY = Category.getInstance(TKHttpThread.class); 69 70 71 protected Thread myThread; 72 73 74 protected TKHttpInterface httpInterface; 75 76 77 static TKEventHandler handler = com.teamkonzept.webman.mainint.WebManThread.getInstance(); 78 79 public PrintStream log; 80 81 87 public TKHttpThread( TKHttpInterface httpInterface ) 88 { 89 this.httpInterface = httpInterface; 90 93 this.log = new TKByteArrayPrintStream (httpInterface.getLogStream()); 94 } 95 96 104 public void register() 105 { 106 myThread = Thread.currentThread(); 107 TKHttp.register( myThread, this, httpInterface ); 108 } 109 110 115 public void deregister() 116 { 117 120 try { 121 log.flush(); 122 } 123 catch( Exception e ) { 124 CATEGORY.error( "deregister: ", e); 125 } 126 finally 127 { 128 TKHttp.deregister( myThread ); 129 } 130 } 131 132 141 public void init() 142 { 143 149 } 150 151 152 153 162 public void start() 163 { 164 try { 165 TKEvent event = handler.createEvent(httpInterface); 166 171 handleEvent( event ); 172 event.consume(); 173 } 174 catch( Throwable e ) { 175 log.println( "message: "+e.getMessage() ); 176 e.printStackTrace( log ); 177 } 178 } 179 180 188 public void run() 189 { 190 register(); 192 start(); 194 deregister(); 195 } 197 198 204 public TKHTMLTemplate prepTemplate( TKHTMLTemplate t ) 205 { 206 t.set( "SELF", httpInterface.getOwnURL() ); 207 t.setAppName( httpInterface.getOwnName() ); 208 return t; 209 } 210 211 217 223 230 public void handleEvent( TKEvent event ) throws Exception 231 { 232 handler.handleEvent(event); 233 } 234 235 236 241 266 } 267 268 | Popular Tags |