KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > connector > LocalServer


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2004 - Bull SA
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): Frederic Maistre (Bull SA)
21  * Contributor(s): Nicolas Tachker (Bull SA)
22  */

23 package org.objectweb.joram.client.connector;
24
25 import org.objectweb.joram.client.jms.ConnectionMetaData;
26 import org.objectweb.joram.client.jms.Destination;
27 import org.objectweb.joram.client.jms.Queue;
28 import org.objectweb.joram.client.jms.Topic;
29 import org.objectweb.joram.client.jms.admin.AdminModule;
30 import org.objectweb.joram.client.jms.admin.User;
31
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34 import java.util.Vector JavaDoc;
35
36
37 /**
38  * The <code>LocalServer</code> class allows to manage the adapter's
39  * underlying server.
40  */

41 public class LocalServer implements LocalServerMBean
42 {
43   /** The wrapped adapter instance. */
44   private JoramAdapter adapter;
45   
46   private String JavaDoc objectName;
47   private boolean eventProvider = false;
48   private boolean stateManageable = false;
49   private boolean statisticsProvider = false;
50
51   /** Constructs a <code>LocalServer</code> instance. */
52   public LocalServer(JoramAdapter adapter) {
53     this.adapter = adapter;
54   }
55
56   public void setObjectName(String JavaDoc objectName) {
57     this.objectName = objectName;
58   }
59
60   public void setStateManageable(boolean stateManageable) {
61     this.stateManageable = stateManageable;
62   }
63
64   public void setStatisticsProvider(boolean statisticsProvider) {
65     this.statisticsProvider = statisticsProvider;
66   }
67
68   public void setEventProvider(boolean eventProvider) {
69     this.eventProvider = eventProvider;
70   }
71
72   public String JavaDoc getobjectName() {
73     return objectName;
74   }
75
76   public boolean iseventProvider() {
77     return eventProvider;
78   }
79
80   public boolean isstateManageable() {
81     return stateManageable;
82   }
83
84   public boolean isstatisticsProvider() {
85     return statisticsProvider;
86   }
87
88   public String JavaDoc getPlatformConfiguration()
89   {
90     if (adapter.platformServersIds != null
91         && adapter.platformServersIds.size() > 1)
92       return "Distributed";
93     else
94       return "Centralized";
95   }
96
97   public List JavaDoc getPlatformServersIds()
98   {
99     return adapter.platformServersIds;
100   }
101
102   public String JavaDoc getLocalServerId()
103   {
104     return "" + adapter.serverId;
105   }
106
107   public String JavaDoc getRelease()
108   {
109     return ConnectionMetaData.providerVersion;
110   }
111
112   public String JavaDoc getRunningMode()
113   {
114     if (adapter.getCollocatedServer().booleanValue())
115       return "Collocated";
116     return "Remote";
117   }
118
119   public String JavaDoc getHost()
120   {
121     return adapter.hostName;
122   }
123
124   public String JavaDoc getPort()
125   {
126     return "" + adapter.serverPort;
127   }
128
129   public List JavaDoc getLocalQueuesNames()
130   {
131     try {
132       List JavaDoc list = AdminModule.getDestinations();
133       Iterator JavaDoc it = list.iterator();
134       Destination dest;
135       Vector JavaDoc names = new Vector JavaDoc();
136       while (it.hasNext()) {
137         dest = (Destination) it.next();
138         if (dest instanceof Queue)
139           names.add(dest.getAdminName());
140       }
141       return names;
142     }
143     catch (Exception JavaDoc exc) {
144       return new Vector JavaDoc();
145     }
146   }
147
148   public List JavaDoc getLocalTopicsNames()
149   {
150     try {
151       List JavaDoc list = AdminModule.getDestinations();
152       Iterator JavaDoc it = list.iterator();
153       Destination dest;
154       Vector JavaDoc names = new Vector JavaDoc();
155       while (it.hasNext()) {
156         dest = (Destination) it.next();
157         if (dest instanceof Topic)
158           names.add(dest.getAdminName());
159       }
160       return names;
161     }
162     catch (Exception JavaDoc exc) {
163       return new Vector JavaDoc();
164     }
165   }
166
167   public List JavaDoc getLocalUsersNames()
168   {
169     try {
170       List JavaDoc list = AdminModule.getUsers();
171       Iterator JavaDoc it = list.iterator();
172       User user;
173       Vector JavaDoc names = new Vector JavaDoc();
174       while (it.hasNext()) {
175         user = (User) it.next();
176         names.add(user.getName());
177       }
178       return names;
179     }
180     catch (Exception JavaDoc exc) {
181       return new Vector JavaDoc();
182     }
183   }
184
185
186   public void createLocalQueue(String JavaDoc jndiName) throws Exception JavaDoc
187   {
188     JoramAdapter.createQueue(jndiName);
189   }
190
191   public void createLocalTopic(String JavaDoc jndiName) throws Exception JavaDoc
192   {
193     JoramAdapter.createTopic(jndiName);
194   }
195 }
196
Popular Tags