1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
40
41
42
43
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 }