changeset 887:df84a1741687

make Connector reference to server explicit
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Oct 2016 23:59:56 -0600
parents 0d876a03ab0b
children 1aa58272794f
files src/org/eclipse/jetty/server/Connector.java src/org/eclipse/jetty/server/Request.java src/org/eclipse/jetty/server/Response.java src/org/eclipse/jetty/server/Server.java src/org/eclipse/jetty/server/nio/AbstractNIOConnector.java src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java src/org/eclipse/jetty/server/nio/SelectChannelConnector.java src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java
diffstat 8 files changed, 43 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/Connector.java
--- a/src/org/eclipse/jetty/server/Connector.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/Connector.java	Tue Oct 04 23:59:56 2016 -0600
@@ -59,9 +59,9 @@
 
 	private String _name;
 
-	private Server _server;
+	public final Server server;
 	private String _host;
-	private int _port = 0;
+	public final int port;
 	private String _integralScheme = HttpSchemes.HTTPS;
 	private int _integralPort = 0;
 	private String _confidentialScheme = HttpSchemes.HTTPS;
@@ -89,35 +89,14 @@
 
 	protected final HttpBuffersImpl _buffers = new HttpBuffersImpl();
 
-	/* ------------------------------------------------------------ */
-	/**
-	 */
-	public Connector()
-	{
+	public Connector(Server server,int port) {
+		this.server = server;
+		this.port = port;
+		server.connectors.add(this);
 		addBean(_buffers);
 	}
 
 	/* ------------------------------------------------------------ */
-	/*
-	 */
-	public Server getServer()
-	{
-		return _server;
-	}
-
-	/* ------------------------------------------------------------ */
-	public void setServer(Server server)
-	{
-		_server = server;
-	}
-
-	/* ------------------------------------------------------------ */
-	public ThreadPoolExecutor getThreadPool()
-	{
-		return _server.threadPool;
-	}
-
-	/* ------------------------------------------------------------ */
 	/**
 	 */
 	public void setHost(String host)
@@ -134,18 +113,6 @@
 	}
 
 	/* ------------------------------------------------------------ */
-	public void setPort(int port)
-	{
-		_port = port;
-	}
-
-	/* ------------------------------------------------------------ */
-	public int getPort()
-	{
-		return _port;
-	}
-
-	/* ------------------------------------------------------------ */
 	/**
 	 * @return Returns the maxIdleTime.
 	 */
@@ -284,9 +251,6 @@
 	@Override
 	protected void doStart() throws Exception
 	{
-		if (_server == null)
-			throw new IllegalStateException("No server");
-
 		// open listener port
 		open();
 
@@ -297,10 +261,10 @@
 		{
 			_acceptorThreads = new Thread[getAcceptors()];
 
-			ThreadPoolExecutor _threadPool = getThreadPool();
+			ThreadPoolExecutor _threadPool = server.threadPool;
 			for (int i = 0; i < _acceptorThreads.length; i++)
 				_threadPool.execute(new Acceptor(i));
-			if (_server.isLowOnThreads())
+			if (server.isLowOnThreads())
 				LOG.warn("insufficient threads configured for {}",this);
 		}
 
@@ -861,7 +825,7 @@
 		return String.format("%s@%s:%d",
 				getClass().getSimpleName(),
 				getHost()==null?"0.0.0.0":getHost(),
-				getLocalPort()<=0?getPort():getLocalPort());
+				getLocalPort()<=0 ? port : getLocalPort());
 	}
 
 	/* ------------------------------------------------------------ */
@@ -938,7 +902,7 @@
 	public String getName()
 	{
 		if (_name == null)
-			_name = (getHost() == null?"0.0.0.0":getHost()) + ":" + (getLocalPort() <= 0?getPort():getLocalPort());
+			_name = (getHost() == null?"0.0.0.0":getHost()) + ":" + (getLocalPort() <= 0?port:getLocalPort());
 		return _name;
 	}
 
@@ -1008,7 +972,7 @@
 	/* ------------------------------------------------------------ */
 	public final boolean isLowResources()
 	{
-		return _server.isLowOnThreads();
+		return server.isLowOnThreads();
 	}
 
 	/* ------------------------------------------------------------ */
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/Request.java
--- a/src/org/eclipse/jetty/server/Request.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/Request.java	Tue Oct 04 23:59:56 2016 -0600
@@ -271,7 +271,7 @@
 							
 							if (maxFormContentSize < 0)
 							{
-								Object obj = _connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
+								Object obj = _connection.getConnector().server.getAttribute("org.eclipse.jetty.server.Request.maxFormContentSize");
 								if (obj == null)
 									maxFormContentSize = 200000;
 								else if (obj instanceof Number)
@@ -287,7 +287,7 @@
 							
 							if (maxFormKeys < 0)
 							{
-								Object obj = _connection.getConnector().getServer().getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
+								Object obj = _connection.getConnector().server.getAttribute("org.eclipse.jetty.server.Request.maxFormKeys");
 								if (obj == null)
 									maxFormKeys = 1000;
 								else if (obj instanceof Number)
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/Response.java
--- a/src/org/eclipse/jetty/server/Response.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/Response.java	Tue Oct 04 23:59:56 2016 -0600
@@ -252,7 +252,7 @@
 			if (context!=null)
 				error_handler=context.getContextHandler().getErrorHandler();
 			if (error_handler==null)
-				error_handler = _connection.getConnector().getServer().getBean(ErrorHandler.class);
+				error_handler = _connection.getConnector().server.getBean(ErrorHandler.class);
 			if (error_handler!=null)
 			{
 				request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE,new Integer(code));
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/Server.java
--- a/src/org/eclipse/jetty/server/Server.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/Server.java	Tue Oct 04 23:59:56 2016 -0600
@@ -62,29 +62,18 @@
 	public static final String version = "8";
 
 	private final AttributesMap _attributes = new AttributesMap();
-	public final ThreadPoolExecutor threadPool;
-	private final List<Connector> connectors = new ArrayList<Connector>();
+	public final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
+	final List<Connector> connectors = new ArrayList<Connector>();
 
 
-	/* ------------------------------------------------------------ */
-	/** Convenience constructor
-	 * Creates server and a {@link SelectChannelConnector} at the passed port.
-	 */
+	public Server() {
+		setServer(this);
+	}
+
 	public Server(int port)
 	{
 		setServer(this);
-
-		Connector connector = new SelectChannelConnector();
-		connector.setPort(port);
-		connector.setServer(this);
-		connectors.add(connector);
-
-		threadPool = new ThreadPoolExecutor(256, 256, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
-	}
-
-	// call before start
-	public void addConnector(Connector connector) {
-		connectors.add(connector);
+		new SelectChannelConnector(this,port);
 	}
 
 	/* ------------------------------------------------------------ */
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/nio/AbstractNIOConnector.java
--- a/src/org/eclipse/jetty/server/nio/AbstractNIOConnector.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/AbstractNIOConnector.java	Tue Oct 04 23:59:56 2016 -0600
@@ -23,11 +23,13 @@
 
 import org.eclipse.jetty.io.Buffers.Type;
 import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
 
 public abstract class AbstractNIOConnector extends Connector implements NIOConnector
 {
-	public AbstractNIOConnector()
+	public AbstractNIOConnector(Server server,int port)
 	{
+		super(server,port);
 		_buffers.setRequestBufferType(Type.DIRECT);
 		_buffers.setRequestHeaderType(Type.INDIRECT);
 		_buffers.setResponseBufferType(Type.DIRECT);
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java
--- a/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Tue Oct 04 23:59:56 2016 -0600
@@ -38,6 +38,7 @@
 import org.eclipse.jetty.io.nio.ChannelEndPoint;
 import org.eclipse.jetty.server.BlockingHttpConnection;
 import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,8 +67,9 @@
 	/** Constructor.
 	 *
 	 */
-	public BlockingChannelConnector()
+	public BlockingChannelConnector(Server server,int port)
 	{
+		super(server,port);
 	}
 
 	/* ------------------------------------------------------------ */
@@ -84,7 +86,7 @@
 	protected void doStart() throws Exception
 	{
 		super.doStart();
-		getThreadPool().execute(new Runnable()
+		server.threadPool.execute(new Runnable()
 		{
 
 			public void run()
@@ -124,7 +126,7 @@
 		_acceptChannel.configureBlocking(true);
 
 		// Bind the server socket to the local host and port
-		InetSocketAddress addr = getHost()==null?new InetSocketAddress(getPort()):new InetSocketAddress(getHost(),getPort());
+		InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port);
 		_acceptChannel.socket().bind(addr,getAcceptQueueSize());
 	}
 
@@ -182,7 +184,7 @@
 			throws IOException
 		{
 			super(channel,BlockingChannelConnector.this._maxIdleTime);
-			_connection = new BlockingHttpConnection(BlockingChannelConnector.this,this,getServer());
+			_connection = new BlockingHttpConnection(BlockingChannelConnector.this,this,server);
 		}
 
 		/* ------------------------------------------------------------ */
@@ -226,7 +228,7 @@
 		void dispatch() throws IOException
 		{
 			try {
-				getThreadPool().execute(this);
+				server.threadPool.execute(this);
 			} catch(RejectedExecutionException e) {
 				LOG.warn("dispatch failed for  {}",_connection);
 				super.close();
@@ -280,7 +282,7 @@
 					_idleTimestamp=System.currentTimeMillis();
 					if (_connection.isIdle())
 					{
-						if (getServer().isLowOnThreads())
+						if (server.isLowOnThreads())
 						{
 							int lrmit = getLowResourcesMaxIdleTime();
 							if (lrmit>=0 && _timeout!= lrmit)
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/nio/SelectChannelConnector.java
--- a/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/SelectChannelConnector.java	Tue Oct 04 23:59:56 2016 -0600
@@ -36,6 +36,7 @@
 import org.eclipse.jetty.io.nio.SelectorManager.SelectSet;
 import org.eclipse.jetty.server.AsyncHttpConnection;
 import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
 
 /* ------------------------------------------------------------------------------- */
 /**
@@ -77,8 +78,9 @@
 	 * Constructor.
 	 *
 	 */
-	public SelectChannelConnector()
+	public SelectChannelConnector(Server server,int port)
 	{
+		super(server,port);
 		_manager.setMaxIdleTime(getMaxIdleTime());
 		addBean(_manager,true);
 		setAcceptors(Math.max(1,(Runtime.getRuntime().availableProcessors()+3)/4));
@@ -173,7 +175,7 @@
 
 				// Bind the server socket to the local host and port
 				_acceptChannel.socket().setReuseAddress(getReuseAddress());
-				InetSocketAddress addr = getHost()==null?new InetSocketAddress(getPort()):new InetSocketAddress(getHost(),getPort());
+				InetSocketAddress addr = getHost()==null?new InetSocketAddress(port):new InetSocketAddress(getHost(),port);
 				_acceptChannel.socket().bind(addr,getAcceptQueueSize());
 
 				_localPort=_acceptChannel.socket().getLocalPort();
@@ -272,7 +274,7 @@
 	/* ------------------------------------------------------------------------------- */
 	protected AsyncConnection newConnection(SocketChannel channel,final AsyncEndPoint endpoint)
 	{
-		return new AsyncHttpConnection(SelectChannelConnector.this,endpoint,getServer());
+		return new AsyncHttpConnection(SelectChannelConnector.this,endpoint,server);
 	}
 
 
@@ -284,7 +286,7 @@
 		@Override
 		public void execute(Runnable task)
 		{
-			getThreadPool().execute(task);
+			server.threadPool.execute(task);
 		}
 
 		@Override
diff -r 0d876a03ab0b -r df84a1741687 src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java
--- a/src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java	Tue Oct 04 20:27:50 2016 -0600
+++ b/src/org/eclipse/jetty/server/ssl/SslSelectChannelConnector.java	Tue Oct 04 23:59:56 2016 -0600
@@ -36,6 +36,7 @@
 import org.eclipse.jetty.io.nio.AsyncConnection;
 import org.eclipse.jetty.io.nio.SslConnection;
 import org.eclipse.jetty.server.Request;
+import org.eclipse.jetty.server.Server;
 import org.eclipse.jetty.server.nio.SelectChannelConnector;
 import org.eclipse.jetty.util.component.AggregateLifeCycle;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
@@ -52,9 +53,9 @@
 	private Buffers _sslBuffers;
 
 	/* ------------------------------------------------------------ */
-	public SslSelectChannelConnector()
+	public SslSelectChannelConnector(Server server,int port)
 	{
-		this(new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH));
+		this(new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH),server,port);
 		setSoLingerTime(30000);
 	}
 
@@ -64,8 +65,9 @@
 	 * it's lifecycle may be managed with {@link AggregateLifeCycle}.
 	 * @param sslContextFactory
 	 */
-	public SslSelectChannelConnector(SslContextFactory sslContextFactory)
+	public SslSelectChannelConnector(SslContextFactory sslContextFactory,Server server,int port)
 	{
+		super(server,port);
 		_sslContextFactory = sslContextFactory;
 		addBean(_sslContextFactory);
 		setUseDirectBuffers(false);