1 17 18 package org.apache.tomcat.util.net; 19 20 import java.net.InetAddress ; 21 import java.util.concurrent.Executor ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 import org.apache.tomcat.util.res.StringManager; 26 27 42 public abstract class BaseEndpoint { 43 44 45 47 48 protected static Log log = LogFactory.getLog(BaseEndpoint.class); 49 50 protected static StringManager sm = 51 StringManager.getManager("org.apache.tomcat.util.net.res"); 52 53 54 57 public static final String CIPHER_SUITE_KEY = "javax.servlet.request.cipher_suite"; 58 59 62 public static final String KEY_SIZE_KEY = "javax.servlet.request.key_size"; 63 64 67 public static final String CERTIFICATE_KEY = "javax.servlet.request.X509Certificate"; 68 69 73 public static final String SESSION_ID_KEY = "javax.servlet.request.ssl_session"; 74 75 76 78 79 82 protected volatile boolean running = false; 83 84 85 88 protected volatile boolean paused = false; 89 90 91 94 protected boolean initialized = false; 95 96 97 100 protected int curThreadsBusy = 0; 101 102 103 106 protected int curThreads = 0; 107 108 109 112 protected int sequence = 0; 113 114 115 117 118 121 protected Executor executor = null; 122 public void setExecutor(Executor executor) { this.executor = executor; } 123 public Executor getExecutor() { return executor; } 124 125 126 129 protected int maxThreads = 40; 130 public void setMaxThreads(int maxThreads) { this.maxThreads = maxThreads; } 131 public int getMaxThreads() { return maxThreads; } 132 133 134 137 protected int threadPriority = Thread.NORM_PRIORITY; 138 public void setThreadPriority(int threadPriority) { this.threadPriority = threadPriority; } 139 public int getThreadPriority() { return threadPriority; } 140 141 142 145 protected int port; 146 public int getPort() { return port; } 147 public void setPort(int port ) { this.port=port; } 148 149 150 153 protected InetAddress address; 154 public InetAddress getAddress() { return address; } 155 public void setAddress(InetAddress address) { this.address = address; } 156 157 158 163 protected int backlog = 100; 164 public void setBacklog(int backlog) { if (backlog > 0) this.backlog = backlog; } 165 public int getBacklog() { return backlog; } 166 167 168 171 protected boolean tcpNoDelay = false; 172 public boolean getTcpNoDelay() { return tcpNoDelay; } 173 public void setTcpNoDelay(boolean tcpNoDelay) { this.tcpNoDelay = tcpNoDelay; } 174 175 176 179 protected int soLinger = 100; 180 public int getSoLinger() { return soLinger; } 181 public void setSoLinger(int soLinger) { this.soLinger = soLinger; } 182 183 184 187 protected int soTimeout = -1; 188 public int getSoTimeout() { return soTimeout; } 189 public void setSoTimeout(int soTimeout) { this.soTimeout = soTimeout; } 190 191 192 197 protected boolean daemon = true; 198 public void setDaemon(boolean b) { daemon = b; } 199 public boolean getDaemon() { return daemon; } 200 201 202 205 protected String name = "TP"; 206 public void setName(String name) { this.name = name; } 207 public String getName() { return name; } 208 209 210 213 public int getMaxSpareThreads() { return 0; } 214 215 216 219 public int getMinSpareThreads() { return 0; } 220 221 222 224 225 230 public int getCurrentThreadCount() { 231 return curThreads; 232 } 233 234 235 240 public int getCurrentThreadsBusy() { 241 return curThreadsBusy; 242 } 243 244 245 250 public boolean isRunning() { 251 return running; 252 } 253 254 255 260 public boolean isPaused() { 261 return paused; 262 } 263 264 265 267 268 271 public abstract void init() 272 throws Exception ; 273 274 275 278 public abstract void start() 279 throws Exception ; 280 281 282 285 public void pause() { 286 if (running && !paused) { 287 paused = true; 288 unlockAccept(); 289 } 290 } 291 292 293 297 public void resume() { 298 if (running) { 299 paused = false; 300 } 301 } 302 303 304 307 public abstract void stop(); 308 309 310 313 public abstract void destroy() throws Exception ; 314 315 316 318 319 322 protected int getSequence() { 323 return sequence++; 324 } 325 326 327 330 protected void unlockAccept() { 331 java.net.Socket s = null; 332 try { 333 if (address == null) { 335 s = new java.net.Socket ("127.0.0.1", port); 336 } else { 337 s = new java.net.Socket (address, port); 338 s.setSoLinger(true, 0); 341 } 342 } catch(Exception e) { 343 if (log.isDebugEnabled()) { 344 log.debug(sm.getString("endpoint.debug.unlock", "" + port), e); 345 } 346 } finally { 347 if (s != null) { 348 try { 349 s.close(); 350 } catch (Exception e) { 351 } 353 } 354 } 355 } 356 357 358 } 359 | Popular Tags |