[jbossws-commits] JBossWS SVN: r10896 - in stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core: server/netty and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Mon Oct 12 17:10:58 EDT 2009


Author: richard.opalka at jboss.com
Date: 2009-10-12 17:10:58 -0400 (Mon, 12 Oct 2009)
New Revision: 10896

Added:
   stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerShutdownHook.java
Modified:
   stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java
   stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java
   stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java
   stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java
Log:
[JBWS-2674][JBWS-2754] refactoring (WIP)

Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java
===================================================================
--- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java	2009-10-12 17:04:17 UTC (rev 10895)
+++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyHttpServerConfig.java	2009-10-12 21:10:58 UTC (rev 10896)
@@ -59,26 +59,51 @@
       super();
    }
 
+   /**
+    * @see ServerConfig#getServerHomeDir()
+    * 
+    * @return server home directory
+    */
    public File getHomeDir()
    {
       return NettyHttpServerConfig.tmpDir;
    }
 
+   /**
+    * @see ServerConfig#getServerDataDir()
+    * 
+    * @return server data directory
+    */
    public File getServerDataDir()
    {
       return NettyHttpServerConfig.tmpDir;
    }
 
+   /**
+    * @see ServerConfig#getServerTempDir()
+    * 
+    * @return server temp directory
+    */
    public File getServerTempDir()
    {
       return NettyHttpServerConfig.tmpDir;
    }
 
+   /**
+    * @see ServerConfig#getWebServiceHost()
+    * 
+    * @return localhost
+    */
    public String getWebServiceHost()
    {
       return "localhost";
    }
 
+   /**
+    * @see ServerConfig#isModifySOAPAddress()
+    * 
+    * @return always return false
+    */
    public boolean isModifySOAPAddress()
    {
       return false;

Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java
===================================================================
--- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java	2009-10-12 17:04:17 UTC (rev 10895)
+++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/http/NettyRequestHandlerFactoryImpl.java	2009-10-12 21:10:58 UTC (rev 10896)
@@ -31,21 +31,35 @@
 final class NettyRequestHandlerFactoryImpl implements NettyRequestHandlerFactory<NettyRequestHandlerImpl>
 {
    
+   /** Factory singleton. */
    private static final NettyRequestHandlerFactory<NettyRequestHandlerImpl> SINGLETON = new NettyRequestHandlerFactoryImpl();
    
+   /**
+    * Constructor.
+    */
    private NettyRequestHandlerFactoryImpl()
    {
       super();
    }
 
+   /**
+    * Creates new request handler.
+    * 
+    * @return new request handler
+    */
    public NettyRequestHandlerImpl newNettyRequestHandler()
    {
       return new NettyRequestHandlerImpl();
    }
    
+   /**
+    * Returns factory instance.
+    *
+    * @return factory instance
+    */
    public static NettyRequestHandlerFactory<NettyRequestHandlerImpl> getInstance()
    {
-      return SINGLETON;
+      return NettyRequestHandlerFactoryImpl.SINGLETON;
    }
 
 }

Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java
===================================================================
--- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java	2009-10-12 17:04:17 UTC (rev 10895)
+++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/AbstractNettyRequestHandler.java	2009-10-12 21:10:58 UTC (rev 10896)
@@ -45,6 +45,7 @@
 
    /** Callbacks registry. */
    private final List<NettyCallbackHandler> callbacks = new LinkedList<NettyCallbackHandler>();
+
    /** Callback registry lock. */
    private final Lock callbackRegistryLock = new ReentrantLock();
 
@@ -69,7 +70,7 @@
       //       so that they are closed properly on shutdown
       //       If the added channel is closed before shutdown,
       //       it will be removed from the group automatically.
-      NettyHttpServerImpl.channelGroup.add(ctx.getChannel());
+      NettyHttpServerImpl.NETTY_CHANNEL_GROUP.add(ctx.getChannel());
    }
 
    /**

Modified: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java
===================================================================
--- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java	2009-10-12 17:04:17 UTC (rev 10895)
+++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerImpl.java	2009-10-12 21:10:58 UTC (rev 10896)
@@ -26,7 +26,6 @@
 
 import javax.xml.ws.WebServiceException;
 
-import org.jboss.logging.Logger;
 import org.jboss.netty.bootstrap.ServerBootstrap;
 import org.jboss.netty.channel.Channel;
 import org.jboss.netty.channel.ChannelFactory;
@@ -44,208 +43,213 @@
 final class NettyHttpServerImpl implements NettyHttpServer, Runnable
 {
 
-   private static final Logger LOG = Logger.getLogger(NettyHttpServerImpl.class);
-
+   /** Wait period. */
    private static final long WAIT_PERIOD = 100;
 
-   static final ChannelGroup channelGroup = new DefaultChannelGroup("NettyHttpServer");
+   /** Netty channel group. */
+   static final ChannelGroup NETTY_CHANNEL_GROUP = new DefaultChannelGroup("NettyHttpServer");
 
-   private final Object instanceLock = new Object();
-
+   /** Server port. */
    private final int port;
 
-   private boolean started;
-
+   /** Indicates server is stopped. */
    private boolean stopped;
 
+   /** Indicates server is terminated. */
    private boolean terminated;
 
-   private ChannelFactory factory;
+   /** Channel factory. */
+   private ChannelFactory channelFactory;
 
-   private AbstractNettyRequestHandler handler;
+   /** Netty request handler. */
+   private AbstractNettyRequestHandler nettyRequestHandler;
 
-   NettyHttpServerImpl(int port, NettyRequestHandlerFactory<?> nettyRequestHandlerFactory)
+   /**
+    * Constructor. This starts new http server in the background and registers shutdown hook for it.
+    *
+    * @param port server port
+    * @param nettyRequestHandlerFactory request handler factory
+    */
+   NettyHttpServerImpl(final int port, final NettyRequestHandlerFactory<?> nettyRequestHandlerFactory)
    {
       super();
       this.port = port;
       try
       {
-         factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
+         this.channelFactory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors
+               .newCachedThreadPool());
 
-         ServerBootstrap bootstrap = new ServerBootstrap(factory);
-         this.handler = nettyRequestHandlerFactory.newNettyRequestHandler();
-         WSServerPipelineFactory channelPipelineFactory = new WSServerPipelineFactory();
-         channelPipelineFactory.setRequestHandler(this.handler);
+         final ServerBootstrap bootstrap = new ServerBootstrap(this.channelFactory);
+         this.nettyRequestHandler = nettyRequestHandlerFactory.newNettyRequestHandler();
+         final WSServerPipelineFactory channelPipelineFactory = new WSServerPipelineFactory();
+         channelPipelineFactory.setRequestHandler(this.nettyRequestHandler);
          bootstrap.setPipelineFactory(channelPipelineFactory);
          bootstrap.setOption("child.tcpNoDelay", true);
          bootstrap.setOption("child.keepAlive", true);
          // Bind and start to accept incoming connections.
-         Channel c = bootstrap.bind(new InetSocketAddress(this.port));
-         channelGroup.add(c);
+         final Channel c = bootstrap.bind(new InetSocketAddress(this.port));
+         NettyHttpServerImpl.NETTY_CHANNEL_GROUP.add(c);
          // forking Netty server
-         Thread t = new Thread(this, "NettyHttpServer listening on port " + port);
+         final Thread t = new Thread(this, "NettyHttpServer listening on port " + port);
          t.setDaemon(true);
          t.start();
          // registering shutdown hook
-         Runnable shutdownHook = new NettyHttpServerShutdownHook(this);
+         final Runnable shutdownHook = new NettyHttpServerShutdownHook(this);
          Runtime.getRuntime().addShutdownHook(
                new Thread(shutdownHook, "NettyHttpServerShutdownHook(port=" + port + ")"));
-         if (LOG.isDebugEnabled())
-            LOG.debug("Netty http server started on port: " + this.port);
       }
       catch (Exception e)
       {
-         LOG.warn(e.getMessage(), e);
          throw new WebServiceException(e.getMessage(), e);
       }
    }
 
-   public final void registerCallback(final NettyCallbackHandler callback)
+   /**
+    * @see NettyHttpServer#registerCallback(NettyCallbackHandler)
+    * 
+    * @param callback new callback
+    */
+   public void registerCallback(final NettyCallbackHandler callback)
    {
-      if (callback == null)
-         throw new IllegalArgumentException("Null callback handler");
-
-      this.ensureUpAndRunning();
-
-      this.handler.registerCallback(callback);
+      if (callback != null)
+      {
+         this.ensureUpAndRunning();
+         this.nettyRequestHandler.registerCallback(callback);
+      }
    }
 
-   public final void unregisterCallback(final NettyCallbackHandler callback)
+   /**
+    * @see NettyHttpServer#unregisterCallback(NettyCallbackHandler)
+    *
+    * @param callback old callback
+    */
+   public void unregisterCallback(final NettyCallbackHandler callback)
    {
-      if (callback == null)
-         throw new IllegalArgumentException("Null callback handler");
-
-      this.ensureUpAndRunning();
-
-      try
+      if (callback != null)
       {
-         this.handler.unregisterCallback(callback);
-      }
-      finally
-      {
-         if (!this.hasMoreCallbacks())
+         this.ensureUpAndRunning();
+         try
          {
-            this.terminate();
+            this.nettyRequestHandler.unregisterCallback(callback);
          }
+         finally
+         {
+            if (!this.hasMoreCallbacks())
+            {
+               this.terminate();
+            }
+         }
       }
    }
 
-   public final NettyCallbackHandler getCallback(final String requestPath)
+   /**
+    * @see NettyHttpServer#getCallback(String)
+    *
+    * @param requestPath request path
+    * @return callback handler associated with path
+    */
+   public NettyCallbackHandler getCallback(final String requestPath)
    {
       if (requestPath == null)
+      {
          throw new IllegalArgumentException("Null request path");
+      }
 
       this.ensureUpAndRunning();
-
-      return this.handler.getCallback(requestPath);
+      return this.nettyRequestHandler.getCallback(requestPath);
    }
 
-   public final boolean hasMoreCallbacks()
+   /**
+    * @see NettyHttpServer#hasMoreCallbacks()
+    * 
+    * @return true if at least one callback handler is registered, false otherwise
+    */
+   public boolean hasMoreCallbacks()
    {
       this.ensureUpAndRunning();
-
-      return this.handler.hasMoreCallbacks();
+      return this.nettyRequestHandler.hasMoreCallbacks();
    }
 
-   public final int getPort()
+   /**
+    * @see NettyHttpServer#getPort()
+    * 
+    * @return server port
+    */
+   public int getPort()
    {
       this.ensureUpAndRunning();
-
       return this.port;
    }
 
-   private void ensureUpAndRunning()
+   /**
+    * Ensures server is up and running.
+    */
+   private synchronized void ensureUpAndRunning()
    {
-      synchronized (this.instanceLock)
+      if (this.stopped)
       {
-         if (this.stopped)
-            throw new IllegalStateException("Server is down");
+         throw new IllegalStateException("Server is down");
       }
    }
 
-   public final void run()
+   /**
+    * Handles incomming connections.
+    */
+   public synchronized void run()
    {
-      synchronized (this.instanceLock)
+      while (!this.stopped)
       {
-         if (this.started)
-            return;
-
-         this.started = true;
-
-         while (this.stopped == false)
+         try
          {
-            try
-            {
-               this.instanceLock.wait(WAIT_PERIOD);
-            }
-            catch (InterruptedException ie)
-            {
-               LOG.warn(ie.getMessage(), ie);
-            }
+            this.wait(NettyHttpServerImpl.WAIT_PERIOD);
          }
-         try
+         catch (InterruptedException ie)
          {
-            //Close all connections and server sockets.
-            channelGroup.close().awaitUninterruptibly();
-            //Shutdown the selector loop (boss and worker).
-            if (factory != null)
-            {
-               factory.releaseExternalResources();
-            }
+            ie.printStackTrace();
          }
-         finally
+      }
+      try
+      {
+         //Close all connections and server sockets.
+         NettyHttpServerImpl.NETTY_CHANNEL_GROUP.close().awaitUninterruptibly();
+         //Shutdown the selector loop (boss and worker).
+         if (this.channelFactory != null)
          {
-            LOG.debug("terminated");
-            this.terminated = true;
+            this.channelFactory.releaseExternalResources();
          }
       }
+      finally
+      {
+         this.terminated = true;
+      }
    }
 
-   public final void terminate()
+   /**
+    * Terminates server instance.
+    */
+   public synchronized void terminate()
    {
-      synchronized (this.instanceLock)
+      if (this.stopped)
       {
-         if (this.stopped == true)
-            return;
+         return;
+      }
 
-         this.stopped = true;
-         LOG.debug("termination forced");
-         while (this.terminated == false)
+      this.stopped = true;
+      while (!this.terminated)
+      {
+         try
          {
-            try
-            {
-               LOG.debug("waiting for termination");
-               this.instanceLock.wait(WAIT_PERIOD);
-            }
-            catch (InterruptedException ie)
-            {
-               LOG.warn(ie.getMessage(), ie);
-            }
+            this.wait(NettyHttpServerImpl.WAIT_PERIOD);
          }
-         synchronized (NettyHttpServerFactory.SERVERS)
+         catch (InterruptedException ie)
          {
-            NettyHttpServerFactory.SERVERS.remove(port);
+            ie.printStackTrace();
          }
       }
-   }
-
-   private static final class NettyHttpServerShutdownHook implements Runnable
-   {
-
-      private final NettyHttpServerImpl nettyHttpServer;
-
-      private NettyHttpServerShutdownHook(final NettyHttpServerImpl nettyHttpServer)
+      synchronized (NettyHttpServerFactory.SERVERS)
       {
-         super();
-
-         this.nettyHttpServer = nettyHttpServer;
+         NettyHttpServerFactory.SERVERS.remove(this.port);
       }
-
-      public void run()
-      {
-         this.nettyHttpServer.terminate();
-      }
-
    }
 
 }

Added: stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerShutdownHook.java
===================================================================
--- stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerShutdownHook.java	                        (rev 0)
+++ stack/native/branches/ropalka/modules/core/src/main/java/org/jboss/ws/core/server/netty/NettyHttpServerShutdownHook.java	2009-10-12 21:10:58 UTC (rev 10896)
@@ -0,0 +1,34 @@
+package org.jboss.ws.core.server.netty;
+
+/**
+ * Netty server shutdown hook.
+ *
+ * @author <a href="mailto:ropalka at redhat.com">Richard Opalka</a>
+ */
+final class NettyHttpServerShutdownHook implements Runnable
+{
+
+   /** Delegee. */
+   private final NettyHttpServerImpl server;
+
+   /**
+    * Constructor.
+    *
+    * @param server netty http server
+    */
+   NettyHttpServerShutdownHook(final NettyHttpServerImpl server)
+   {
+      super();
+
+      this.server = server;
+   }
+
+   /**
+    * Terminates server.
+    */
+   public void run()
+   {
+      this.server.terminate();
+   }
+
+}



More information about the jbossws-commits mailing list