KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > client > RPCClientTestImpl


1 /*
2  * Timer: The timer class
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * RPCClientTestImpl.java
20  */

21
22 package test.client;
23
24 import com.rift.coad.daemon.messageservice.Message;
25 import com.rift.coad.daemon.messageservice.MessageProducer;
26 import com.rift.coad.daemon.messageservice.MessageServiceException;
27 import com.rift.coad.daemon.messageservice.Producer;
28 import com.rift.coad.daemon.messageservice.TextMessage;
29 import java.rmi.Remote JavaDoc;
30 import java.rmi.RemoteException JavaDoc;
31 import java.util.Date JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Set JavaDoc;
34 import com.rift.coad.daemon.messageservice.rpc.RPCMessageClient;
35 import javax.naming.Context JavaDoc;
36 import javax.naming.InitialContext JavaDoc;
37 import javax.naming.NamingException JavaDoc;
38 import javax.rmi.PortableRemoteObject JavaDoc;
39 import test.server.RPCServerTest;
40
41 public class RPCClientTestImpl implements RPCClientTest {
42     
43     public String JavaDoc testID = "";
44     
45     public RPCClientTestImpl() {
46     }
47     
48     public void runBasicTest(String JavaDoc testString) throws RemoteException JavaDoc,
49             MessageTestException {
50         try {
51             System.out.println("The runtime class");
52             RPCServerTestAsync async = (RPCServerTestAsync)RPCMessageClient.create(
53                     "RPCClientTest",RPCServerTest .class,
54                     RPCServerTestAsync.class,"RPCServerTest");
55             
56             testID = async.testMethod(testString);
57             System.out.println("End of method : " + testID);
58         } catch (Throwable JavaDoc ex) {
59             System.out.println("The test run failed : " +
60                     ex.getMessage());
61             ex.printStackTrace(System.out);
62             throw new MessageTestException("The test run failed : " +
63                     ex.getMessage(),ex);
64         }
65     }
66     
67     public synchronized void onSuccess(String JavaDoc messageId, String JavaDoc correllationId,
68             Object JavaDoc result) throws RemoteException JavaDoc {
69         
70         if (messageId == testID) {
71             System.out.println("ID: " + result.toString());
72         }
73         
74     }
75     
76     public synchronized void onFailure(String JavaDoc messageId, String JavaDoc correllationId,
77             Throwable JavaDoc caught) throws RemoteException JavaDoc {
78         
79         System.out.println("The exception is not a message test " +
80                 "exception : " + caught.getClass().getName());
81         
82     }
83     
84     public void runBasicMessageTest(String JavaDoc testString) throws RemoteException JavaDoc,
85             MessageTestException {
86         System.out.println("The beginning of the start test method");
87         Context JavaDoc context;
88         try {
89             context = new InitialContext JavaDoc();
90             MessageProducer messageProducer =
91                     (MessageProducer)PortableRemoteObject.narrow(
92                     context.lookup(MessageProducer.JNDI_URL),
93                     MessageProducer.class);
94             Producer producer = messageProducer.createProducer("RPCClientTest");
95             TextMessage textMessage = producer.createTextMessage(
96                     Message.POINT_TO_POINT);
97             textMessage.setTarget("TextServerTest");
98             textMessage.setReply(true);
99             textMessage.setTextBody(testString);
100             producer.submit(textMessage);
101         } catch (Exception JavaDoc ex) {
102             throw new MessageTestException("Text message failure:",ex);
103         }
104     }
105     
106     public Message processMessage(Message message) throws RemoteException JavaDoc,
107             MessageServiceException {
108         TextMessage textMessage = (TextMessage) message;
109         System.out.println("Message is : " + textMessage.getTextBody());
110         textMessage.acknowledge();
111         return textMessage;
112     }
113 }
Popular Tags