Mercurial Hosting > luan
diff src/org/eclipse/jetty/server/Server.java @ 876:2efdb98f3543
use just one fixed Connector in Server
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 04 Oct 2016 14:05:45 -0600 |
parents | b9aa175d9a29 |
children | fef4392f4905 |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/Server.java Tue Oct 04 13:45:47 2016 -0600 +++ b/src/org/eclipse/jetty/server/Server.java Tue Oct 04 14:05:45 2016 -0600 @@ -20,6 +20,7 @@ import java.io.IOException; import java.net.InetSocketAddress; +import java.util.Collections; import java.util.Enumeration; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -62,7 +63,7 @@ private final AttributesMap _attributes = new AttributesMap(); public final ThreadPoolExecutor threadPool; - private Connector[] _connectors; + public final Connector connector; private boolean _sendServerVersion = true; //send Server: header private boolean _sendDateHeader = false; //send Date: header private int _graceful=0; @@ -80,9 +81,9 @@ { setServer(this); - Connector connector=new SelectChannelConnector(); + connector = new SelectChannelConnector(); connector.setPort(port); - setConnectors(new Connector[]{connector}); + connector.setServer(this); threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); } @@ -120,47 +121,6 @@ _stopAtShutdown=stop; } - /* ------------------------------------------------------------ */ - /** - * @return Returns the connectors. - */ - public Connector[] getConnectors() - { - return _connectors; - } - - /* ------------------------------------------------------------ */ - public void addConnector(Connector connector) - { - setConnectors((Connector[])LazyList.addToArray(getConnectors(), connector, Connector.class)); - } - - /* ------------------------------------------------------------ */ - /** - * Conveniance method which calls {@link #getConnectors()} and {@link #setConnectors(Connector[])} to - * remove a connector. - * @param connector The connector to remove. - */ - public void removeConnector(Connector connector) { - setConnectors((Connector[])LazyList.removeFromArray (getConnectors(), connector)); - } - - /* ------------------------------------------------------------ */ - /** Set the connectors for this server. - * Each connector has this server set as it's ThreadPool and its Handler. - * @param connectors The connectors to set. - */ - public void setConnectors(Connector[] connectors) - { - if (connectors!=null) - { - for (int i=0;i<connectors.length;i++) - connectors[i].setServer(this); - } - - _connectors = connectors; - } - /** * @return true if {@link #dumpStdErr()} is called after starting */ @@ -220,15 +180,12 @@ mex.add(e); } - if (_connectors!=null && mex.size()==0) + if (mex.size()==0) { - for (int i=0;i<_connectors.length;i++) + try{connector.start();} + catch(Throwable e) { - try{_connectors[i].start();} - catch(Throwable e) - { - mex.add(e); - } + mex.add(e); } } @@ -249,14 +206,8 @@ if (_graceful>0) { - if (_connectors!=null) - { - for (int i=_connectors.length;i-->0;) - { - LOG.info("Graceful shutdown {}",_connectors[i]); - try{_connectors[i].close();}catch(Throwable e){mex.add(e);} - } - } + LOG.info("Graceful shutdown {}",connector); + try{connector.close();}catch(Throwable e){mex.add(e);} Handler[] contexts = getChildHandlersByClass(Graceful.class); for (int c=0;c<contexts.length;c++) @@ -268,11 +219,7 @@ Thread.sleep(_graceful); } - if (_connectors!=null) - { - for (int i=_connectors.length;i-->0;) - try{_connectors[i].stop();}catch(Throwable e){mex.add(e);} - } + try{connector.stop();}catch(Throwable e){mex.add(e);} threadPool.shutdownNow(); @@ -481,7 +428,7 @@ public void dump(Appendable out,String indent) throws IOException { dumpThis(out); - dump(out,indent,TypeUtil.asList(getHandlers()),getBeans(),TypeUtil.asList(_connectors)); + dump(out,indent,TypeUtil.asList(getHandlers()),getBeans(),Collections.singletonList(connector)); }