[grizzly~git:ccbb8b78] Incremental changes for https://java.net/jira/browse/GRIZZLY-1546 (Ref GR

  • From: rlubke@...
  • To: commits@...
  • Subject: [grizzly~git:ccbb8b78] Incremental changes for https://java.net/jira/browse/GRIZZLY-1546 (Ref GR
  • Date: Tue, 16 Jul 2013 23:59:20 +0000

Project:    grizzly
Repository: git
Revision:   ccbb8b7896411b3ad87379393c2764fea3376e3b
Author:     rlubke
Date:       2013-07-16 22:48:47 UTC
Link:       

Log Message:
------------
Incremental changes for https://java.net/jira/browse/GRIZZLY-1546 ;(Ref 
GRIZZLY-1345. Generalize the graceful shutdown to be a feature of the core 
transport vs specific to http-server).
  - In addition to the feature changes, refactored common loggic from 
{TCP,UDP}NIOTransport into NIOTransport.  Doing so
    removed duplicate logic in both concrete transport classes as well as 
removing duplicate test code.



Revisions:
----------
ccbb8b7896411b3ad87379393c2764fea3376e3b


Modified Paths:
---------------
extras/connection-pool/src/test/java/org/glassfish/grizzly/connectionpool/MultiEndPointPoolTest.java
extras/connection-pool/src/test/java/org/glassfish/grizzly/connectionpool/SingleEndPointPoolTest.java
modules/benchmark/usecase/1.x/http-echo/src/main/java/org/glassfish/grizzly/http/echo/EchoServer.java
modules/benchmark/usecase/1.x/http-writerbm/src/main/java/org/glassfish/grizzly/http/writerbm/Server.java
modules/benchmark/usecase/1.x/tcp-echo/src/org/glassfish/grizzly/benchmark/TCPEchoServer.java
modules/benchmark/usecase/2dot0/http-echo/src/main/java/org/glassfish/grizzly/http/echo/EchoServer.java
modules/benchmark/usecase/2dot0/http-writerbm/src/main/java/org/glassfish/grizzly/http/writerbm/Server.java
modules/benchmark/usecase/2dot0/httpget-2dot0/src/org/glassfish/grizzly/benchmark/HttpGetServer.java
modules/benchmark/usecase/2dot0/tcp-echo/src/main/java/org/glassfish/grizzly/benchmark/TCPEchoServer.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/FilterChainTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/GZipTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/IdleConnectionFilterTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/SSLTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/StandaloneTest.java
modules/grizzly-aio/src/test/java/org/glassfish/grizzly/TCPAIOTransportTest.java
modules/grizzly/src/main/java/org/glassfish/grizzly/AbstractBindingHandler.java
modules/grizzly/src/main/java/org/glassfish/grizzly/AbstractTransport.java
modules/grizzly/src/main/java/org/glassfish/grizzly/SocketBinder.java
modules/grizzly/src/main/java/org/glassfish/grizzly/SocketConnectorHandler.java
modules/grizzly/src/main/java/org/glassfish/grizzly/Transport.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOBindingHandler.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnection.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOServerConnection.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOTransport.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOBindingHandler.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnectorHandler.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOServerConnection.java
modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOTransport.java
modules/grizzly/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/ByteBufferStreamsTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/CompositeBufferInStreamTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/FilterChainTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/GZipTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/IOStrategyTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/IdleConnectionFilterTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/LZMATest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/SSLTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/StandaloneTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/TCPNIOTransportTest.java
modules/grizzly/src/test/java/org/glassfish/grizzly/UDPNIOTransportTest.java
modules/http-server/src/main/java/org/glassfish/grizzly/http/server/NetworkListener.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/AggregatorAddOnTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BasicConfigTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/CLStaticHttpHandlerTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpInputStreamsTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpResponseStreamsTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpSessionTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/KeepAliveTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOInputSourcesTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOOutputSinksTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/ParametersTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/RequestURITest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SendFileTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SplitTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/StaticHttpHandlerTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TraceMethodTest.java
modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TransferEncodingTest.java
modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HttpSessionTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/ChunkedTransferEncodingTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/ClientRequestPipeliningTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/CompressionSemanticsTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/ContentTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/GZipEncodingTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpCommTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpRequestParseTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpResponseParseTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpSemanticsTest.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/LZMAEncodingTest.java
modules/monitoring/grizzly/src/test/java/org/glassfish/grizzly/JmxBasicTest.java
modules/portunif/src/test/java/org/glassfish/grizzly/portunif/AsyncPUTest.java
modules/portunif/src/test/java/org/glassfish/grizzly/portunif/BasicPUTest.java
modules/portunif/src/test/java/org/glassfish/grizzly/portunif/FilterChainReadTest.java
modules/portunif/src/test/java/org/glassfish/grizzly/portunif/SSLAndPlainTest.java
modules/rcm/src/test/java/org/glassfish/grizzly/rcm/RCMTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpInputStreamsTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpLayerSemanticsTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpOutputStreamsTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOInputSourcesTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOOutputSinksTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/ServerPushTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SpdySemanticsTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SplitTest.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/TestClient.java
modules/spdy/src/test/java/org/glassfish/grizzly/spdy/TestMain.java
modules/websockets/src/test/java/org/glassfish/grizzly/websockets/LifecycleTest.java
modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketClient.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/echo/EchoClient.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/echo/EchoServer.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/filterchain/GIOPClient.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/filterchain/GIOPServer.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/lifecycle/LifeCycleExample.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Client.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Server.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/ssl/SSLEchoClient.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/ssl/SSLEchoServer.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/strategy/CustomStrategy.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelServer.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoClient.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoServer.java
samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpmulticast/MulticastChat.java
samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Client.java
samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Server.java
samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/blockinghandler/BlockingHttpHandlerSample.java
samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/NonBlockingHttpHandlerSample.java
samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/AddClient.java
samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/PUServer.java
samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/SubClient.java


Added Paths:
------------
modules/grizzly/src/main/java/org/glassfish/grizzly/ShutdownContext.java
modules/grizzly/src/main/java/org/glassfish/grizzly/ShutdownListener.java
modules/grizzly/src/test/java/org/glassfish/grizzly/NIOTransportTest.java


Diffs:
------
--- 
a/extras/connection-pool/src/test/java/org/glassfish/grizzly/connectionpool/MultiEndPointPoolTest.java
+++ 
b/extras/connection-pool/src/test/java/org/glassfish/grizzly/connectionpool/MultiEndPointPoolTest.java
@@ -110,7 +110,7 @@ public class MultiEndPointPoolTest {
         serverSideConnections.clear();
         
         if (transport != null) {
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 --- 
a/extras/connection-pool/src/test/java/org/glassfish/grizzly/connectionpool/SingleEndPointPoolTest.java
+++ 
b/extras/connection-pool/src/test/java/org/glassfish/grizzly/connectionpool/SingleEndPointPoolTest.java
@@ -111,7 +111,7 @@ public class SingleEndPointPoolTest {
         serverSideConnections.clear();
         
         if (transport != null) {
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -355,7 +355,7 @@ public class SingleEndPointPoolTest {
         
         try {
             clientTransport.start();
-            transport.stop();
+            transport.shutdownNow();
             
             t.start();
             
@@ -366,7 +366,7 @@ public class SingleEndPointPoolTest {
         } finally {
             t.join();
             pool.close();
-            clientTransport.stop();
+            clientTransport.shutdownNow();
         }
     }
 
@@ -398,7 +398,7 @@ public class SingleEndPointPoolTest {
 
         try {
             clientTransport.start();
-            transport.stop();
+            transport.shutdownNow();
             final AtomicBoolean notified = new AtomicBoolean();
             final AtomicReference<Connection> connection =
                     new AtomicReference<Connection>();
@@ -425,7 +425,7 @@ public class SingleEndPointPoolTest {
             e.printStackTrace();
         } finally {
             pool.close();
-            clientTransport.stop();
+            clientTransport.shutdownNow();
         }
     }
 }--- 
a/modules/benchmark/usecase/1.x/http-echo/src/main/java/org/glassfish/grizzly/http/echo/EchoServer.java
+++ 
b/modules/benchmark/usecase/1.x/http-echo/src/main/java/org/glassfish/grizzly/http/echo/EchoServer.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -37,6 +37,7 @@
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
+
 package org.glassfish.grizzly.http.echo;
 
 import com.sun.grizzly.Controller;
@@ -97,7 +98,7 @@ final class EchoServer {
             System.exit(1);
         } finally {
             try {
-                server.stop();
+                server.shutdownNow();
             } catch (IOException ioe) {
                 System.err.println(ioe);
             }
@@ -110,7 +111,7 @@ final class EchoServer {
     }
 
     public void stop() throws IOException {
-        httpServer.stop();
+        httpServer.shutdownNow();
     }
 
 --- 
a/modules/benchmark/usecase/1.x/http-writerbm/src/main/java/org/glassfish/grizzly/http/writerbm/Server.java
+++ 
b/modules/benchmark/usecase/1.x/http-writerbm/src/main/java/org/glassfish/grizzly/http/writerbm/Server.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -37,6 +37,7 @@
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
+
 package org.glassfish.grizzly.http.writerbm;
 
 import com.sun.grizzly.Controller;
@@ -97,7 +98,7 @@ final class Server {
             System.exit(1);
         } finally {
             try {
-                server.stop();
+                server.shutdownNow();
             } catch (IOException ioe) {
                 System.err.println(ioe);
             }
@@ -110,7 +111,7 @@ final class Server {
     }
 
     public void stop() throws IOException {
-        httpServer.stop();
+        httpServer.shutdownNow();
     }
 
 --- 
a/modules/benchmark/usecase/1.x/tcp-echo/src/org/glassfish/grizzly/benchmark/TCPEchoServer.java
+++ 
b/modules/benchmark/usecase/1.x/tcp-echo/src/org/glassfish/grizzly/benchmark/TCPEchoServer.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -133,7 +133,7 @@ public class TCPEchoServer {
         if (controller.isStarted()) {
             System.out.println("Press enter to exit...");
             System.in.read();
-            controller.stop();
+            controller.shutdownNow();
         }
     }
 }--- 
a/modules/benchmark/usecase/2dot0/http-echo/src/main/java/org/glassfish/grizzly/http/echo/EchoServer.java
+++ 
b/modules/benchmark/usecase/2dot0/http-echo/src/main/java/org/glassfish/grizzly/http/echo/EchoServer.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -37,6 +37,7 @@
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
+
 package org.glassfish.grizzly.http.echo;
 
 import org.glassfish.grizzly.IOStrategy;
@@ -105,7 +106,7 @@ final class EchoServer {
             System.exit(1);
         } finally {
             try {
-                server.stop();
+                server.shutdownNow();
             } catch (IOException ioe) {
                 System.err.println(ioe);
             }
@@ -117,7 +118,7 @@ final class EchoServer {
     }
 
     public void stop() throws IOException {
-        httpServer.stop();
+        httpServer.shutdownNow();
         if (probe != null) {
             probe.toString();
         }--- 
a/modules/benchmark/usecase/2dot0/http-writerbm/src/main/java/org/glassfish/grizzly/http/writerbm/Server.java
+++ 
b/modules/benchmark/usecase/2dot0/http-writerbm/src/main/java/org/glassfish/grizzly/http/writerbm/Server.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -37,6 +37,7 @@
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
+
 package org.glassfish.grizzly.http.writerbm;
 
 import java.io.IOException;
@@ -96,7 +97,7 @@ final class Server {
             System.exit(1);
         } finally {
             try {
-                server.stop();
+                server.shutdownNow();
             } catch (IOException ioe) {
                 System.err.println(ioe);
             }
@@ -108,7 +109,7 @@ final class Server {
     }
 
     public void stop() throws IOException {
-        httpServer.stop();
+        httpServer.shutdownNow();
         if (probe != null) {
             probe.toString();
         }--- 
a/modules/benchmark/usecase/2dot0/httpget-2dot0/src/org/glassfish/grizzly/benchmark/HttpGetServer.java
+++ 
b/modules/benchmark/usecase/2dot0/httpget-2dot0/src/org/glassfish/grizzly/benchmark/HttpGetServer.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -97,7 +97,7 @@ public class HttpGetServer {
             System.out.println("Press enter to stop the server...");
             System.in.read();
         } finally {
-            server.stop();
+            server.shutdownNow();
             TransportFactory.getInstance().close();
         }
 --- 
a/modules/benchmark/usecase/2dot0/tcp-echo/src/main/java/org/glassfish/grizzly/benchmark/TCPEchoServer.java
+++ 
b/modules/benchmark/usecase/2dot0/tcp-echo/src/main/java/org/glassfish/grizzly/benchmark/TCPEchoServer.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -100,7 +100,7 @@ public class TCPEchoServer {
             System.out.println("Press enter to stop the server...");
             System.in.read();
         } finally {
-            transport.stop();
+            transport.shutdownNow();
         }
 
         if (probe != null) {--- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java
@@ -211,7 +211,7 @@ public class AsyncWriteQueueTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -312,7 +312,7 @@ public class AsyncWriteQueueTest extends GrizzlyTestCase {
             if (transport.isPaused()) {
                 transport.resume();
             }
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -393,7 +393,7 @@ public class AsyncWriteQueueTest extends GrizzlyTestCase {
             if (transport.isPaused()) {
                 transport.resume();
             }
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 --- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java
@@ -172,7 +172,7 @@ public class FilterChainReadTest extends TestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -287,7 +287,7 @@ public class FilterChainReadTest extends TestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -364,7 +364,7 @@ public class FilterChainReadTest extends TestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 }--- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/FilterChainTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/FilterChainTest.java
@@ -233,7 +233,7 @@ public class FilterChainTest extends TestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 --- a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/GZipTest.java
+++ b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/GZipTest.java
@@ -142,7 +142,7 @@ public class GZipTest extends TestCase {
                 connection.closeSilently();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 --- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/IdleConnectionFilterTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/IdleConnectionFilterTest.java
@@ -109,7 +109,7 @@ public class IdleConnectionFilterTest extends 
GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -162,7 +162,7 @@ public class IdleConnectionFilterTest extends 
GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 --- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java
@@ -208,7 +208,7 @@ public class ProtocolChainCodecTest extends 
GrizzlyTestCase {
                 connection.closeSilently();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 }--- a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/SSLTest.java
+++ b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/SSLTest.java
@@ -264,7 +264,7 @@ public class SSLTest {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
 
     }
@@ -393,7 +393,7 @@ public class SSLTest {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -477,7 +477,7 @@ public class SSLTest {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
     --- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/StandaloneTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/StandaloneTest.java
@@ -121,7 +121,7 @@ public class StandaloneTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
 
     }--- 
a/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/TCPAIOTransportTest.java
+++ 
b/modules/grizzly-aio/src/test/java/org/glassfish/grizzly/TCPAIOTransportTest.java
@@ -88,7 +88,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
             transport.bind(PORT);
             transport.start();
         } finally {
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -108,7 +108,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -145,7 +145,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -193,7 +193,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -236,7 +236,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -291,7 +291,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -351,7 +351,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -404,7 +404,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -497,7 +497,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 
@@ -595,7 +595,7 @@ public class TCPAIOTransportTest extends GrizzlyTestCase {
                 connection.close();
             }
 
-            transport.stop();
+            transport.shutdownNow();
         }
     }
 }--- 
a/modules/grizzly/src/main/java/org/glassfish/grizzly/AbstractBindingHandler.java
+++ 
b/modules/grizzly/src/main/java/org/glassfish/grizzly/AbstractBindingHandler.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -37,6 +37,7 @@
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
+
 package org.glassfish.grizzly;
 
 import org.glassfish.grizzly.nio.NIOTransport;
@@ -173,7 +174,7 @@ public abstract class AbstractBindingHandler implements 
SocketBinder {
      * @throws UnsupportedOperationException
      */
     @Override
-    public final void unbindAll() throws IOException {
+    public final void unbindAll() {
         throw new UnsupportedOperationException();
     }
 --- 
a/modules/grizzly/src/main/java/org/glassfish/grizzly/AbstractTransport.java
+++ 
b/modules/grizzly/src/main/java/org/glassfish/grizzly/AbstractTransport.java
@@ -670,7 +670,7 @@ public abstract class AbstractTransport implements 
Transport {
      * @throws IOException
      */
     @Override
-    public abstract void pause() throws IOException;
+    public abstract void pause();
     
     /**
      * Resumes the transport after a pause
@@ -678,7 +678,7 @@ public abstract class AbstractTransport implements 
Transport {
      * @throws IOException
      */
     @Override
-    public abstract void resume() throws IOException;
+    public abstract void resume();
 
     /**
      * Create the Transport JMX management object.--- /dev/null
+++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ShutdownContext.java
@@ -0,0 +1,59 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").  You
+ * may not use this file except in compliance with the License.  You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt.  See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the 
License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or 
GPL
+ * Version 2] license."  If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above.  However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+package org.glassfish.grizzly;
+
+/**
+ *
+ * @since 2.3.5
+ */
+public interface ShutdownContext {
+
+    /**
+     * @return the Transport that is being shutdown.
+     */
+    Transport getTransport();
+
+    /**
+     * Invoked by called {@link ShutdownListener} to notify the graceful
+     * termination process that it's safe to terminate the transport.
+     */
+    void ready();
+
+}--- /dev/null
+++ 
b/modules/grizzly/src/main/java/org/glassfish/grizzly/ShutdownListener.java
@@ -0,0 +1,92 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").  You
+ * may not use this file except in compliance with the License.  You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt.  See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the 
License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or 
GPL
+ * Version 2] license."  If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above.  However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+package org.glassfish.grizzly;/*
+
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common Development
+ * and Distribution License("CDDL") (collectively, the "License").  You
+ * may not use this file except in compliance with the License.  You can
+ * obtain a copy of the License at
+ * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
+ * or packager/legal/LICENSE.txt.  See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ * When distributing the software, include this License Header Notice in each
+ * file and include the License file at packager/legal/LICENSE.txt.
+ *
+ * GPL Classpath Exception:
+ * Oracle designates this particular file as subject to the "Classpath"
+ * exception as provided by Oracle in the GPL Version 2 section of the 
License
+ * file that accompanied this code.
+ *
+ * Modifications:
+ * If applicable, add the following below the License Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyright [year] [name of copyright owner]"
+ *
+ * Contributor(s):
+ * If you wish your version of this file to be governed by only the CDDL or
+ * only the GPL Version 2, indicate your decision by adding "[Contributor]
+ * elects to include this software in this distribution under the [CDDL or 
GPL
+ * Version 2] license."  If you don't indicate a single choice of license, a
+ * recipient has the option to distribute your version of this file under
+ * either the CDDL, the GPL Version 2 or to extend the choice of license to
+ * its licensees as provided above.  However, if you add GPL Version 2 code
+ * and therefore, elected the GPL Version 2 license, then the option applies
+ * only if the new code is made subject to such option by the copyright
+ * holder.
+ */
+
+/**
+ * Interface to notify interested parties that a {@link Transport} is being
+ * shutdown.
+ *
+ * @since 2.3.5
+ */
+public interface ShutdownListener {
+
+    void shutdownRequested(final ShutdownContext shutdownContext);
+
+}--- a/modules/grizzly/src/main/java/org/glassfish/grizzly/SocketBinder.java
+++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/SocketBinder.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2009-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2009-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -132,13 +132,13 @@ public interface SocketBinder {
      *
      * @throws java.io.IOException
      */
-    public void unbind(Connection connection) throws IOException;
+    public void unbind(Connection connection);
 
     /**
      * Unbinds all bound {@link Transport} connections.
      *
      * @throws java.io.IOException
      */
-    public void unbindAll() throws IOException;
+    public void unbindAll();
 
 }--- 
a/modules/grizzly/src/main/java/org/glassfish/grizzly/SocketConnectorHandler.java
+++ 
b/modules/grizzly/src/main/java/org/glassfish/grizzly/SocketConnectorHandler.java
@@ -52,6 +52,10 @@ import java.net.SocketAddress;
  * @author Alexey Stashok
  */
 public interface SocketConnectorHandler extends 
ConnectorHandler<SocketAddress> {
+
+
+    int DEFAULT_CONNECTION_TIMEOUT = 30000;
+
     /**
      * Creates, initializes and connects socket to the specific remote host
      * and port and returns {@link Connection}, representing socket.
@@ -63,5 +67,5 @@ public interface SocketConnectorHandler extends 
ConnectorHandler<SocketAddress>
      * 
      * @throws java.io.IOException
      */
-    public GrizzlyFuture<Connection> connect(String host, int port) throws 
IOException;
+    GrizzlyFuture<Connection> connect(String host, int port) throws 
IOException;
 }--- a/modules/grizzly/src/main/java/org/glassfish/grizzly/Transport.java
+++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/Transport.java
@@ -413,8 +413,65 @@ public interface Transport extends 
MonitoringAware<TransportProbe> {
      * Stops the transport and closes all the connections
      * 
      * @throws IOException
+     *
+     * @deprecated Use {@link #shutdownNow()}.
      */
+    @Deprecated
     void stop() throws IOException;
+
+    /**
+     * Gracefully stops the transport accepting new connections and allows
+     * existing work to complete before finalizing the shutdown.  This method
+     * will wait indefinitely for all interested parties to signal it is safe
+     * to terminate the transport.
+     *
+     * @return a {@link GrizzlyFuture} which will return the stopped 
transport.
+     *
+     * @since 2.3.5
+     *
+     * @see ShutdownListener
+     */
+    GrizzlyFuture<Transport> shutdown();
+
+    /**
+     * Gracefully stops the transport accepting new connections and allows
+     * existing work to complete before finalizing the shutdown.  This method
+     * will wait for the specified time for all interested parties to signal 
it
+     * is safe to terminate the transport.  If the timeout is exceeded, the
+     * transport will be terminated forcefully.
+     *
+     * @param gracePeriod the grace period for a graceful shutdown before the
+     *                    transport is forcibly terminated.  A grace period
+     *                    of zero or less effectively means no timeout.
+     * @param timeUnit the {@link TimeUnit} of the specified grace period.
+     * @return
+     */
+    GrizzlyFuture<Transport> shutdown(final long gracePeriod,
+                                      final TimeUnit timeUnit);
+
+    /**
+     * Forcibly stops the transport and closes all connections.
+     *
+     * @throws IOException
+     *
+     * @since 2.3.5
+     */
+    void shutdownNow() throws IOException;
+
+    /**
+     * Adds a {@link ShutdownListener} which will be called when {@link 
#shutdown()}
+     * is called to enable graceful shutdown of transports.  This allows the
+     * owner of the listener to signal that all shutdown tasks are complete 
and
+     * that it's safe to finalize the termination of the transport
+     *
+     * @param shutdownListener the {@link ShutdownListener}
+     *
+     * @return <code>true</code> if the listener was successfully registered,
+     *  otherwise <code>false</code>.
+     *
+     * @since 2.3.5
+     */
+    boolean addShutdownListener(final ShutdownListener shutdownListener);
     
     /**
      * Pauses the transport--- 
a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java
+++ 
b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java
@@ -792,7 +792,15 @@ public abstract class NIOConnection implements 
Connection<SocketAddress> {
         } catch (IOException ignored) {
         }
     }
-    
+
+    /**
+     * Set the monitoringProbes array directly.
+     * @param monitoringProbes
+     */
+    void setMonitoringProbes(final ConnectionProbe[] monitoringProbes) {
+        this.monitoringConfig.addProbes(monitoringProbes);
+    }
+
     /**
      * Map, which contains {@link Processor}s and their states related to 
this {@link Connection}.
      */--- 
a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
+++ 
b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java
@@ -1,7 +1,7 @@
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  *
- * Copyright (c) 2008-2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008-2013 Oracle and/or its affiliates. All rights reserved.
  *
  * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common Development
@@ -42,20 +42,78 @@ package org.glassfish.grizzly.nio;
 
 import java.io.IOException;
 import java.nio.channels.spi.SelectorProvider;
-import java.util.Random;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
 import org.glassfish.grizzly.AbstractTransport;
 import org.glassfish.grizzly.Connection;
+import org.glassfish.grizzly.Grizzly;
+import org.glassfish.grizzly.GrizzlyFuture;
+import org.glassfish.grizzly.ShutdownContext;
+import org.glassfish.grizzly.ShutdownListener;
+import org.glassfish.grizzly.SocketBinder;
+import org.glassfish.grizzly.SocketConnectorHandler;
+import org.glassfish.grizzly.StandaloneProcessor;
+import org.glassfish.grizzly.Transport;
 import org.glassfish.grizzly.TransportProbe;
+import org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport;
+import org.glassfish.grizzly.impl.FutureImpl;
+import org.glassfish.grizzly.localization.LogMessages;
+import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorIO;
+import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorPool;
+import 
org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorsEnabledTransport;
+import org.glassfish.grizzly.strategies.SameThreadIOStrategy;
+import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy;
+import org.glassfish.grizzly.threadpool.AbstractThreadPool;
+import org.glassfish.grizzly.threadpool.GrizzlyExecutorService;
+import org.glassfish.grizzly.utils.Futures;
 
 /**
  *
  * @author oleksiys
  */
-public abstract class NIOTransport extends AbstractTransport {
-    protected static final Random RANDOM = new Random();
-    
+public abstract class NIOTransport extends AbstractTransport
+        implements SocketBinder, SocketConnectorHandler,
+        TemporarySelectorsEnabledTransport, AsyncQueueEnabledTransport {
+    private static final Logger LOGGER = Grizzly.logger(NIOTransport.class);
+
     protected SelectorHandler selectorHandler;
     protected SelectionKeyHandler selectionKeyHandler;
+    /**
+     * The server socket time out
+     */
+    int serverSocketSoTimeout = 0;
+    /**
+     * The socket tcpDelay.
+     *
+     * Default value for tcpNoDelay is disabled (set to true).
+     */
+    boolean tcpNoDelay = true;
+    /**
+     * The socket reuseAddress
+     */
+    boolean reuseAddress = true;
+    /**
+     * The socket keepAlive mode.
+     */
+    boolean isKeepAlive = false;
+    /**
+     * The socket time out
+     */
+    int clientSocketSoTimeout = -1;
+    /**
+     * Default channel connection timeout
+     */
+    int connectionTimeout =
+            SocketConnectorHandler.DEFAULT_CONNECTION_TIMEOUT;
 
     private int selectorRunnersCount = -1;
     
@@ -64,9 +122,37 @@ public abstract class NIOTransport extends 
AbstractTransport {
     protected NIOChannelDistributor nioChannelDistributor;
 
     protected SelectorProvider selectorProvider = 
SelectorProvider.provider();
+
+    protected final TemporarySelectorIO temporarySelectorIO;
+
+    protected Set<ShutdownListener> shutdownListeners;
+
+    /**
+     * Future to control graceful shutdown status
+     */
+    private FutureImpl<Transport> shutdownFuture;
     
     public NIOTransport(final String name) {
         super(name);
+        temporarySelectorIO = createTemporarySelectorIO();
+    }
+
+    public abstract TemporarySelectorIO createTemporarySelectorIO();
+
+    public abstract void listen();
+
+    public abstract void unbindAll();
+
+    @Override
+    public synchronized boolean addShutdownListener(ShutdownListener 
shutdownListener) {
+        final State state = getState().getState();
+        if (state != State.STOPPING || state != State.STOPPED) {
+            if (shutdownListeners == null) {
+                shutdownListeners = new HashSet<ShutdownListener>();
+            }
+            return shutdownListeners.add(shutdownListener);
+        }
+        return false;
     }
 
     public SelectionKeyHandler getSelectionKeyHandler() {
@@ -122,13 +208,6 @@ public abstract class NIOTransport extends 
AbstractTransport {
                 : SelectorProvider.provider();
     }
 
-    @Override
-    public void start() throws IOException {
-        if (selectorProvider == null) {
-            selectorProvider = SelectorProvider.provider();
-        }
-    }
-    
     protected synchronized void startSelectorRunners() throws IOException {
         selectorRunners = new SelectorRunner[selectorRunnersCount];
         
@@ -139,7 +218,7 @@ public abstract class NIOTransport extends 
AbstractTransport {
         }
     }
     
-    protected synchronized void stopSelectorRunners() throws IOException {
+    protected synchronized void stopSelectorRunners() {
         if (selectorRunners == null) {
             return;
         }
@@ -252,6 +331,267 @@ public abstract class NIOTransport extends 
AbstractTransport {
         }
     }
 
+    /**
+     * Start TCPNIOTransport.
+     * <p/>
+     * The transport will be started only if its current state is {@link 
State#STOPPED},
+     * otherwise the call will be ignored without exception thrown and the 
transport
+     * state will remain the same as it was before the method call.
+     */
+    @Override
+    public void start() throws IOException {
+        final Lock lock = state.getStateLocker().writeLock();
+        lock.lock();
+        try {
+            State currentState = state.getState();
+            if (currentState != State.STOPPED) {
+                LOGGER.log(Level.WARNING,
+                           
LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_STOP_STATE_EXCEPTION());
+                return;
+            }
+
+            state.setState(State.STARTING);
+            notifyProbesBeforeStart(this);
+
+            if (selectorProvider == null) {
+                selectorProvider = SelectorProvider.provider();
+            }
+
+            if (selectorHandler == null) {
+                selectorHandler = new DefaultSelectorHandler();
+            }
+
+            if (selectionKeyHandler == null) {
+                selectionKeyHandler = new DefaultSelectionKeyHandler();
+            }
+
+            if (processor == null && processorSelector == null) {
+                processor = new StandaloneProcessor();
+            }
+
+            final int selectorRunnersCount = getSelectorRunnersCount();
+
+            if (nioChannelDistributor == null) {
+                nioChannelDistributor =
+                        new RoundRobinConnectionDistributor(this);
+            }
+
+            if (kernelPool == null) {
+                kernelPoolConfig.setMemoryManager(memoryManager);
+                setKernelPool0(
+                        GrizzlyExecutorService.createInstance(
+                                kernelPoolConfig));
+            }
+
+            if (workerThreadPool == null) {
+                if (workerPoolConfig != null) {
+                    if (getThreadPoolMonitoringConfig().hasProbes()) {
+                        
workerPoolConfig.getInitialMonitoringConfig().addProbes(
+                                getThreadPoolMonitoringConfig().getProbes());
+                    }
+                    workerPoolConfig.setMemoryManager(memoryManager);
+                    
setWorkerThreadPool0(GrizzlyExecutorService.createInstance(
+                            workerPoolConfig));
+                }
+            }
+
+                /* By default TemporarySelector pool size should be equal
+                to the number of processing threads */
+            int selectorPoolSize =
+                    TemporarySelectorPool.DEFAULT_SELECTORS_COUNT;
+            if (workerThreadPool instanceof AbstractThreadPool) {
+                if (strategy instanceof SameThreadIOStrategy) {
+                    selectorPoolSize = selectorRunnersCount;
+                } else {
+                    selectorPoolSize = Math.min(
+                            ((AbstractThreadPool) 
workerThreadPool).getConfig()
+                                    .getMaxPoolSize(),
+                            selectorPoolSize);
+                }
+            }
+
+            if (strategy == null) {
+                strategy = WorkerThreadIOStrategy.getInstance();
+            }
+
+            temporarySelectorIO.setSelectorPool(
+                    new TemporarySelectorPool(selectorProvider,
+                                              selectorPoolSize));
+
+            startSelectorRunners();
+
+            listen();
+
+            state.setState(State.STARTED);
+
+            notifyProbesStart(this);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void stop() throws IOException {
+        shutdownNow();
+    }
+
+    @Override
+    public GrizzlyFuture<Transport> shutdown() {
+        return shutdown(-1, TimeUnit.MILLISECONDS);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public GrizzlyFuture<Transport> shutdown(final long gracePeriod,
+                                             final TimeUnit timeUnit) {
+        final Lock lock = state.getStateLocker().writeLock();
+        lock.lock();
+        try {
+            final State stateNow = state.getState();
+            if (stateNow == State.STOPPING
+                    || stateNow == State.STOPPED) {
+                return shutdownFuture;
+            } else if (stateNow == State.PAUSED) {
+                resume();
+            }
+
+            state.setState(State.STOPPING);
+
+            unbindAll();
+            shutdownFuture = Futures.createSafeFuture();
+
+            if (shutdownListeners != null && !shutdownListeners.isEmpty()) {
+                final int listenerCount = shutdownListeners.size();
+                final Thread t =
+                        new Thread("Grizzly-Graceful-Shutdown-Thread") {
+                            @Override
+                            public void run() {
+
+                                final CountDownLatch shutdownLatch =
+                                        new CountDownLatch(listenerCount);
+                                final ExecutorService executorService =
+                                        Executors.newFixedThreadPool(
+                                                listenerCount,
+                                                new ThreadFactory() {
+                                                    private int counter;
+
+                                                    @Override
+                                                    public Thread 
newThread(Runnable r) {
+                                                        
System.out.println("Creating new thread");
+                                                        Thread t = new 
Thread(r,
+                                                                
"Grizzly-Graceful-Shutdown-Thread-Sub(" + counter++ + ')');
+                                                        t.setDaemon(true);
+                                                        return t;
+                                                    }
+                                                });
+
+                                for (final ShutdownListener l : 
shutdownListeners) {
+                                    executorService.execute(new Runnable() {
+                                        @Override
+                                        public void run() {
+                                            l.shutdownRequested(
+                                                    new ShutdownContext() {
+                                                        @Override
+                                                        public Transport 
getTransport() {
+                                                            return 
NIOTransport.this;
+                                                        }
+
+                                                        @Override
+                                                        public void ready() {
+                                                            
shutdownLatch.countDown();
+                                                        }
+                                                    });
+                                        }
+                                    });
+                                }
+
+                                try {
+                                    if (gracePeriod <= 0) {
+                                        shutdownLatch.await();
+                                    } else {
+                                        Boolean result =
+                                                
shutdownLatch.await(gracePeriod,
+                                                                    
timeUnit);
+                                        if (!result) {
+                                            if 
(LOGGER.isLoggable(Level.WARNING)) {
+                                                LOGGER.warning("Shutdown 
grace period exceeded.  Terminating transport.");
+                                            }
+                                        }
+                                    }
+                                } catch (InterruptedException ie) {
+                                    if (LOGGER.isLoggable(Level.WARNING)) {
+                                        LOGGER.warning("Primary shutdown 
thread interrupted.  Forcing transport termination.");
+                                    }
+                                } finally {
+                                    executorService.shutdownNow();
+                                }
+                                finalizeShutdown();
+                                shutdownFuture.result(NIOTransport.this);
+                            }
+                        };
+                t.setDaemon(true);
+                t.start();
+            } else {
+                finalizeShutdown();
+                shutdownFuture.result(NIOTransport.this);
+            }
+        } finally {
+            lock.unlock();
+        }
+
+        return shutdownFuture;
+    }
+
+    protected void finalizeShutdown() {
+        notifyProbesBeforeStop(this);
+        stopSelectorRunners();
+
+        if (workerThreadPool != null && managedWorkerPool) {
+            workerThreadPool.shutdown();
+            workerThreadPool = null;
+        }
+
+        if (kernelPool != null) {
+            kernelPool.shutdownNow();
+            kernelPool = null;
+        }
+        state.setState(State.STOPPED);
+        notifyProbesStop(this);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void shutdownNow() throws IOException {
+        final Lock lock = state.getStateLocker().writeLock();
+        lock.lock();
+        try {
+            final State stateNow = state.getState();
+
+            if (stateNow == State.STOPPED) {
+                return;
+            }
+
+            if (stateNow == State.PAUSED) {
+                // if Transport is paused - first we need to resume it
+                // so selectorrunners can perform the close phase
+                resume();
+            }
+
+            unbindAll();
+            state.setState(State.STOPPING);
+            finalizeShutdown();
+        } finally {
+            lock.unlock();
+        }
+    }
+
     @Override
     protected abstract void closeConnection(Connection connection)
             throws IOException;
@@ -259,4 +599,127 @@ public abstract class NIOTransport extends 
AbstractTransport {
     protected int getDefaultSelectorRunnersCount() {
         return Runtime.getRuntime().availableProcessors();
     }
+
+    /**
+     * Pause UDPNIOTransport, so I/O events coming on its {@link 
org.glassfish.grizzly.nio.transport.UDPNIOConnection}s
+     * will not be processed. Use {@link #resume()} in order to resume 
UDPNIOTransport processing.
+     *
+     * The transport will be paused only if its current state is {@link 
org.glassfish.grizzly.Transport.State#STARTED},
+     * otherwise the call will be ignored without exception thrown and the 
transport
+     * state will remain the same as it was before the method call.
+     */
+    @Override
+    public void pause() {
+        final Lock lock = state.getStateLocker().writeLock();
+        lock.lock();
+        try {
+            if (state.getState() != State.STARTED) {
+                LOGGER.log(Level.WARNING,
+                        
LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_START_STATE_EXCEPTION());
+                return;
+            }
+            state.setState(State.PAUSING);
+            notifyProbesBeforePause(this);
+            state.setState(State.PAUSED);
+            notifyProbesPause(this);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    /**
+     * Resume UDPNIOTransport, which has been paused before using {@link 
#pause()}.
+     *
+     * The transport will be resumed only if its current state is {@link 
org.glassfish.grizzly.Transport.State#PAUSED},
+     * otherwise the call will be ignored without exception thrown and the 
transport
+     * state will remain the same as it was before the method call.
+     */
+    @Override
+    public void resume() {
+        final Lock lock = state.getStateLocker().writeLock();
+        lock.lock();
+        try {
+            if (state.getState() != State.PAUSED) {
+                LOGGER.log(Level.WARNING,
+                        
LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_PAUSE_STATE_EXCEPTION());
+                return;
+            }
+            state.setState(State.STARTING);
+            notifyProbesBeforeResume(this);
+            state.setState(State.STARTED);
+            notifyProbesResume(this);
+        } finally {
+            lock.unlock();
+        }
+    }
+
+    protected void configureNIOConnection(NIOConnection connection) {
+        connection.configureBlocking(isBlocking);
+        connection.configureStandalone(isStandalone);
+        connection.setProcessor(processor);
+        connection.setProcessorSelector(processorSelector);
+        connection.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS);
+        connection.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS);
+        if (connectionMonitoringConfig.hasProbes()) {
+            
connection.setMonitoringProbes(connectionMonitoringConfig.getProbes());
+        }
+    }
+
+    public boolean isKeepAlive() {
+        return isKeepAlive;
+    }
+
+    @SuppressWarnings({"UnusedDeclaration"})
+    public void setKeepAlive(final boolean isKeepAlive) {
+        this.isKeepAlive = isKeepAlive;
+        notifyProbesConfigChanged(this);
+    }
+
+    public boolean isReuseAddress() {
+        return reuseAddress;
+    }
+
+    public void setReuseAddress(final boolean reuseAddress) {
+        this.reuseAddress = reuseAddress;
+        notifyProbesConfigChanged(this);
+    }
+
+    public int getClientSocketSoTimeout() {
+        return clientSocketSoTimeout;
+    }
+
+    @SuppressWarnings({"UnusedDeclaration"})
+    public void setClientSocketSoTimeout(final int socketTimeout) {
+        this.clientSocketSoTimeout = socketTimeout;
+        notifyProbesConfigChanged(this);
+    }
+
+    public int getConnectionTimeout() {
+        return connectionTimeout;
+    }
+
+    @SuppressWarnings({"UnusedDeclaration"})
+    public void setConnectionTimeout(final int connectionTimeout) {
+        this.connectionTimeout = connectionTimeout;
+        notifyProbesConfigChanged(this);
+    }
+
+    public boolean isTcpNoDelay() {
+        return tcpNoDelay;
+    }
+
+    public void setTcpNoDelay(final boo
[truncated due to length]



[grizzly~git:ccbb8b78] Incremental changes for https://java.net/jira/browse/GRIZZLY-1546 (Ref GR

rlubke 07/16/2013
Terms of Use; Privacy Policy; Copyright ©2013-2017 (revision 20160708.bf2ac18)
 
 
Close
loading
Please Confirm
Close