[jboss-cvs] JBoss Messaging SVN: r1577 - branches/Branch_1_0_1_SP/src/main/org/jboss/jms/client/remoting

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 16 23:24:52 EST 2006


Author: ron_sigal
Date: 2006-11-16 23:24:51 -0500 (Thu, 16 Nov 2006)
New Revision: 1577

Added:
   branches/Branch_1_0_1_SP/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java
Log:
Netflix patch: Socket wrapper for client side socket transport invoker.

Added: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java	2006-11-17 04:22:42 UTC (rev 1576)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/client/remoting/ClientSocketWrapper.java	2006-11-17 04:24:51 UTC (rev 1577)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.jms.client.remoting;
+
+
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.serialization.SerializationStreamFactory;
+import org.jboss.remoting.transport.socket.SocketWrapper;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+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;
+
+/**
+ * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
+ */
+public class ClientSocketWrapper extends SocketWrapper
+{
+   private ObjectInputStream in;
+   private ObjectOutputStream out;
+
+   public ClientSocketWrapper(Socket socket) throws IOException
+   {
+      super(socket);
+      createStreams(socket, null);
+   }
+
+   public ClientSocketWrapper(Socket socket, Map metadata, Integer timeout) throws Exception
+   {
+      super(socket, timeout);
+      createStreams(socket, metadata);
+   }
+
+   protected void createStreams(Socket socket, Map metadata) throws IOException
+   {
+
+      String serializationType = "jboss"; // hardcoding to default to jboss serialization
+
+      if(metadata != null)
+      {
+         String serializationTypeParam = (String) metadata.get(InvokerLocator.SERIALIZATIONTYPE);
+         if(serializationTypeParam == null || serializationTypeParam.length() == 0)
+         {
+            serializationTypeParam = (String) metadata.get(InvokerLocator.SERIALIZATIONTYPE_CASED);
+         }
+         if(serializationTypeParam != null && serializationTypeParam.length() > 0)
+         {
+            serializationType = serializationTypeParam;
+         }
+      }
+
+      out = createOutputStream(serializationType, socket);
+      in = createInputStream(serializationType, socket);
+   }
+
+   protected ObjectInputStream createInputStream(String serializationType, Socket socket)
+         throws IOException
+   {
+      BufferedInputStream bin = new BufferedInputStream(socket.getInputStream());
+      ObjectInputStream oin = SerializationStreamFactory.getManagerInstance(serializationType).createInput(bin, null);
+      return oin;
+   }
+
+   protected ObjectOutputStream createOutputStream(String serializationType, Socket socket)
+         throws IOException
+   {
+      BufferedOutputStream bout = new BufferedOutputStream(socket.getOutputStream());
+      ObjectOutputStream oout = SerializationStreamFactory.getManagerInstance(serializationType).createOutput(bout);
+      return oout;
+   }
+
+   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();
+   }
+}




More information about the jboss-cvs-commits mailing list