1    //
2    // SwitchRMI  Framework
3    // Copyright (c) 2000-2002 by Michael J. Henderson & Associates.
4    //
5    // Michael Henderson
6    // http://switchrmi.sf.net
7    // mailto:mikehenderson@dunelm.org.uk
8    //
9    // This library is free software.
10   //
11   // You may redistribute it and/or modify it under the terms of the GNU
12   // Lesser General Public License as published by the Free Software Foundation.
13   //
14   // Version 2.1 of the license should be included with this distribution in
15   // the file LICENSE, as well as License.html. If the license is not
16   // included with this distribution, you may find a copy at the FSF web
17   // site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
18   // Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
19   //
20   // This library is distributed in the hope that it will be useful,
21   // but WITHOUT ANY WARRANTY; without even the implied waranty of
22   // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23   // Lesser General Public License for more details.
24   //
25   // $Id: TestTransport.java,v 1.1 2002/11/11 22:19:48 mikehenderson Exp $
26   package com.mjh.switchrmi.transport.test;
27   
28   import com.mjh.switchrmi.*;
29   
30   import java.io.ByteArrayInputStream;
31   import java.io.ByteArrayOutputStream;
32   import java.io.IOException;
33   import java.io.InputStream;
34   import java.io.OutputStream;
35   
36   import org.apache.log4j.Logger;
37   
38   //
39   // call getOutputStream from client code to write the request
40   // call getInputStream from service side to read the request;
41   // -- here trigger the rpchandler lookup and invocation of the method
42   // call getOutputStream to write out the response
43   // call getInputStream on client side to read the
44   // 
45   //
46   //
47   //
48   public class TestTransport extends RmiTransportBase
49   {
50       private static final Logger log = 
51               Logger.getLogger(TestTransport.class.getName());
52       private ByteArrayOutputStream out;
53       private ByteArrayInputStream in;
54       private int sendCount = 0;
55   
56       public TestTransport()
57       {
58           super.setType(RmiTransport.SYNCHRONOUS);
59           super.setName("test");
60       }
61   
62       public void send(RmiContext context)
63                 throws Exception
64       {
65           sendCount++;
66   
67           if ((sendCount % 2) == 1)
68           {
69               try
70               {
71                   RmiHandler handler = new RmiHandler();
72   
73                   handler.serviceInvoke(context, null);
74               }
75               catch (Exception ex)
76               {
77                   log.debug("send()", ex);
78               }
79           }
80       }
81   
82       public InputStream getInputStream(RmiContext context)
83           throws IOException
84       {
85           in = new ByteArrayInputStream(out.toByteArray());
86   
87           return in;
88       }
89   
90       public OutputStream getOutputStream(RmiContext context)
91           throws IOException
92       {
93           out = new ByteArrayOutputStream();
94   
95           return out;
96       }
97   
98       private void invoke()
99       {
100      }
101  }