Mark Salter | 27 Nov 2009 12:12

Addition of BaseChannel.send(byte[])

I would like to add the ability to send 'raw' data through a channel,
but can anyone see a reason not to or object at all?

If not, I would also add the same method to ISOChannel (and adjust
ChannelPool, LoopbackChannel).

The patch for these items follows:-

### Eclipse Workspace Patch 1.0
#P jpos6
Index: modules/jpos/src/org/jpos/iso/channel/ChannelPool.java
===================================================================
--- modules/jpos/src/org/jpos/iso/channel/ChannelPool.java	(revision 2807)
+++ modules/jpos/src/org/jpos/iso/channel/ChannelPool.java	(working copy)
 <at>  <at>  -105,6 +105,9  <at>  <at> 
     public void send (ISOMsg m) throws IOException, ISOException {
         getCurrent().send (m);
     }
+    public void send (byte[] b) throws IOException, ISOException {
+        getCurrent().send (b);
+    }
     public void setUsable(boolean b) {
         this.usable = b;
     }
Index: modules/jpos/src/org/jpos/iso/channel/LoopbackChannel.java
===================================================================
--- modules/jpos/src/org/jpos/iso/channel/LoopbackChannel.java	(revision
2807)
+++ modules/jpos/src/org/jpos/iso/channel/LoopbackChannel.java	(working
copy)
 <at>  <at>  -93,6 +93,18  <at>  <at> 
         notifyObservers();
         Logger.log (evt);
     }
+
+    public void send (byte[] b)
+    throws IOException,ISOException, VetoException
+{
+    if (!isConnected())
+        throw new ISOException ("unconnected ISOChannel");
+    LogEvent evt = new LogEvent (this, "loopback-send", b);
+    queue.enqueue (b);
+    cnt[TX]++;
+    notifyObservers();
+    Logger.log (evt);
+}

     public ISOMsg receive() throws IOException, ISOException
     {
Index: modules/jpos/src/org/jpos/iso/ISOChannel.java
===================================================================
--- modules/jpos/src/org/jpos/iso/ISOChannel.java	(revision 2807)
+++ modules/jpos/src/org/jpos/iso/ISOChannel.java	(working copy)
 <at>  <at>  -77,6 +77,14  <at>  <at> 
      *  <at> exception ISOException
      */
     public void send (ISOMsg m) throws IOException, ISOException;
+
+    /**
+     * sends a byte[] over the TCP/IP session
+     *  <at> param b the byte array to be sent
+     *  <at> exception IOException
+     *  <at> exception ISOException
+     */
+    public void send (byte[] b) throws IOException, ISOException;

     /**
      *  <at> param b - usable state
Index: modules/jpos/src/org/jpos/iso/BaseChannel.java
===================================================================
--- modules/jpos/src/org/jpos/iso/BaseChannel.java	(revision 2814)
+++ modules/jpos/src/org/jpos/iso/BaseChannel.java	(working copy)
 <at>  <at>  -553,6 +553,33  <at>  <at> 
         }
     }
     /**
+     * sends a byte[] over the TCP/IP session
+     *  <at> param b the byte array to be sent
+     *  <at> exception IOException
+     *  <at> exception ISOException
+     *  <at> exception ISOFilter.VetoException;
+     */
+    public void send (byte[] b)
+        throws IOException, ISOException
+    {
+        LogEvent evt = new LogEvent (this, "send");
+        try {
+            if (!isConnected())
+                throw new ISOException ("unconnected ISOChannel");
+            synchronized (serverOutLock) {
+                serverOut.write(b);
+                serverOut.flush();
+            }
+            cnt[TX]++;
+            setChanged();
+        } catch (Exception e) {
+            evt.addMessage (e);
+            throw new ISOException ("unexpected exception", e);
+        } finally {
+            Logger.log (evt);
+        }
+    }
+    /**
      * Sends a high-level keep-alive message (zero length)
      *  <at> throws IOException on exception
      */

--

-- 
Mark

------------------------------------


Gmane