KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cluster > queue > ClusterAdmin


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - 2005 ScalAgent Distributed Technologies
4  * Copyright (C) 2004 - France Telecom R&D
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): ScalAgent Distributed Technologies
22  * Contributor(s):
23  */

24 package cluster.queue;
25
26 import org.objectweb.joram.client.jms.admin.*;
27 import org.objectweb.joram.client.jms.*;
28 import org.objectweb.joram.client.jms.tcp.*;
29 import org.objectweb.joram.shared.admin.*;
30 import org.objectweb.joram.client.jms.Queue;
31
32 import java.util.Properties JavaDoc;
33 import java.util.Hashtable JavaDoc;
34
35 /**
36  * Administers three agent servers for the cluster sample.
37  */

38 public class ClusterAdmin {
39   public static void main(String JavaDoc[] args) throws Exception JavaDoc {
40     System.out.println();
41     System.out.println("Cluster administration...");
42
43     AdminModule admin = new AdminModule();
44     admin.connect("root", "root", 60);
45
46     Properties JavaDoc prop = new Properties JavaDoc();
47     prop.setProperty("period","100");
48     prop.setProperty("producThreshold","25");
49     prop.setProperty("consumThreshold","2");
50     prop.setProperty("autoEvalThreshold","true");
51     prop.setProperty("waitAfterClusterReq","100");
52
53 // prop.setProperty("period",args[0]);
54
// prop.setProperty("producThreshold",args[1]);
55
// prop.setProperty("consumThreshold",args[2]);
56
// prop.setProperty("autoEvalThreshold",args[3]);
57
// prop.setProperty("waitAfterClusterReq",args[4]);
58

59     String JavaDoc ClusterQueueCN = "org.objectweb.joram.mom.dest.ClusterQueue";
60
61     Queue queue0 = Queue.create(0, null, ClusterQueueCN, prop);
62     Queue queue1 = Queue.create(1, null, ClusterQueueCN, prop);
63     Queue queue2 = Queue.create(2, null, ClusterQueueCN, prop);
64     
65     System.out.println("queue0 = " + queue0);
66     System.out.println("queue1 = " + queue1);
67     System.out.println("queue2 = " + queue1);
68
69     User user0 = User.create("user0", "user0", 0);
70     User user1 = User.create("user1", "user1", 1);
71     User user2 = User.create("user2", "user2", 2);
72
73     javax.jms.QueueConnectionFactory JavaDoc cf0 =
74       QueueTcpConnectionFactory.create("localhost", 16010);
75     javax.jms.QueueConnectionFactory JavaDoc cf1 =
76       QueueTcpConnectionFactory.create("localhost", 16011);
77     javax.jms.QueueConnectionFactory JavaDoc cf2 =
78       QueueTcpConnectionFactory.create("localhost", 16012);
79
80     AdminHelper.setQueueCluster(queue0,queue1);
81     AdminHelper.setQueueCluster(queue0,queue2);
82     
83     queue0.addClusteredQueue(queue1);
84     queue0.addClusteredQueue(queue2);
85     
86     Hashtable JavaDoc h = new Hashtable JavaDoc();
87     h.put("0",queue0);
88     h.put("1",queue1);
89     h.put("2",queue2);
90
91     ClusterQueue clusterQueue = new ClusterQueue(h);
92     System.out.println("clusterQueue = " + clusterQueue);
93
94     clusterQueue.setReader(user0);
95     clusterQueue.setWriter(user0);
96     clusterQueue.setReader(user1);
97     clusterQueue.setWriter(user1);
98     clusterQueue.setReader(user2);
99     clusterQueue.setWriter(user2);
100
101     javax.naming.Context JavaDoc jndiCtx = new javax.naming.InitialContext JavaDoc();
102     jndiCtx.bind("qcf0", cf0);
103     jndiCtx.bind("qcf1", cf1);
104     jndiCtx.bind("qcf2", cf2);
105     jndiCtx.bind("clusterQueue", clusterQueue);
106     jndiCtx.bind("queue0", queue0);
107     jndiCtx.bind("queue1", queue1);
108     jndiCtx.bind("queue2", queue2);
109     jndiCtx.close();
110
111     admin.disconnect();
112
113     javax.naming.InitialContext JavaDoc jndiCtx2 = new javax.naming.InitialContext JavaDoc();
114     clusterQueue = (ClusterQueue) jndiCtx2.lookup("clusterQueue");
115     System.out.println("clusterQueue = " + clusterQueue);
116     jndiCtx2.close();
117
118     System.out.println("Admins closed.");
119   }
120 }
121
Popular Tags