KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > KProducer


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA.
19  *
20  * Initial developer(s): Nicolas Tachker (ScalAgent)
21  * Contributor(s):
22  */

23 import javax.microedition.midlet.*;
24 import javax.microedition.lcdui.*;
25 import javax.microedition.io.*;
26
27 import com.scalagent.kjoram.*;
28 import com.scalagent.kjndi.ksoap.*;
29
30 /**
31  *
32  */

33 public class KProducer extends MIDlet {
34   
35   protected void startApp() throws MIDletStateChangeException {
36     System.out.println();
37     System.out.println("Produces messages on the queue and on the topic...");
38
39     try {
40       SoapNamingContext ictx = new SoapNamingContext("X.X.X.X",8080);
41       ConnectionFactory cf =
42         new com.scalagent.kjoram.ksoap.SoapConnectionFactory(
43           "X.X.X.X", 8080, 360000);
44       Queue queue = (Queue) ictx.lookup("queue");
45       Topic topic = (Topic) ictx.lookup("topic");
46       
47       com.scalagent.kjoram.Connection cnx = cf.createConnection();
48       //Session sess = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
49
Session sess = cnx.createSession(true, 0);
50       
51       MessageProducer producer = sess.createProducer(null);
52       
53       TextMessage msg = sess.createTextMessage();
54       
55       for (int i = 1; i < 2; i++) {
56         msg.setText("kJORAM test " + i);
57         producer.send(queue, msg);
58         producer.send(topic, msg);
59       }
60       
61       sess.commit();
62       cnx.close();
63     } catch (Exception JavaDoc exc) {
64       System.out.println("////////// EXCEPTION " + exc);
65     }
66   }
67
68   protected void pauseApp() {
69   }
70
71   protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
72   }
73 }
74
Popular Tags