changeset 975:53b3f7d9714c

simplify BlockingChannelConnector
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 16 Oct 2016 01:10:02 -0600
parents 7422ca1ae146
children 0697c1219e70
files src/org/eclipse/jetty/server/Server.java src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java
diffstat 2 files changed, 31 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
diff -r 7422ca1ae146 -r 53b3f7d9714c src/org/eclipse/jetty/server/Server.java
--- a/src/org/eclipse/jetty/server/Server.java	Sat Oct 15 23:27:08 2016 -0600
+++ b/src/org/eclipse/jetty/server/Server.java	Sun Oct 16 01:10:02 2016 -0600
@@ -34,6 +34,7 @@
 
 import org.eclipse.jetty.http.HttpURI;
 import org.eclipse.jetty.server.handler.HandlerWrapper;
+import org.eclipse.jetty.server.nio.BlockingChannelConnector;
 import org.eclipse.jetty.server.nio.SelectChannelConnector;
 import org.eclipse.jetty.util.Attributes;
 import org.eclipse.jetty.util.AttributesMap;
@@ -73,7 +74,8 @@
 	public Server(int port)
 	{
 		setServer(this);
-		new SelectChannelConnector(this,port);
+//		new SelectChannelConnector(this,port);
+		new BlockingChannelConnector(this,port);
 	}
 
 	@Override
diff -r 7422ca1ae146 -r 53b3f7d9714c src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java
--- a/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Sat Oct 15 23:27:08 2016 -0600
+++ b/src/org/eclipse/jetty/server/nio/BlockingChannelConnector.java	Sun Oct 16 01:10:02 2016 -0600
@@ -75,7 +75,7 @@
 	protected void doStart() throws Exception
 	{
 		// Create a new server socket and set to non blocking mode
-		_acceptChannel= ServerSocketChannel.open();
+		_acceptChannel = ServerSocketChannel.open();
 		_acceptChannel.configureBlocking(true);
 
 		// Bind the server socket to the local host and port
@@ -93,7 +93,7 @@
 					try
 					{
 						Thread.sleep(400);
-						long now=System.currentTimeMillis();
+						long now = System.currentTimeMillis();
 						for (BlockingChannelEndPoint endp : _endpoints)
 						{
 							endp.checkIdleTimestamp(now);
@@ -123,8 +123,13 @@
 		Socket socket = channel.socket();
 		configure(socket);
 
-		BlockingChannelEndPoint connection=new BlockingChannelEndPoint(channel);
-		connection.dispatch();
+		BlockingChannelEndPoint connection = new BlockingChannelEndPoint(channel);
+		try {
+			server.threadPool.execute(connection);
+		} catch(RejectedExecutionException e) {
+			LOG.warn("dispatch failed for  {}",connection._connection);
+			connection.close();
+		}
 	}
 
 	@Override
@@ -150,80 +155,53 @@
 			_connection = new BlockingHttpConnection(BlockingChannelConnector.this,this);
 		}
 
-		public void checkIdleTimestamp(long now)
+		private void checkIdleTimestamp(long now)
 		{
 			if (_idleTimestamp!=0 && _timeout>0 && now>(_idleTimestamp+_timeout))
 			{
-				idleExpired();
-			}
-		}
-
-		protected void idleExpired()
-		{
-			try
-			{
-				super.close();
-			}
-			catch (IOException e)
-			{
-				LOG.trace("",e);
-			}
-		}
-
-		void dispatch() throws IOException
-		{
-			try {
-				server.threadPool.execute(this);
-			} catch(RejectedExecutionException e) {
-				LOG.warn("dispatch failed for  {}",_connection);
-				super.close();
+				try
+				{
+					close();
+				}
+				catch (IOException e)
+				{
+					LOG.trace("",e);
+				}
 			}
 		}
 
-		/* ------------------------------------------------------------ */
-		/**
-		 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#fill(org.eclipse.jetty.io.Buffer)
-		 */
 		@Override
 		public int fill(Buffer buffer) throws IOException
 		{
-			_idleTimestamp=System.currentTimeMillis();
+			_idleTimestamp = System.currentTimeMillis();
 			return super.fill(buffer);
 		}
 
-		/* ------------------------------------------------------------ */
-		/**
-		 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#flush(org.eclipse.jetty.io.Buffer)
-		 */
 		@Override
 		public int flush(Buffer buffer) throws IOException
 		{
-			_idleTimestamp=System.currentTimeMillis();
+			_idleTimestamp = System.currentTimeMillis();
 			return super.flush(buffer);
 		}
 
-		/* ------------------------------------------------------------ */
-		/**
-		 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#flush(org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer, org.eclipse.jetty.io.Buffer)
-		 */
 		@Override
 		public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException
 		{
-			_idleTimestamp=System.currentTimeMillis();
+			_idleTimestamp = System.currentTimeMillis();
 			return super.flush(header,buffer,trailer);
 		}
 
-		/* ------------------------------------------------------------ */
+		@Override
 		public void run()
 		{
 			try
 			{
-				_timeout=getMaxIdleTime();
+				_timeout = getMaxIdleTime();
 				_endpoints.add(this);
 
 				while (isOpen())
 				{
-					_idleTimestamp=System.currentTimeMillis();
+					_idleTimestamp = System.currentTimeMillis();
 					_connection.handle();
 
 				}
@@ -237,13 +215,13 @@
 			catch (HttpException e)
 			{
 				LOG.debug("BAD", e);
-				try{super.close();}
+				try{close();}
 				catch(IOException e2){LOG.trace("",e2);}
 			}
 			catch(Throwable e)
 			{
 				LOG.warn("handle failed",e);
-				try{super.close();}
+				try{close();}
 				catch(IOException e2){LOG.trace("",e2);}
 			}
 			finally
@@ -255,8 +233,8 @@
 				{
 					if (!_socket.isClosed())
 					{
-						long timestamp=System.currentTimeMillis();
-						int max_idle=getMaxIdleTime();
+						long timestamp = System.currentTimeMillis();
+						int max_idle = getMaxIdleTime();
 
 						_socket.setSoTimeout(getMaxIdleTime());
 						int c=0;
@@ -276,7 +254,6 @@
 			}
 		}
 
-		/* ------------------------------------------------------------ */
 		@Override
 		public String toString()
 		{