[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/socket ...

Ovidiu Feodorov ovidiu.feodorov at jboss.com
Sat Jan 13 07:42:36 EST 2007


  User: ovidiu  
  Date: 07/01/13 07:42:36

  Modified:    src/main/org/jboss/remoting/transport/socket    Tag:
                        remoting_2_x MicroSocketClientInvoker.java
                        ServerThread.java SocketServerInvoker.java
  Log:
  Various logging improvments, minor reformatting and new tests in preparation 
  for a solution for http://jira.jboss.org/jira/browse/JBREM-666.
  
  Includes http://jira.jboss.org/jira/browse/JBREM-667.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.16.2.5  +27 -31    JBossRemoting/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MicroSocketClientInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/MicroSocketClientInvoker.java,v
  retrieving revision 1.16.2.4
  retrieving revision 1.16.2.5
  diff -u -b -r1.16.2.4 -r1.16.2.5
  --- MicroSocketClientInvoker.java	11 Jan 2007 20:34:50 -0000	1.16.2.4
  +++ MicroSocketClientInvoker.java	13 Jan 2007 12:42:36 -0000	1.16.2.5
  @@ -32,12 +32,12 @@
    *
    * @author <a href="mailto:jhaynie at vocalocity.net">Jeff Haynie</a>
    * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
  - * @version $Revision: 1.16.2.4 $
  + * @version $Revision: 1.16.2.5 $
    */
   public class MicroSocketClientInvoker extends RemoteClientInvoker
   {
      private static final Logger log = Logger.getLogger(MicroSocketClientInvoker.class);
  -   private static final boolean isTraceEnabled = log.isTraceEnabled();
  +   private static final boolean trace = log.isTraceEnabled();
   
      protected InetAddress addr;
      protected int port;
  @@ -140,13 +140,11 @@
      private volatile boolean bailOut;
   
      public MicroSocketClientInvoker(InvokerLocator locator)
  -         throws IOException
      {
         this(locator, null);
      }
   
      public MicroSocketClientInvoker(InvokerLocator locator, Map configuration)
  -         throws IOException
      {
         super(locator, configuration);
         try
  @@ -191,8 +189,7 @@
            {
               try
               {
  -               boolean bVal = Boolean.valueOf((String) val).booleanValue();
  -               enableTcpNoDelay = bVal;
  +               enableTcpNoDelay = Boolean.valueOf((String) val).booleanValue();
                  log.debug("Setting SocketClientInvoker::enableTcpNoDelay to: " + enableTcpNoDelay);
               }
               catch (Exception e)
  @@ -206,8 +203,7 @@
            {
               try
               {
  -               int nVal = Integer.valueOf((String) val).intValue();
  -               maxPoolSize = nVal;
  +               maxPoolSize = Integer.valueOf((String)val).intValue();
                  log.debug("Setting SocketClientInvoker::maxPoolSize to: " + maxPoolSize);
               }
               catch (Exception e)
  @@ -270,7 +266,7 @@
   
      public synchronized void disconnect()
      {
  -      if (isTraceEnabled) { log.trace(this + " disconnecting ..."); }
  +      if (trace) { log.trace(this + " disconnecting ..."); }
         bailOut = true;
         super.disconnect();
      }
  @@ -332,15 +328,17 @@
            {
               throw new CannotConnectException("Can not get connection to server.  Problem establishing socket connection for locator - " + locator, e);
            }
  +
            long end = System.currentTimeMillis() - start;
            getSocketTime += end;
  +
            try
            {
  -
               int version = Version.getDefaultVersion();
               boolean performVersioning = Version.performVersioning();
   
               OutputStream outputStream = socketWrapper.getOutputStream();
  +
               if (performVersioning)
               {
                  writeVersion(outputStream, version);
  @@ -359,10 +357,7 @@
                  Object val = metadata.get(org.jboss.remoting.Client.ONEWAY_FLAG);
                  if(val != null && val instanceof String && Boolean.valueOf((String)val).booleanValue())
                  {
  -                  if(isTraceEnabled)
  -                  {
  -                     log.trace("Oneway invocation, so not waiting for response.  Returning null.");
  -                  }
  +                  if(trace) { log.trace(this + " sent oneway invocation, so not waiting for response, returning null"); }
                     return null;
                  }
               }
  @@ -393,7 +388,7 @@
               }
               catch (Exception ex)
               {
  -               if (isTraceEnabled) { log.trace(this + " couldn't successfully close its socketWrapper", ex); }
  +               if (trace) { log.trace(this + " couldn't successfully close its socketWrapper", ex); }
               }
   
               /**
  @@ -411,7 +406,7 @@
            }
            catch (Exception ex)
            {
  -            log.debug(this + " got Exception " + ex);
  +            log.debug(this + " got exception " + ex);
   
               try
               {
  @@ -447,7 +442,7 @@
            }
            else
            {
  -            if (isTraceEnabled)
  +            if (trace)
               {
                  log.trace("Pool was already full, will close the connection");
               }
  @@ -461,14 +456,8 @@
            }
         }
   
  -      // Return response
  -      if (isTraceEnabled)
  -      {
  -         log.trace("Response: " + response);
  -      }
  -
  +      if (trace) { log.trace(this + " received " + response);  }
         return response;
  -
      }
   
      public void flushConnectionPool()
  @@ -512,6 +501,7 @@
            case Version.VERSION_1:
            case Version.VERSION_2:
            {
  +            if (trace) { log.trace(this + " reading response from input stream"); }
               return unmarshaller.read(inputStream, null);
            }
            default:
  @@ -529,7 +519,10 @@
            case Version.VERSION_1:
            case Version.VERSION_2:
            {
  +            if (trace) { log.trace(this + " writing invocation on output stream"); }
               marshaller.write(invocation, outputStream);
  +            if (trace) { log.trace(this + " done writing invocation on output stream"); }
  +
               return;
            }
            default:
  @@ -542,16 +535,19 @@
      //TODO: -TME Exact same method in ServerThread
      private int readVersion(InputStream inputStream) throws IOException
      {
  -      return inputStream.read();
  +      if (trace) { log.trace(this + " reading version from input stream"); }
  +      int version = inputStream.read();
  +      if (trace) { log.trace(this + " read version " + version + " from input stream"); }
  +      return version;
      }
   
      //TODO: -TME Exact same method in ServerThread
      private void writeVersion(OutputStream outputStream, int version) throws IOException
      {
  +      if (trace) { log.trace(this + " writing version " + version + " on output stream"); }
         outputStream.write(version);
      }
   
  -
      /**
       * Close all sockets in a specific pool.
       */
  @@ -599,7 +595,7 @@
            {
               ServerAddress sa = (ServerAddress) it.next();
   
  -            if (isTraceEnabled) { log.trace("clearing pool for " + sa); }
  +            if (trace) { log.trace("clearing pool for " + sa); }
   
               clearPool(sa);
            }
  @@ -721,9 +717,9 @@
                  long timestamp = System.currentTimeMillis();
                  try
                  {
  -                  if (isTraceEnabled)
  +                  if (trace)
                     {
  -                     log.trace(this + " creating socket number " + (counter++) + ", attempt number " + (i + 1));
  +                     log.trace(this + " creating socket " + (counter++) + ", attempt " + (i + 1));
                     }
                     socket = createSocket(address.address, address.port);
                  }
  @@ -808,7 +804,7 @@
            }
            catch (Exception ex)
            {
  -            if (isTraceEnabled)
  +            if (trace)
               {
                  log.trace("Couldn't reuse connection from pool");
               }
  
  
  
  1.29.2.6  +110 -88   JBossRemoting/src/main/org/jboss/remoting/transport/socket/ServerThread.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerThread.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/ServerThread.java,v
  retrieving revision 1.29.2.5
  retrieving revision 1.29.2.6
  diff -u -b -r1.29.2.5 -r1.29.2.6
  --- ServerThread.java	11 Jan 2007 20:34:50 -0000	1.29.2.5
  +++ ServerThread.java	13 Jan 2007 12:42:36 -0000	1.29.2.6
  @@ -59,27 +59,33 @@
    *
    * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
    * @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
  - * @version $Revision: 1.29.2.5 $
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + *
  + * @version $Revision: 1.29.2.6 $
    */
   public class ServerThread extends Thread
   {
      final static private Logger log = Logger.getLogger(ServerThread.class);
   
  +   private static final boolean trace = log.isTraceEnabled();
  +
      protected SocketServerInvoker invoker;
      protected LRUPool clientpool;
      protected LinkedList threadpool;
      protected volatile boolean running = true;
      protected volatile boolean handlingResponse = true; // start off as true so that nobody can interrupt us
      protected volatile boolean shutdown = false;
  -   protected static int id = 0;
  +
  +   protected static int idGenerator = 0;
   
      private SocketWrapper socketWrapper = null;
      protected String serverSocketClassName = ServerSocketWrapper.class.getName();
      protected Class serverSocketClass = null;
      private Constructor serverSocketConstructor = null;
   
  -   private static final boolean isTrace = log.isTraceEnabled();
  -   private static final boolean isDebug = log.isDebugEnabled();
  +   // the unique identity of the thread, which won't change during the life of the thread. The
  +   // thread may get associated with different IP addresses though.
  +   private int id = Integer.MIN_VALUE;
   
      /**
       * Indicates if will check the socket connection when
  @@ -97,19 +103,23 @@
   
      public static synchronized int nextID()
      {
  -      int nextID = id++;
  -      return nextID;
  +      return idGenerator++;
      }
   
      public ServerThread(Socket socket, SocketServerInvoker invoker, LRUPool clientpool,
  -                       LinkedList threadpool, int timeout, String serverSocketClassName) throws Exception
  +                       LinkedList threadpool, int timeout, String serverSocketClassName)
  +      throws Exception
      {
  -      super("SocketServerInvokerThread-" + socket.getInetAddress().getHostAddress() + "-" + nextID());
  +      super();
  +
  +      setName(getWorkerThreadName(socket));
  +
         this.serverSocketClassName = serverSocketClassName;
         this.socketWrapper = createServerSocket(socket, timeout, invoker.getLocator().getParameters());
         this.invoker = invoker;
         this.clientpool = clientpool;
         this.threadpool = threadpool;
  +
         init();
      }
   
  @@ -172,8 +182,6 @@
      /**
       * Indicates if server will check with client (via an ACK) to
       * see if is still there.
  -    *
  -    * @return
       */
      public boolean getCheckingConnection()
      {
  @@ -262,16 +270,16 @@
   
      public synchronized void wakeup(Socket socket, int timeout, Map metadata) throws Exception
      {
  +      // rename the worker thread to reflect the new socket it is handling
  +      setName(getWorkerThreadName(socket));
  +
         this.socketWrapper = createServerSocket(socket, timeout, metadata);
  -      String name = "SocketServerInvokerThread-" + socket.getInetAddress().getHostAddress() + "-" + nextID();
  -      super.setName(name);
  +
         running = true;
         handlingResponse = true;
         this.notify();
  -      if(isTrace)
  -      {
  -         log.trace("Have woken up " + getName());
  -      }
  +
  +      if(trace) { log.trace(this + " has woken up"); }
      }
   
      public void run()
  @@ -311,7 +319,7 @@
                        }
                        else
                        {
  -                        if(isTrace)
  +                        if(trace)
                           {
                              log.trace("removing from clientpool and adding to threadpool " + this);
                           }
  @@ -325,12 +333,12 @@
   
                  try
                  {
  -                  if(isTrace)
  +                  if(trace)
                     {
                        log.trace("begin thread wait");
                     }
                     this.wait();
  -                  if(isTrace)
  +                  if(trace)
                     {
                        log.trace("WAKEUP in SERVER THREAD");
                     }
  @@ -350,13 +358,31 @@
         }
         catch (Exception ignored)
         {
  -         if(isDebug)
  -         {
               log.debug("Exiting run on exception", ignored);
            }
         }
  +
  +   public String toString()
  +   {
  +      return getName();
  +   }
  +
  +   private String getWorkerThreadName(Socket currentSocket)
  +   {
  +      if (id == Integer.MIN_VALUE)
  +      {
  +         id = nextID();
      }
   
  +      StringBuffer sb = new StringBuffer("WorkerThread#");
  +      sb.append(id).append('[');
  +      sb.append(currentSocket.getInetAddress().getHostAddress());
  +      sb.append(':');
  +      sb.append(currentSocket.getPort());
  +      sb.append(']');
  +
  +      return sb.toString();
  +   }
   
      protected void acknowledge() throws Exception
      {
  @@ -373,6 +399,7 @@
   
            try
            {
  +            if(trace) { log.trace("checking connection"); }
               socketWrapper.checkConnection();
            }
            catch (EOFException e)
  @@ -393,79 +420,76 @@
      }
   
      protected Object versionedRead(InputStream inputStream, ServerInvoker invoker,
  -                                  ClassLoader classLoader, int version) throws IOException, ClassNotFoundException
  +                                  ClassLoader classLoader, int version)
  +      throws IOException, ClassNotFoundException
      {
  -      //TODO: -TME - Should I even botther to check for version here?  Only one way to do processing at this
  -      // point, regardless of version.
  +      //TODO: -TME - Should I even botther to check for version here?  Only one way to do processing
  +      //             at this point, regardless of version.
         switch (version)
         {
            case Version.VERSION_1:
            case Version.VERSION_2:
            {
  -
               //TODO: -TME Need better way to get the unmarshaller (via config)
  -            UnMarshaller unmarshaller = MarshalFactory.getUnMarshaller(invoker.getLocator(), classLoader);
  +            UnMarshaller unmarshaller = MarshalFactory.
  +               getUnMarshaller(invoker.getLocator(), classLoader);
  +
               if (unmarshaller == null)
               {
  -               unmarshaller = MarshalFactory.getUnMarshaller(invoker.getDataType(), invoker.getSerializationType());
  +               unmarshaller = MarshalFactory.
  +                  getUnMarshaller(invoker.getDataType(), invoker.getSerializationType());
               }
  +
  +            if(trace) { log.trace("performing versioned read from the input stream"); }
               return unmarshaller.read(inputStream, null);
            }
            default:
            {
  -            throw new IOException("Can not read data for version " + version + ".  Supported versions: " + Version.VERSION_1 + "," + Version.VERSION_2);
  +            throw new IOException("Can not read data for version " + version +
  +               ".  Supported versions: " + Version.VERSION_1 + "," + Version.VERSION_2);
            }
         }
      }
   
      protected void processInvocation() throws Exception
      {
  -      if(isTrace)
  -      {
  -         log.trace("processing invocation in server thread.");
  -      }
  +      if(trace) { log.trace("processing invocation"); }
  +
         handlingResponse = true;
  +
         // Ok, now read invocation and invoke
   
         //TODO: -TME This needs to be done by ServerInvoker
         int version = Version.getDefaultVersion();
         boolean performVersioning = Version.performVersioning();
         InputStream inputStream = socketWrapper.getInputStream();
  +
         if (performVersioning)
         {
  -//         if(!inputStream.markSupported())
  -//         {
  -//            inputStream = new BufferedInputStream(inputStream);
  -//         }
  -//         // marking the stream in case the version is invalid
  -//         inputStream.mark(2);
  -
            version = readVersion(inputStream);
  +
            //TODO: -TME Should I be checking for -1?
   
  -         /**
  -          * This is a best attempt to determine if is old version.  Typically, the first
  -          * byte will be -1, so if is, will reset stream and process as though is older version
  -          */
  -         /**
  -          * Originally this code (now uncommented) and the other commented code was to try to
  -          * make so could automatically detect older version that would not be sending a byte
  -          * for the version.  However, due to the way the serialization stream manager handles
  -          * the stream, resetting it does not work, so will probably have to throw away that idea.
  -          * However, for now, am uncommenting this section because if are using the flag to turn
  -          * off connection checking (ack back to client), then will get a -1 when the client
  -          * closes connection.  Then when stream passed onto the versionedRead, will get EOFException
  -          * thrown and will process normally (as though came from the acknowledge, as would have happened
  -          * if connection checking was turned on).  Am hoping this is not a mistake...
  -          */
  +         // This is a best attempt to determine if is old version.  Typically, the first byte will
  +         // be -1, so if is, will reset stream and process as though is older version.
  +
  +         // Originally this code (now uncommented) and the other commented code was to try to make
  +         // so could automatically detect older version that would not be sending a byte for the
  +         // version.  However, due to the way the serialization stream manager handles the stream,
  +         // resetting it does not work, so will probably have to throw away that idea. However, for
  +         // now, am uncommenting this section because if are using the flag to turn off connection
  +         // checking (ack back to client), then will get a -1 when the client closes connection.
  +         // Then when stream passed onto the versionedRead, will get EOFException thrown and will
  +         // process normally (as though came from the acknowledge, as would have happened if
  +         // connection checking was turned on).  Am hoping this is not a mistake...
  +
            if(version == -1)
            {
               version = Version.VERSION_1;
  -//            inputStream.reset();
            }
         }
   
  -      Object obj = versionedRead(inputStream, invoker, this.getClass().getClassLoader(), version);
  +      Object obj = versionedRead(inputStream, invoker, getClass().getClassLoader(), version);
   
         // setting timestamp since about to start processing
         lastRequestHandledTimestamp = System.currentTimeMillis();
  @@ -484,27 +508,26 @@
            performVersioning = false;
         }
   
  -
         Object resp = null;
  +
         try
         {
  -         if(isTrace)
  -         {
  -            log.trace("About to call ServerInvoker.invoke()");
  -         }
            // Make absolutely sure thread interrupted is cleared.
  -         boolean interrupted = Thread.interrupted();
  +         Thread.interrupted();
  +
  +         if(trace) { log.trace("about to call ServerInvoker.invoke()"); }
  +
            // call transport on the subclass, get the result to handback
            resp = invoker.invoke(req);
  -         if(isTrace)
  -         {
  -            log.trace("ServerInvoker.invoke() returned");
  -         }
  +
  +         if(trace) { log.trace("returned from ServerInvoker.invoke()"); }
         }
         catch (Throwable ex)
         {
            resp = ex;
            isError = true;
  +
  +         if(trace) { log.trace("ServerInvoker.invoke() call generated an exception", ex); }
         }
   
         Thread.interrupted(); // clear interrupted state so we don't fail on socket writes
  @@ -539,7 +562,7 @@
            Object val = metadata.get(org.jboss.remoting.Client.ONEWAY_FLAG);
            if (val != null && val instanceof String && Boolean.valueOf((String) val).booleanValue())
            {
  -            if (isTrace)
  +            if (trace)
               {
                  log.trace("Oneway invocation, so not waiting for response.  Returning null.");
               }
  @@ -560,8 +583,9 @@
            // need to wrap request with invocation request
            SocketAddress remoteAddress = socketWrapper.getSocket().getRemoteSocketAddress();
   
  -         InvocationRequest request = new InvocationRequest(remoteAddress.toString(), invoker.getSupportedSubsystems()[0], obj, null, null, null);
  -         return request;
  +         return new InvocationRequest(remoteAddress.toString(),
  +                                      invoker.getSupportedSubsystems()[0],
  +                                      obj, null, null, null);
         }
   
      }
  @@ -595,6 +619,7 @@
   
      private int readVersion(InputStream inputStream) throws IOException
      {
  +      if(trace) { log.trace("blocking to read version from input stream"); }
         return inputStream.read();
         }
   
  @@ -608,21 +633,20 @@
       */
      protected void dorun()
      {
  -      if(isTrace)
  -      {
  -         log.trace("beginning dorun");
  -      }
  +      if(trace) { log.trace("beginning dorun()"); }
  +
         running = true;
         handlingResponse = true;
   
         // Always do first one without an ACK because its not needed
         try
         {
  +         if(trace) { log.trace("processing first invocation without acknowledging"); }
            processInvocation();
         }
         catch (Exception ex)
         {
  -         log.error("failed to process invocation.", ex);
  +         log.error("failed to process invocation!", ex);
            running = false;
         }
   
  @@ -636,18 +660,17 @@
            }
            catch (AcknowledgeFailure e)
            {
  -            if (!shutdown && isTrace)
  +            if (!shutdown && trace)
               {
  -               log.trace("Keep alive acknowledge failed.");
  +               log.trace("keep alive acknowledge failed!");
               }
               running = false;
  -
            }
            catch(SocketTimeoutException ste)
            {
               if(!shutdown)
               {
  -               if(isTrace)
  +               if(trace)
                  {
                     log.trace(ste);
                  }
  @@ -665,7 +688,7 @@
            }
            catch (InterruptedException e)
            {
  -            if(isTrace)
  +            if(trace)
               {
                  log.trace(e);
               }
  @@ -676,16 +699,15 @@
            }
            catch (EOFException eof)
            {
  -            if (!shutdown && isTrace)
  +            if (!shutdown && trace)
               {
  -               log.trace("EOF received.  This is likely due to client finishing comminication.");
  +               log.trace("EOFException received. This is likely due to client finishing communication.");
               }
               running = false;
  -
            }
            catch (SocketException sex)
            {
  -            if (!shutdown && isTrace)
  +            if (!shutdown && trace)
               {
                  log.trace("SocketException received.  This is likely due to client disconnecting and resetting connection.");
               }
  @@ -703,6 +725,7 @@
            handlingResponse = false;
            Thread.interrupted();
         }
  +
         // Ok, we've been shutdown.  Do appropriate cleanups.
         try
         {
  @@ -733,6 +756,5 @@
   
      public static class AcknowledgeFailure extends Exception
      {
  -
      }
   }
  
  
  
  1.30.2.5  +53 -55    JBossRemoting/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SocketServerInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java,v
  retrieving revision 1.30.2.4
  retrieving revision 1.30.2.5
  diff -u -b -r1.30.2.4 -r1.30.2.5
  --- SocketServerInvoker.java	19 Dec 2006 06:02:23 -0000	1.30.2.4
  +++ SocketServerInvoker.java	13 Jan 2007 12:42:36 -0000	1.30.2.5
  @@ -27,8 +27,10 @@
   import org.jboss.remoting.util.TimerUtil;
   import org.jboss.remoting.marshal.serializable.SerializableMarshaller;
   import org.jboss.util.propertyeditor.PropertyEditors;
  +import org.jboss.logging.Logger;
   
   import javax.net.ServerSocketFactory;
  +import javax.net.ssl.SSLException;
   import java.io.IOException;
   import java.net.InetAddress;
   import java.net.ServerSocket;
  @@ -45,13 +47,15 @@
    *
    * @author <a href="mailto:jhaynie at vocalocity.net">Jeff Haynie</a>
    * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
  - * @version $Revision: 1.30.2.4 $
  + * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  + *
  + * @version $Revision: 1.30.2.5 $
    * @jmx:mbean
    */
   public class SocketServerInvoker extends ServerInvoker implements Runnable, SocketServerInvokerMBean
   {
  -   private InetAddress addr;
  -   private int port;
  +   private static final Logger log = Logger.getLogger(SocketServerInvoker.class);
  +
      static int clientCount = 0;
   
      private Properties props = new Properties();
  @@ -121,10 +125,11 @@
       * creating a new ServerSocket from new ServerSocketFactory
       * @throws IOException
       */
  -   protected void refreshServerSocket() throws IOException{
  +   protected void refreshServerSocket() throws IOException
  +   {
   	   newServerSocketFactory=false;
   	   serverSocket.close();
  -	   serverSocket=null;
  +	   serverSocket = null;
   	   InetAddress bindAddress = InetAddress.getByName(getServerBindAddress());
   	   serverSocket = createServerSocket(getServerBindPort(), backlog, bindAddress);
         serverSocket.setReuseAddress(reuseAddress);
  @@ -247,7 +252,7 @@
   
      protected String getThreadName(int i)
      {
  -      return "SocketServerInvoker#" + i + "-" + getServerBindPort();
  +      return "AcceptorThread#" + i + ":" + getServerBindPort();
      }
   
      public void destroy()
  @@ -342,7 +347,6 @@
      /**
       * Indicates if SO_REUSEADDR is enabled on server sockets
       * Default is true.
  -    * @return
       */
      public boolean getReuseAddress()
      {
  @@ -487,12 +491,9 @@
   
      public void run()
      {
  -      if(trace)
  -      {
  -         log.trace("Started execution of method run");
  -      }
  +      if(trace) { log.trace(this + " started execution of method run()"); }
   
  -      ServerSocketRefresh thread=new ServerSocketRefresh();
  +      ServerSocketRefresh thread = new ServerSocketRefresh();
         thread.start();
   
         try
  @@ -501,20 +502,17 @@
            {
               try
               {
  -               if(trace)
  -               {
  -                  log.trace("Socket is going to be accepted");
  -               }
  -
                  thread.release(); //goes on if serversocket refresh is completed
  +
  +               if(trace) { log.trace(this + " is going to wait on serverSocket.accept()"); }
  +
                  Socket socket = serverSocket.accept();
  -               if(trace)
  -               {
  -                  log.trace("Accepted: " + socket);
  -               }
  +
  +               if(trace) { log.trace(this + " accepted " + socket); }
  +
                  processInvocation(socket);
               }
  -            catch (javax.net.ssl.SSLException e)
  +            catch (SSLException e)
               {
                  log.error("SSLServerSocket error", e);
                  return;
  @@ -523,7 +521,7 @@
               {
                  if(running)
                  {
  -                  log.error("Failed to accept socket connection", ex);
  +                  log.error(this + " failed to handle socket", ex);
                  }
               }
            }
  @@ -534,54 +532,55 @@
         }
      }
   
  -   protected void processInvocation(Socket socket)
  -         throws Exception
  +   protected void processInvocation(Socket socket) throws Exception
      {
         ServerThread thread = null;
         boolean newThread = false;
   
         while(thread == null)
         {
  -         if(log.isTraceEnabled())
  -         {
  -            log.trace("try to get a thread for processing");
  -         }
  +         if(trace) { log.trace(this + " trying to get a worker thread for processing"); }
  +
            synchronized(threadpool)
            {
               if(threadpool.size() > 0)
               {
  -               thread = (ServerThread) threadpool.removeFirst();
  -               if(log.isTraceEnabled())
  -               {
  -                  log.trace("Got thread for processing - " + thread);
  -               }
  +               thread = (ServerThread)threadpool.removeFirst();
  +
  +               if(trace) { log.trace(this + (thread == null ? " found NO threads in pool" : " got " + thread + " from pool")); }
               }
            }
  +
            if(thread == null)
            {
               synchronized(clientpool)
               {
                  if(clientpool.size() < maxPoolSize)
                  {
  -                  thread = new ServerThread(socket, this, clientpool, threadpool, getTimeout(), serverSocketClass);
  +                  if(trace) { log.trace(this + " creating new worker thread"); }
  +
  +                  thread = new ServerThread(socket, this, clientpool, threadpool,
  +                                            getTimeout(), serverSocketClass);
  +
  +                  if(trace) { log.trace(this + " created " + thread); }
  +
                     newThread = true;
                  }
  +
                  if(thread == null)
                  {
                     clientpool.evict();
  -                  if(trace)
  -                  {
  -                     log.trace("Waiting for a thread...");
  -                  }
  +
  +                  if(trace) {log.trace(this + " waiting for a thread from clientpool"); }
  +
                     clientpool.wait();
  -                  if(trace)
  -                  {
  -                     log.trace("Notified of available thread");
  -                  }
  +
  +                  if(trace) { log.trace(this + " notified of clientpool thread availability"); }
                  }
               }
            }
         }
  +
         synchronized(clientpool)
         {
            clientpool.insert(thread, thread);
  @@ -589,18 +588,12 @@
   
         if(newThread)
         {
  -         if(trace)
  -         {
  -            log.trace("Created a new thread, t=" + thread);
  -         }
  +         if(trace) {log.trace(this + " starting " + thread); }
            thread.start();
         }
         else
         {
  -         if(trace)
  -         {
  -            log.trace("Reusing thread t=" + thread);
  -         }
  +         if(trace) { log.trace(this + " reusing " + thread); }
            thread.wakeup(socket, getTimeout(), locator.getParameters());
         }
      }
  @@ -609,20 +602,25 @@
       * returns true if the transport is bi-directional in nature, for example,
       * SOAP in unidirectional and SOCKETs are bi-directional (unless behind a firewall
       * for example).
  -    *
  -    * @return
       */
      public boolean isTransportBiDirectional()
      {
         return true;
      }
   
  +   public String toString()
  +   {
  +      return "SocketServerInvoker[" +
  +         (serverSocket == null ?
  +            "UNINITIALIZED" :
  +            serverSocket.getInetAddress().getHostAddress() + ":" + serverSocket.getLocalPort()) +
  +         "]";
  +   }
  +
      /**
       * Each implementation of the remote client invoker should have
       * a default data type that is uses in the case it is not specified
       * in the invoker locator uri.
  -    *
  -    * @return
       */
      protected String getDefaultDataType()
      {
  
  
  



More information about the jboss-cvs-commits mailing list