1 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 ; 30 import java.rmi.RemoteException ; 31 import java.util.Date ; 32 import java.util.HashSet ; 33 import java.util.Set ; 34 import com.rift.coad.daemon.messageservice.rpc.RPCMessageClient; 35 import javax.naming.Context ; 36 import javax.naming.InitialContext ; 37 import javax.naming.NamingException ; 38 import javax.rmi.PortableRemoteObject ; 39 import test.server.RPCServerTest; 40 41 public class RPCClientTestImpl implements RPCClientTest { 42 43 public String testID = ""; 44 45 public RPCClientTestImpl() { 46 } 47 48 public void runBasicTest(String testString) throws RemoteException , 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 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 messageId, String correllationId, 68 Object result) throws RemoteException { 69 70 if (messageId == testID) { 71 System.out.println("ID: " + result.toString()); 72 } 73 74 } 75 76 public synchronized void onFailure(String messageId, String correllationId, 77 Throwable caught) throws RemoteException { 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 testString) throws RemoteException , 85 MessageTestException { 86 System.out.println("The beginning of the start test method"); 87 Context context; 88 try { 89 context = new InitialContext (); 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 ex) { 102 throw new MessageTestException("Text message failure:",ex); 103 } 104 } 105 106 public Message processMessage(Message message) throws RemoteException , 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 |