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

Ron Sigal ron_sigal at yahoo.com
Sat Feb 3 00:06:27 EST 2007


  User: rsigal  
  Date: 07/02/03 00:06:27

  Modified:    src/main/org/jboss/remoting/transport/socket 
                        ClientSocketWrapper.java
  Log:
  JBREM-598, JBREM-690, JBREM-692, and ovidiu's logging changes: sync with remoting_2_x.
  
  Revision  Changes    Path
  1.18      +126 -37   JBossRemoting/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClientSocketWrapper.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/ClientSocketWrapper.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- ClientSocketWrapper.java	9 Nov 2006 21:35:23 -0000	1.17
  +++ ClientSocketWrapper.java	3 Feb 2007 05:06:26 -0000	1.18
  @@ -22,22 +22,40 @@
   
   package org.jboss.remoting.transport.socket;
   
  -import org.jboss.remoting.InvokerLocator;
  -
   import java.io.IOException;
   import java.io.InputStream;
  +import java.io.ObjectInputStream;
  +import java.io.ObjectOutputStream;
   import java.io.OutputStream;
   import java.net.Socket;
   import java.util.Map;
  +import org.jboss.remoting.InvokerLocator;
  +import org.jboss.remoting.marshal.Marshaller;
  +import org.jboss.remoting.marshal.PreferredStreamMarshaller;
  +import org.jboss.remoting.marshal.PreferredStreamUnMarshaller;
  +import org.jboss.remoting.marshal.UnMarshaller;
  +import org.jboss.logging.Logger;
   
   /**
    * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
    */
  -public class ClientSocketWrapper extends SocketWrapper
  +public class ClientSocketWrapper extends SocketWrapper implements OpenConnectionChecker
   {
  +   // Constants ------------------------------------------------------------------------------------
  +
  +   private static final Logger log = Logger.getLogger(ClientSocketWrapper.class);
  +
  +   // Static ---------------------------------------------------------------------------------------
  +
  +   private static boolean trace = log.isTraceEnabled();
  +
  +   // Attributes -----------------------------------------------------------------------------------
  +
      private InputStream in;
      private OutputStream out;
   
  +   // Constructors ---------------------------------------------------------------------------------
  +
      public ClientSocketWrapper(Socket socket) throws IOException
      {
         super(socket);
  @@ -50,6 +68,57 @@
         createStreams(socket, metadata);
      }
   
  +   // SocketWrapper overrides ----------------------------------------------------------------------
  +
  +   public OutputStream getOutputStream()
  +   {
  +      return out;
  +   }
  +
  +   public InputStream getInputStream()
  +   {
  +      return in;
  +   }
  +
  +   public void checkConnection() throws IOException
  +   {
  +      // Test to see if socket is alive by send ACK message
  +      final byte ACK = 1;
  +      
  +//      out.reset();
  +//      out.writeByte(ACK);
  +//      out.flush();
  +//      in.readByte();
  +
  +      out.write(ACK);
  +      out.flush();
  +      int i = in.read();
  +      if (trace) { log.trace(this + " got " + i + " while checking connection"); }
  +   }
  +   
  +   // OpenConnectionChecker implementation ---------------------------------------------------------
  +   
  +   public void checkOpenConnection() throws IOException
  +   {
  +      log.debug("checking open connection");
  +      if (in.available() > 0)
  +      {
  +         log.debug("remote endpoint has closed");
  +         throw new IOException("remote endpoint has closed");
  +      }
  +   }
  +
  +   // Public ---------------------------------------------------------------------------------------
  +
  +   public String toString()
  +   {
  +      return "ClientSocketWrapper[" + getSocket() + "]";
  +   }
  +
  +   // Package protected ----------------------------------------------------------------------------
  +
  +   // Protected ------------------------------------------------------------------------------------
  +
      protected void createStreams(Socket socket, Map metadata) throws IOException
      {
   
  @@ -68,50 +137,70 @@
            }
         }
   
  -      out = createOutputStream(serializationType, socket);
  -      in = createInputStream(serializationType, socket);
  -   }
  +      Marshaller marshaller = null;
  +      UnMarshaller unmarshaller = null;
  +      int tempTimeout = -1;
  +      int savedTimeout = getTimeout();
   
  -   protected InputStream createInputStream(String serializationType, Socket socket)
  -         throws IOException
  +      if (metadata != null)
  +      {
  +         marshaller = (Marshaller) metadata.get(MARSHALLER);
  +         unmarshaller = (UnMarshaller) metadata.get(UNMARSHALLER);
  +         Object o = metadata.get(TEMP_TIMEOUT);
  +         if (o instanceof Integer)
      {
  -//      BufferedInputStream bin = new BufferedInputStream(socket.getInputStream());
  -//      ObjectInputStream oin = SerializationStreamFactory.getManagerInstance(serializationType).createInput(bin, null);
  -//      return oin;
  -      return socket.getInputStream();
  +            tempTimeout = ((Integer) o).intValue();
  +            if (tempTimeout != -1)
  +            {
  +               socket.setSoTimeout(tempTimeout);
  +            }
  +         }
  +      }
  +      
  +      out = createOutputStream(serializationType, socket, marshaller);
  +      in = createInputStream(serializationType, socket, unmarshaller);
  +      setTimeout(savedTimeout);
      }
   
  -   protected OutputStream createOutputStream(String serializationType, Socket socket)
  +   protected InputStream createInputStream(String serializationType, Socket socket, UnMarshaller unmarshaller)
            throws IOException
      {
  -//      BufferedOutputStream bout = new BufferedOutputStream(socket.getOutputStream());
  -//      ObjectOutputStream oout = SerializationStreamFactory.getManagerInstance(serializationType).createOutput(bout);
  -//      return oout;
  -      return socket.getOutputStream();
  -   }
  +      if (trace) { log.trace(this + " getting input stream from " + socket + ", " + unmarshaller); }
   
  -   public OutputStream getOutputStream()
  +      if (unmarshaller == null)
  +         log.warn("got null unmarshaller");
  +      
  +      InputStream is = socket.getInputStream();
  +      if (unmarshaller instanceof PreferredStreamUnMarshaller)
      {
  -      return out;
  +         PreferredStreamUnMarshaller psum = (PreferredStreamUnMarshaller) unmarshaller;
  +         is = psum.getMarshallingStream(is);
      }
   
  -   public InputStream getInputStream()
  -   {
  -      return in;
  +      return is;
      }
   
  -   public void checkConnection() throws IOException
  +   protected OutputStream createOutputStream(String serializationType, Socket socket, Marshaller marshaller)
  +         throws IOException
      {
  -      // Test to see if socket is alive by send ACK message
  -      final byte ACK = 1;
  +      if (trace) { log.trace(this + " getting output stream from " + socket + ", " + marshaller); }
   
  -//      out.reset();
  -//      out.writeByte(ACK);
  -//      out.flush();
  -//      in.readByte();
   
  -      out.write(ACK);
  -      out.flush();
  -      in.read();
  +      if (marshaller == null)
  +         log.warn("got null marshaller");
  +      
  +      OutputStream os = socket.getOutputStream();
  +      if (marshaller instanceof PreferredStreamMarshaller)
  +      {
  +         PreferredStreamMarshaller psm = (PreferredStreamMarshaller) marshaller;
  +         os = psm.getMarshallingStream(os);
      }
  +      
  +      return os;
  +   }
  +
  +   // Private --------------------------------------------------------------------------------------
  +
  +   // Inner classes --------------------------------------------------------------------------------
  +
   }
  
  
  



More information about the jboss-cvs-commits mailing list