KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bridge > BridgeAdmin


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2007 - ScalAgent DT
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 package bridge;
24
25 import org.objectweb.joram.client.jms.admin.*;
26 import org.objectweb.joram.client.jms.*;
27 import org.objectweb.joram.client.jms.tcp.*;
28
29 import java.util.Properties JavaDoc;
30
31
32 /**
33  * Administers an agent server for the bridge sample.
34  */

35 public class BridgeAdmin {
36   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
37     System.out.println();
38     System.out.println("Bridge administration...");
39
40     AdminModule.connect("root", "root", 60);
41     javax.naming.Context JavaDoc jndiCtx = new javax.naming.InitialContext JavaDoc();
42     
43     // create The foreign destination and connectionFactory
44
Queue foreignQueue = Queue.create(1, "foreignQueue");
45     foreignQueue.setFreeReading();
46     foreignQueue.setFreeWriting();
47     System.out.println("foreign queue = " + foreignQueue);
48     
49     Topic foreignTopic = Topic.create(1, "foreignTopic");
50     foreignTopic.setFreeReading();
51     foreignTopic.setFreeWriting();
52     System.out.println("foreign topic = " + foreignTopic);
53     
54     javax.jms.ConnectionFactory JavaDoc foreignCF = TcpConnectionFactory.create("localhost", 16011);
55     
56     // bind foreign destination and connectionFactory
57
jndiCtx.rebind("foreignQueue", foreignQueue);
58     jndiCtx.rebind("foreignTopic", foreignTopic);
59     jndiCtx.rebind("foreignCF", foreignCF);
60     
61     
62     // Setting the bridge properties
63
Properties JavaDoc prop = new Properties JavaDoc();
64     // Foreign QueueConnectionFactory JNDI name: foreignCF
65
prop.setProperty("connectionFactoryName", "foreignCF");
66     // Foreign Queue JNDI name: foreignDest
67
prop.setProperty("destinationName", "foreignQueue");
68     // automaticRequest
69
prop.setProperty("automaticRequest", "false");
70
71     // Creating a Queue bridge on server 0:
72
Queue joramQueue = Queue.create(0,
73                                  "org.objectweb.joram.mom.dest.bridge.BridgeQueue",
74                                  prop);
75     joramQueue.setFreeReading();
76     joramQueue.setFreeWriting();
77     System.out.println("joram queue = " + joramQueue);
78     
79     // Setting the bridge properties
80
prop = new Properties JavaDoc();
81     // Foreign QueueConnectionFactory JNDI name: foreignCF
82
prop.setProperty("connectionFactoryName", "foreignCF");
83     // Foreign Queue JNDI name: foreignDest
84
prop.setProperty("destinationName", "foreignTopic");
85     
86     // Creating a Topic bridge on server 0:
87
Topic joramTopic = Topic.create(0,
88                                  "org.objectweb.joram.mom.dest.bridge.BridgeTopic",
89                                  prop);
90     joramTopic.setFreeReading();
91     joramTopic.setFreeWriting();
92     System.out.println("joram topic = " + joramTopic);
93
94     javax.jms.ConnectionFactory JavaDoc joramCF = TcpConnectionFactory.create();
95
96     User.create("anonymous", "anonymous", 0);
97     User.create("anonymous", "anonymous", 1);
98
99     jndiCtx.rebind("joramQueue", joramQueue);
100     jndiCtx.rebind("joramTopic", joramTopic);
101     jndiCtx.rebind("joramCF", joramCF);
102     
103     jndiCtx.close();
104
105     AdminModule.disconnect();
106     System.out.println("Admin closed.");
107   }
108 }
109
Popular Tags