KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cluster > queue > ClusterAdminAdd


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - France Telecom R&D
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 cluster.queue;
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 import org.objectweb.joram.shared.admin.*;
29 import org.objectweb.joram.client.jms.Queue;
30
31 import java.util.Properties JavaDoc;
32 import java.util.Hashtable JavaDoc;
33
34 /**
35  * Administers three agent servers for the cluster sample.
36  */

37 public class ClusterAdminAdd
38 {
39   public static void main(String JavaDoc[] args) throws Exception JavaDoc
40   {
41     System.out.println();
42     System.out.println("Cluster administration Add ...");
43
44     javax.naming.Context JavaDoc jndiCtx = new javax.naming.InitialContext JavaDoc();
45     
46     Properties JavaDoc prop = new Properties JavaDoc();
47     prop.setProperty("period",args[0]);
48     prop.setProperty("producThreshold",args[1]);
49     prop.setProperty("consumThreshold",args[2]);
50     prop.setProperty("autoEvalThreshold",args[3]);
51     prop.setProperty("waitAfterClusterReq",args[4]);
52     System.out.println("prop = " + prop);
53
54     String JavaDoc sid = args[5];
55     int id = new Integer JavaDoc(sid).intValue();
56     String JavaDoc host = args[6];
57     int port = new Integer JavaDoc(args[7]).intValue();
58
59     AdminModule admin = new AdminModule();
60     admin.connect(host,port,"root", "root", 60);
61
62     Queue queue = Queue.create(
63       id,
64       null,
65       "org.objectweb.joram.mom.dest.ClusterQueue",
66       prop);
67     
68     System.out.println("queue = " + queue);
69
70     User user = User.create("user"+sid, "user"+sid, id);
71
72
73     javax.jms.QueueConnectionFactory JavaDoc cf =
74       QueueTcpConnectionFactory.create("localhost", 16010+id);
75
76     ClusterQueue cluster = (ClusterQueue) jndiCtx.lookup("clusterQueue");
77
78     AdminHelper.setQueueCluster(cluster,queue);
79
80     Hashtable JavaDoc h = cluster.getCluster();
81     h.put(sid,queue);
82
83     ClusterQueue clusterQueue = new ClusterQueue(h);
84     System.out.println("clusterQueue = " + clusterQueue);
85
86     clusterQueue.setReader(user);
87     clusterQueue.setWriter(user);
88
89
90     jndiCtx.bind("qcf"+sid, cf);
91     jndiCtx.rebind("clusterQueue",clusterQueue);
92     jndiCtx.bind("queue"+sid, queue);
93     jndiCtx.close();
94
95     admin.disconnect();
96     System.out.println("Admins closed.");
97   }
98 }
99
Popular Tags