KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > util > BonitaConfigClient


1 package hero.util;
2
3 /**
4 *
5 * Bonita
6 * Copyright (C) 1999 Bull S.A.
7 * Bull 68 route de versailles 78434 Louveciennes Cedex France
8 * Further information: bonita@objectweb.org
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 *
26 --------------------------------------------------------------------------
27 * $Id: BonitaConfigClient.java,v 1.1 2004/11/29 12:29:48 mvaldes Exp $
28 *
29 --------------------------------------------------------------------------
30 */

31
32 import java.net.MalformedURLException JavaDoc;
33 import java.net.URI JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Properties JavaDoc;
36
37 import javax.management.MBeanServer JavaDoc;
38 import javax.management.MBeanServerConnection JavaDoc;
39 import javax.management.MBeanServerFactory JavaDoc;
40 import javax.management.ObjectName JavaDoc;
41 import javax.management.remote.JMXConnector JavaDoc;
42 import javax.management.remote.JMXConnectorFactory JavaDoc;
43 import javax.management.remote.JMXServiceURL JavaDoc;
44 import javax.naming.Context JavaDoc;
45
46 import org.objectweb.carol.util.configuration.CarolCurrentConfiguration;
47
48 public class BonitaConfigClient {
49     
50     private ObjectName JavaDoc config;
51     private MBeanServerConnection JavaDoc server;
52     //private MBeanServer server;
53
private static BonitaConfigClient bc = null; // Singleton pattern
54

55     public BonitaConfigClient() throws HeroException{
56         try{
57             CarolCurrentConfiguration carolConfig = CarolCurrentConfiguration.getCurrent();
58             Properties JavaDoc props = carolConfig.getRMIProperties("jrmp");
59             String JavaDoc sCarolURL = props.getProperty(Context.PROVIDER_URL);
60             URI JavaDoc carolURL = new URI JavaDoc(sCarolURL);
61             String JavaDoc host= carolURL.getHost();
62             int portNb = carolURL.getPort();
63             String JavaDoc port = String.valueOf(portNb);
64             String JavaDoc url = null;
65             
66             url = "service:jmx:rmi:///jndi/rmi://"+host+":" + port + "/jrmpconnector_jonas";
67             // Try to connect to the MBeanServer
68
JMXServiceURL JavaDoc connURL = null;
69             try {
70                 connURL = new JMXServiceURL JavaDoc(url);
71             } catch (MalformedURLException JavaDoc e) {
72                 throw new HeroException("Can't create JMXServiceURL with string: " + url);
73             }
74             JMXConnector JavaDoc connector = null;
75             try {
76                 connector = JMXConnectorFactory.newJMXConnector(connURL, null);
77             } catch (MalformedURLException JavaDoc e1) {
78                 throw new HeroException("there is no provider for the protocol in " + url);
79             } catch (java.io.IOException JavaDoc e) {
80                 throw new HeroException("Connector client cannot be made because of a communication problem (used URL: " + url + ")");
81             }
82             try {
83                 connector.connect(null);
84                 server = connector.getMBeanServerConnection();
85             } catch (java.io.IOException JavaDoc ioe) {
86                 throw new HeroException("connection could not be made because of a communication problem");
87             }
88             
89             config = new ObjectName JavaDoc("jonas:type=service,name=BonitaConfigService");
90         } catch (Exception JavaDoc e) {e.printStackTrace();
91         throw new HeroException(e.getMessage());
92         }
93     }
94     
95     public static BonitaConfigClient getInstance() throws HeroException{
96         if ( bc == null) {
97             bc = new BonitaConfigClient();
98         }
99         return bc;
100     }
101         
102     public boolean getProcessJMS(String JavaDoc projectName) throws HeroException
103     {
104         try {
105             Boolean JavaDoc value =(Boolean JavaDoc) server.invoke(config, "getProcessJMS", new Object JavaDoc[] { projectName},
106                     new String JavaDoc[] {"".getClass().getName()});
107             return value.booleanValue();
108         } catch (Exception JavaDoc e) {
109             throw new HeroException(e.getMessage());
110         }
111     }
112     
113     public boolean getProcessLog(String JavaDoc projectName) throws HeroException
114     {
115         try {
116             Boolean JavaDoc value =(Boolean JavaDoc) server.invoke(config, "getProcessLog", new Object JavaDoc[] { projectName},
117                     new String JavaDoc[] {"".getClass().getName()});
118             return value.booleanValue();
119         } catch (Exception JavaDoc e) {
120             throw new HeroException(e.getMessage());
121         }
122     }
123     
124     public boolean getProcessTrace(String JavaDoc projectName) throws HeroException
125     {
126         try {
127             Boolean JavaDoc value =(Boolean JavaDoc) server.invoke(config, "getProcessTrace", new Object JavaDoc[] { projectName},
128                     new String JavaDoc[] {"".getClass().getName()});
129             return value.booleanValue();
130         } catch (Exception JavaDoc e) {
131             throw new HeroException(e.getMessage());
132         }
133     }
134     
135     public String JavaDoc getPocessLogLevel(String JavaDoc projectName) throws HeroException
136     {
137         try {
138             String JavaDoc value =(String JavaDoc) server.invoke(config, "getProcessLogLevel", new Object JavaDoc[] { projectName},
139                     new String JavaDoc[] {"".getClass().getName()});
140             return value;
141         } catch (Exception JavaDoc e) {
142             throw new HeroException(e.getMessage());
143         }
144     }
145     
146     public String JavaDoc getPocessTraceLevel(String JavaDoc projectName) throws HeroException
147     {
148         try {
149             String JavaDoc value =(String JavaDoc) server.invoke(config, "getProcessTraceLevel", new Object JavaDoc[] { projectName},
150                     new String JavaDoc[] {"".getClass().getName()});
151             return value;
152         } catch (Exception JavaDoc e) {
153             throw new HeroException(e.getMessage());
154         }
155     }
156     
157     public String JavaDoc getPocessHistoric(String JavaDoc projectName) throws HeroException
158     {
159         try {
160             String JavaDoc value =(String JavaDoc) server.invoke(config, "getProcessHistoric", new Object JavaDoc[] { projectName},
161                     new String JavaDoc[] {"".getClass().getName()});
162             return value;
163         } catch (Exception JavaDoc e) {
164             throw new HeroException(e.getMessage());
165         }
166     }
167
168     public void setProcessJMS(String JavaDoc projectName,boolean value) throws HeroException
169     {
170         try {
171             server.invoke(config, "setProcessJMS", new Object JavaDoc[] { projectName,new Boolean JavaDoc(value)},
172                     new String JavaDoc[] {"".getClass().getName(),"boolean"});
173         } catch (Exception JavaDoc e) {
174             throw new HeroException(e.getMessage());
175         }
176     }
177     
178     public void setProcessLog(String JavaDoc projectName,boolean value) throws HeroException
179     {
180         try {
181             server.invoke(config, "setProcessLog", new Object JavaDoc[] { projectName,new Boolean JavaDoc(value)},
182                     new String JavaDoc[] {"".getClass().getName(),"boolean"});
183         } catch (Exception JavaDoc e) {
184             throw new HeroException(e.getMessage());
185         }
186     }
187     
188     public void setProcessTrace(String JavaDoc projectName,boolean value) throws HeroException
189     {
190         try {
191             server.invoke(config, "setProcessTrace", new Object JavaDoc[] { projectName,new Boolean JavaDoc(value)},
192                     new String JavaDoc[] {"".getClass().getName(),"boolean"});
193         } catch (Exception JavaDoc e) {
194             throw new HeroException(e.getMessage());
195         }
196     }
197     
198     public void setProcessTraceLevel(String JavaDoc projectName,String JavaDoc value) throws HeroException
199     {
200         try {
201             server.invoke(config, "setProcessTraceLevel", new Object JavaDoc[] { projectName,value},
202                     new String JavaDoc[] {"".getClass().getName(),"".getClass().getName()});
203         } catch (Exception JavaDoc e) {
204             throw new HeroException(e.getMessage());
205         }
206     }
207     
208     public void setProcessLogLevel(String JavaDoc projectName,String JavaDoc value) throws HeroException
209     {
210         try {
211             server.invoke(config, "setProcessLogLevel", new Object JavaDoc[] { projectName,value},
212                     new String JavaDoc[] {"".getClass().getName(),"".getClass().getName()});
213         } catch (Exception JavaDoc e) {
214             throw new HeroException(e.getMessage());
215         }
216     }
217     
218     public void setPocessHistoric(String JavaDoc projectName,String JavaDoc value) throws HeroException
219     {
220         try {
221             server.invoke(config, "setProcessHistoric", new Object JavaDoc[] { projectName,value},
222                     new String JavaDoc[] {"".getClass().getName(),"".getClass().getName()});
223         } catch (Exception JavaDoc e) {
224             throw new HeroException(e.getMessage());
225         }
226     }
227     
228     
229     public void updateJMS(boolean jms) throws HeroException
230     {
231         try {
232             server.invoke(config, "updateJMS", new Object JavaDoc[] {new Boolean JavaDoc(jms)},new String JavaDoc[] {"boolean"});
233         } catch (Exception JavaDoc e) {
234             throw new HeroException(e.getMessage());
235         }
236     }
237     
238     public void updateLog(boolean log) throws HeroException
239     {
240         try {
241             server.invoke(config, "updateLog", new Object JavaDoc[] {new Boolean JavaDoc(log)},new String JavaDoc[] {"boolean"});
242         } catch (Exception JavaDoc e) {
243             throw new HeroException(e.getMessage());
244         }
245     }
246     
247     public void updateTrace(boolean trace) throws HeroException
248     {
249         try {
250             server.invoke(config, "updateTrace", new Object JavaDoc[] {new Boolean JavaDoc(trace)},new String JavaDoc[] {"boolean"});
251         } catch (Exception JavaDoc e) {
252             throw new HeroException(e.getMessage());
253         }
254     }
255     
256     public void updateLogLevel(String JavaDoc value) throws HeroException
257     {
258         try {
259             server.invoke(config, "updateLogLevel", new Object JavaDoc[] { value},new String JavaDoc[] {"".getClass().getName()});
260         } catch (Exception JavaDoc e) {
261             throw new HeroException(e.getMessage());
262         }
263     }
264     
265     public void updateTraceLevel(String JavaDoc value) throws HeroException
266     {
267         try {
268             server.invoke(config, "updateTraceLevel", new Object JavaDoc[] { value},new String JavaDoc[] {"".getClass().getName()});
269         } catch (Exception JavaDoc e) {
270             throw new HeroException(e.getMessage());
271         }
272     }
273     
274     public void updateHistoric(String JavaDoc value) throws HeroException
275     {
276         try {
277             server.invoke(config, "updateHistoric", new Object JavaDoc[] { value},new String JavaDoc[] {"".getClass().getName()});
278         } catch (Exception JavaDoc e) {
279             throw new HeroException(e.getMessage());
280         }
281     }
282     
283 }
Popular Tags