KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > client > named > NamedClientImpl


1 /*
2  * MessageTest: This is a test message service library.
3  * Copyright (C) 2007 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  * NamedClient1Impl.java
20  */

21
22 package test.client.named;
23
24 // java imports
25
import java.util.Date JavaDoc;
26 import javax.naming.Context JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28 import javax.naming.NamingException JavaDoc;
29 import javax.rmi.PortableRemoteObject JavaDoc;
30
31 // coadunation imports
32
import com.rift.coad.daemon.messageservice.MessageService;
33 import com.rift.coad.daemon.messageservice.MessageServiceException;
34 import com.rift.coad.daemon.messageservice.Message;
35 import com.rift.coad.daemon.messageservice.MessageProducer;
36 import com.rift.coad.daemon.messageservice.Producer;
37 import com.rift.coad.daemon.messageservice.TextMessage;
38
39 /**
40  * This object is responsible for implementing named client interface.
41  *
42  * @author Brett Chaldecott
43  */

44 public class NamedClientImpl implements NamedClient {
45     
46     // private member variables
47
private Context JavaDoc context = null;
48     private int results = 0;
49     
50     /** Creates a new instance of NamedClient1Impl */
51     public NamedClientImpl() throws NamedTestException{
52         try {
53             context = new InitialContext JavaDoc();
54         } catch (Exception JavaDoc ex) {
55             throw new NamedTestException("Failed to instanciate the named test " +
56                     "client : " + ex.getMessage(),ex);
57         }
58     }
59     
60     
61     /**
62      * This method is called to run a basic named message test.
63      *
64      * @param numMessages The number of messages to test the queues with.
65      * @exception MessageTestException
66      */

67     public void runBasicTest(String JavaDoc text) throws NamedTestException {
68         System.out.println("The beginning of the start test method");
69         MessageProducer messageProducer;
70         try {
71             messageProducer = (MessageProducer) PortableRemoteObject.
72                     narrow(context.lookup(MessageProducer.JNDI_URL),
73                     MessageProducer.class);
74             
75             Producer producer = messageProducer.createProducer(JNDI_URL);
76             TextMessage textMessage = producer.createTextMessage(
77                     Message.POINT_TO_POINT);
78             textMessage.setTarget(MessageService.JNDI_URL);
79             textMessage.setTargetNamedQueue("test");
80             textMessage.setReply(false);
81             textMessage.setTextBody(text);
82             producer.submit(textMessage);
83             
84             System.out.println("After result");
85         } catch (Exception JavaDoc ex) {
86             throw new NamedTestException("The test failed:", ex);
87         }
88     }
89     
90 }
91
Popular Tags