Mercurial Hosting > luan
comparison src/org/eclipse/jetty/server/Server.java @ 864:e21ca9878a10
simplify ThreadPool use
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 02 Oct 2016 16:17:38 -0600 |
parents | 22a4e93ed20e |
children | 6b210bb66c63 |
comparison
equal
deleted
inserted
replaced
863:88d3c8ff242a | 864:e21ca9878a10 |
---|---|
55 */ | 55 */ |
56 public class Server extends HandlerWrapper implements Attributes | 56 public class Server extends HandlerWrapper implements Attributes |
57 { | 57 { |
58 private static final Logger LOG = LoggerFactory.getLogger(Server.class); | 58 private static final Logger LOG = LoggerFactory.getLogger(Server.class); |
59 | 59 |
60 private static final String __version; | 60 private static final String __version = "8"; |
61 static | |
62 { | |
63 if (Server.class.getPackage()!=null && | |
64 "Eclipse.org - Jetty".equals(Server.class.getPackage().getImplementationVendor()) && | |
65 Server.class.getPackage().getImplementationVersion()!=null) | |
66 __version=Server.class.getPackage().getImplementationVersion(); | |
67 else | |
68 __version=System.getProperty("jetty.version","8.y.z-SNAPSHOT"); | |
69 } | |
70 | 61 |
71 private final AttributesMap _attributes = new AttributesMap(); | 62 private final AttributesMap _attributes = new AttributesMap(); |
72 private ThreadPool _threadPool; | 63 private final ThreadPool _threadPool; |
73 private Connector[] _connectors; | 64 private Connector[] _connectors; |
74 private boolean _sendServerVersion = true; //send Server: header | 65 private boolean _sendServerVersion = true; //send Server: header |
75 private boolean _sendDateHeader = false; //send Date: header | 66 private boolean _sendDateHeader = false; //send Date: header |
76 private int _graceful=0; | 67 private int _graceful=0; |
77 private boolean _stopAtShutdown; | 68 private boolean _stopAtShutdown; |
79 private boolean _dumpBeforeStop=false; | 70 private boolean _dumpBeforeStop=false; |
80 private boolean _uncheckedPrintWriter=false; | 71 private boolean _uncheckedPrintWriter=false; |
81 | 72 |
82 | 73 |
83 /* ------------------------------------------------------------ */ | 74 /* ------------------------------------------------------------ */ |
84 public Server() | |
85 { | |
86 setServer(this); | |
87 } | |
88 | |
89 /* ------------------------------------------------------------ */ | |
90 /** Convenience constructor | 75 /** Convenience constructor |
91 * Creates server and a {@link SelectChannelConnector} at the passed port. | 76 * Creates server and a {@link SelectChannelConnector} at the passed port. |
92 */ | 77 */ |
93 public Server(int port) | 78 public Server(int port) |
94 { | 79 { |
95 setServer(this); | 80 setServer(this); |
96 | 81 |
97 Connector connector=new SelectChannelConnector(); | 82 Connector connector=new SelectChannelConnector(); |
98 connector.setPort(port); | 83 connector.setPort(port); |
99 setConnectors(new Connector[]{connector}); | 84 setConnectors(new Connector[]{connector}); |
100 } | 85 |
101 | 86 _threadPool = new QueuedThreadPool(); |
102 /* ------------------------------------------------------------ */ | 87 addBean(_threadPool); |
103 /** Convenience constructor | |
104 * Creates server and a {@link SelectChannelConnector} at the passed address. | |
105 */ | |
106 public Server(InetSocketAddress addr) | |
107 { | |
108 setServer(this); | |
109 | |
110 Connector connector=new SelectChannelConnector(); | |
111 connector.setHost(addr.getHostName()); | |
112 connector.setPort(addr.getPort()); | |
113 setConnectors(new Connector[]{connector}); | |
114 } | 88 } |
115 | 89 |
116 | 90 |
117 /* ------------------------------------------------------------ */ | 91 /* ------------------------------------------------------------ */ |
118 public static String getVersion() | 92 public static String getVersion() |
194 public ThreadPool getThreadPool() | 168 public ThreadPool getThreadPool() |
195 { | 169 { |
196 return _threadPool; | 170 return _threadPool; |
197 } | 171 } |
198 | 172 |
199 /* ------------------------------------------------------------ */ | |
200 /** | |
201 * @param threadPool The threadPool to set. | |
202 */ | |
203 public void setThreadPool(ThreadPool threadPool) | |
204 { | |
205 if (_threadPool!=null) | |
206 removeBean(_threadPool); | |
207 _threadPool = threadPool; | |
208 if (_threadPool!=null) | |
209 addBean(_threadPool); | |
210 } | |
211 | |
212 /** | 173 /** |
213 * @return true if {@link #dumpStdErr()} is called after starting | 174 * @return true if {@link #dumpStdErr()} is called after starting |
214 */ | 175 */ |
215 public boolean isDumpAfterStart() | 176 public boolean isDumpAfterStart() |
216 { | 177 { |
256 | 217 |
257 LOG.info("jetty-"+__version); | 218 LOG.info("jetty-"+__version); |
258 HttpGenerator.setServerVersion(__version); | 219 HttpGenerator.setServerVersion(__version); |
259 | 220 |
260 MultiException mex=new MultiException(); | 221 MultiException mex=new MultiException(); |
261 | |
262 if (_threadPool==null) | |
263 setThreadPool(new QueuedThreadPool()); | |
264 | 222 |
265 try | 223 try |
266 { | 224 { |
267 super.doStart(); | 225 super.doStart(); |
268 } | 226 } |
448 public void setMaxCookieVersion(int maxCookieVersion) | 406 public void setMaxCookieVersion(int maxCookieVersion) |
449 { | 407 { |
450 } | 408 } |
451 | 409 |
452 /* ------------------------------------------------------------ */ | 410 /* ------------------------------------------------------------ */ |
453 /** | |
454 * Add a LifeCycle object to be started/stopped | |
455 * along with the Server. | |
456 * @deprecated Use {@link #addBean(Object)} | |
457 * @param c | |
458 */ | |
459 @Deprecated | |
460 public void addLifeCycle (LifeCycle c) | |
461 { | |
462 addBean(c); | |
463 } | |
464 | |
465 /* ------------------------------------------------------------ */ | |
466 /** | |
467 * Add an associated bean. | |
468 * The bean will be added to the servers {@link Container} | |
469 * and if it is a {@link LifeCycle} instance, it will be | |
470 * started/stopped along with the Server. Any beans that are also | |
471 * {@link Destroyable}, will be destroyed with the server. | |
472 * @param o the bean object to add | |
473 */ | |
474 @Override | |
475 public boolean addBean(Object o) | |
476 { | |
477 if (super.addBean(o)) | |
478 { | |
479 return true; | |
480 } | |
481 return false; | |
482 } | |
483 | |
484 /** | |
485 * Remove a LifeCycle object to be started/stopped | |
486 * along with the Server | |
487 * @deprecated Use {@link #removeBean(Object)} | |
488 */ | |
489 @Deprecated | |
490 public void removeLifeCycle (LifeCycle c) | |
491 { | |
492 removeBean(c); | |
493 } | |
494 | |
495 /* ------------------------------------------------------------ */ | |
496 /** | |
497 * Remove an associated bean. | |
498 */ | |
499 @Override | |
500 public boolean removeBean (Object o) | |
501 { | |
502 if (super.removeBean(o)) | |
503 { | |
504 return true; | |
505 } | |
506 return false; | |
507 } | |
508 | |
509 /* ------------------------------------------------------------ */ | |
510 /* | 411 /* |
511 * @see org.eclipse.util.AttributesMap#clearAttributes() | 412 * @see org.eclipse.util.AttributesMap#clearAttributes() |
512 */ | 413 */ |
513 public void clearAttributes() | 414 public void clearAttributes() |
514 { | 415 { |