comparison src/org/eclipse/jetty/server/Connector.java @ 954:a021c4c9c244

use just one SelectSet per SelectorManager
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 13 Oct 2016 00:54:10 -0600
parents f5aefdc4a81a
children 1094975d013b
comparison
equal deleted inserted replaced
953:7db4a488fc82 954:a021c4c9c244
52 * <li>Socket configuration</li> 52 * <li>Socket configuration</li>
53 * <li>Base acceptor thread</li> 53 * <li>Base acceptor thread</li>
54 * <li>Optional reverse proxy headers checking</li> 54 * <li>Optional reverse proxy headers checking</li>
55 * </ul> 55 * </ul>
56 */ 56 */
57 public abstract class Connector extends AggregateLifeCycle implements HttpBuffers, Dumpable 57 public abstract class Connector extends AggregateLifeCycle implements HttpBuffers, Dumpable, Runnable
58 { 58 {
59 private static final Logger LOG = LoggerFactory.getLogger(Connector.class); 59 private static final Logger LOG = LoggerFactory.getLogger(Connector.class);
60 60
61 private String _name; 61 private String _name;
62 62
63 public final Server server; 63 public final Server server;
64 private String _host; 64 private String _host;
65 public final int port; 65 public final int port;
66 private int _acceptors = 1;
67 66
68 protected final int _maxIdleTime = 200000; 67 protected final int _maxIdleTime = 200000;
69 protected int _soLingerTime = -1; 68 protected int _soLingerTime = -1;
70 69
71 protected final HttpBuffersImpl _buffers = new HttpBuffersImpl(); 70 protected final HttpBuffersImpl _buffers = new HttpBuffersImpl();
135 return _soLingerTime; 134 return _soLingerTime;
136 } 135 }
137 136
138 /* ------------------------------------------------------------ */ 137 /* ------------------------------------------------------------ */
139 /** 138 /**
140 * @return Returns the number of acceptor threads.
141 */
142 public int getAcceptors()
143 {
144 return _acceptors;
145 }
146
147 /* ------------------------------------------------------------ */
148 /**
149 * @param acceptors
150 * The number of acceptor threads to set.
151 */
152 public void setAcceptors(int acceptors)
153 {
154 if (acceptors > 2 * Runtime.getRuntime().availableProcessors())
155 LOG.warn("Acceptors should be <=2*availableProcessors: " + this);
156 _acceptors = acceptors;
157 }
158
159 /* ------------------------------------------------------------ */
160 /**
161 * @param soLingerTime 139 * @param soLingerTime
162 * The soLingerTime to set or -1 to disable. 140 * The soLingerTime to set or -1 to disable.
163 */ 141 */
164 public void setSoLingerTime(int soLingerTime) 142 public void setSoLingerTime(int soLingerTime)
165 { 143 {
171 { 149 {
172 super.doStart(); 150 super.doStart();
173 151
174 // Start selector thread 152 // Start selector thread
175 ThreadPoolExecutor _threadPool = server.threadPool; 153 ThreadPoolExecutor _threadPool = server.threadPool;
176 for (int i = 0; i < _acceptors; i++) 154 _threadPool.execute(this);
177 _threadPool.execute(new Acceptor());
178 if (server.isLowOnThreads()) 155 if (server.isLowOnThreads())
179 LOG.warn("insufficient threads configured for {}",this); 156 LOG.warn("insufficient threads configured for {}",this);
180 157
181 LOG.info("Started {}",this); 158 LOG.info("Started {}",this);
182 } 159 }
320 getHost()==null?"0.0.0.0":getHost(), 297 getHost()==null?"0.0.0.0":getHost(),
321 port); 298 port);
322 } 299 }
323 300
324 301
325 private class Acceptor implements Runnable 302 public void run()
326 { 303 {
327 304 Thread current = Thread.currentThread();
328 public void run() 305 String name = current.getName();
306 current.setName(name + " Acceptor" + " " + Connector.this);
307
308 try
329 { 309 {
330 Thread current = Thread.currentThread(); 310 while (isRunning() && _acceptChannel != null)
331 String name = current.getName();
332 current.setName(name + " Acceptor" + " " + Connector.this);
333
334 try
335 { 311 {
336 while (isRunning() && _acceptChannel != null) 312 try
337 { 313 {
338 try 314 accept();
339 { 315 }
340 accept(); 316 catch (EofException e)
341 } 317 {
342 catch (EofException e) 318 LOG.trace("",e);
343 { 319 }
344 LOG.trace("",e); 320 catch (IOException e)
345 } 321 {
346 catch (IOException e) 322 LOG.trace("",e);
347 { 323 }
348 LOG.trace("",e); 324 catch (InterruptedException x)
349 } 325 {
350 catch (InterruptedException x) 326 // Connector has been stopped
351 { 327 LOG.trace("",x);
352 // Connector has been stopped 328 }
353 LOG.trace("",x); 329 catch (Throwable e)
354 } 330 {
355 catch (Throwable e) 331 LOG.warn("",e);
356 {
357 LOG.warn("",e);
358 }
359 } 332 }
360 } 333 }
361 finally 334 }
362 { 335 finally
363 current.setName(name); 336 {
364 } 337 current.setName(name);
365 } 338 }
366 } 339 }
367 340
368 public String getName() 341 public String getName()
369 { 342 {