1 package hero.util; 2 3 31 32 import java.net.MalformedURLException ; 33 import java.net.URI ; 34 import java.util.List ; 35 import java.util.Properties ; 36 37 import javax.management.MBeanServer ; 38 import javax.management.MBeanServerConnection ; 39 import javax.management.MBeanServerFactory ; 40 import javax.management.ObjectName ; 41 import javax.management.remote.JMXConnector ; 42 import javax.management.remote.JMXConnectorFactory ; 43 import javax.management.remote.JMXServiceURL ; 44 import javax.naming.Context ; 45 46 import org.objectweb.carol.util.configuration.CarolCurrentConfiguration; 47 48 public class BonitaConfigClient { 49 50 private ObjectName config; 51 private MBeanServerConnection server; 52 private static BonitaConfigClient bc = null; 55 public BonitaConfigClient() throws HeroException{ 56 try{ 57 CarolCurrentConfiguration carolConfig = CarolCurrentConfiguration.getCurrent(); 58 Properties props = carolConfig.getRMIProperties("jrmp"); 59 String sCarolURL = props.getProperty(Context.PROVIDER_URL); 60 URI carolURL = new URI (sCarolURL); 61 String host= carolURL.getHost(); 62 int portNb = carolURL.getPort(); 63 String port = String.valueOf(portNb); 64 String url = null; 65 66 url = "service:jmx:rmi:///jndi/rmi://"+host+":" + port + "/jrmpconnector_jonas"; 67 JMXServiceURL connURL = null; 69 try { 70 connURL = new JMXServiceURL (url); 71 } catch (MalformedURLException e) { 72 throw new HeroException("Can't create JMXServiceURL with string: " + url); 73 } 74 JMXConnector connector = null; 75 try { 76 connector = JMXConnectorFactory.newJMXConnector(connURL, null); 77 } catch (MalformedURLException e1) { 78 throw new HeroException("there is no provider for the protocol in " + url); 79 } catch (java.io.IOException 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 ioe) { 86 throw new HeroException("connection could not be made because of a communication problem"); 87 } 88 89 config = new ObjectName ("jonas:type=service,name=BonitaConfigService"); 90 } catch (Exception 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 projectName) throws HeroException 103 { 104 try { 105 Boolean value =(Boolean ) server.invoke(config, "getProcessJMS", new Object [] { projectName}, 106 new String [] {"".getClass().getName()}); 107 return value.booleanValue(); 108 } catch (Exception e) { 109 throw new HeroException(e.getMessage()); 110 } 111 } 112 113 public boolean getProcessLog(String projectName) throws HeroException 114 { 115 try { 116 Boolean value =(Boolean ) server.invoke(config, "getProcessLog", new Object [] { projectName}, 117 new String [] {"".getClass().getName()}); 118 return value.booleanValue(); 119 } catch (Exception e) { 120 throw new HeroException(e.getMessage()); 121 } 122 } 123 124 public boolean getProcessTrace(String projectName) throws HeroException 125 { 126 try { 127 Boolean value =(Boolean ) server.invoke(config, "getProcessTrace", new Object [] { projectName}, 128 new String [] {"".getClass().getName()}); 129 return value.booleanValue(); 130 } catch (Exception e) { 131 throw new HeroException(e.getMessage()); 132 } 133 } 134 135 public String getPocessLogLevel(String projectName) throws HeroException 136 { 137 try { 138 String value =(String ) server.invoke(config, "getProcessLogLevel", new Object [] { projectName}, 139 new String [] {"".getClass().getName()}); 140 return value; 141 } catch (Exception e) { 142 throw new HeroException(e.getMessage()); 143 } 144 } 145 146 public String getPocessTraceLevel(String projectName) throws HeroException 147 { 148 try { 149 String value =(String ) server.invoke(config, "getProcessTraceLevel", new Object [] { projectName}, 150 new String [] {"".getClass().getName()}); 151 return value; 152 } catch (Exception e) { 153 throw new HeroException(e.getMessage()); 154 } 155 } 156 157 public String getPocessHistoric(String projectName) throws HeroException 158 { 159 try { 160 String value =(String ) server.invoke(config, "getProcessHistoric", new Object [] { projectName}, 161 new String [] {"".getClass().getName()}); 162 return value; 163 } catch (Exception e) { 164 throw new HeroException(e.getMessage()); 165 } 166 } 167 168 public void setProcessJMS(String projectName,boolean value) throws HeroException 169 { 170 try { 171 server.invoke(config, "setProcessJMS", new Object [] { projectName,new Boolean (value)}, 172 new String [] {"".getClass().getName(),"boolean"}); 173 } catch (Exception e) { 174 throw new HeroException(e.getMessage()); 175 } 176 } 177 178 public void setProcessLog(String projectName,boolean value) throws HeroException 179 { 180 try { 181 server.invoke(config, "setProcessLog", new Object [] { projectName,new Boolean (value)}, 182 new String [] {"".getClass().getName(),"boolean"}); 183 } catch (Exception e) { 184 throw new HeroException(e.getMessage()); 185 } 186 } 187 188 public void setProcessTrace(String projectName,boolean value) throws HeroException 189 { 190 try { 191 server.invoke(config, "setProcessTrace", new Object [] { projectName,new Boolean (value)}, 192 new String [] {"".getClass().getName(),"boolean"}); 193 } catch (Exception e) { 194 throw new HeroException(e.getMessage()); 195 } 196 } 197 198 public void setProcessTraceLevel(String projectName,String value) throws HeroException 199 { 200 try { 201 server.invoke(config, "setProcessTraceLevel", new Object [] { projectName,value}, 202 new String [] {"".getClass().getName(),"".getClass().getName()}); 203 } catch (Exception e) { 204 throw new HeroException(e.getMessage()); 205 } 206 } 207 208 public void setProcessLogLevel(String projectName,String value) throws HeroException 209 { 210 try { 211 server.invoke(config, "setProcessLogLevel", new Object [] { projectName,value}, 212 new String [] {"".getClass().getName(),"".getClass().getName()}); 213 } catch (Exception e) { 214 throw new HeroException(e.getMessage()); 215 } 216 } 217 218 public void setPocessHistoric(String projectName,String value) throws HeroException 219 { 220 try { 221 server.invoke(config, "setProcessHistoric", new Object [] { projectName,value}, 222 new String [] {"".getClass().getName(),"".getClass().getName()}); 223 } catch (Exception 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 [] {new Boolean (jms)},new String [] {"boolean"}); 233 } catch (Exception 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 [] {new Boolean (log)},new String [] {"boolean"}); 242 } catch (Exception 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 [] {new Boolean (trace)},new String [] {"boolean"}); 251 } catch (Exception e) { 252 throw new HeroException(e.getMessage()); 253 } 254 } 255 256 public void updateLogLevel(String value) throws HeroException 257 { 258 try { 259 server.invoke(config, "updateLogLevel", new Object [] { value},new String [] {"".getClass().getName()}); 260 } catch (Exception e) { 261 throw new HeroException(e.getMessage()); 262 } 263 } 264 265 public void updateTraceLevel(String value) throws HeroException 266 { 267 try { 268 server.invoke(config, "updateTraceLevel", new Object [] { value},new String [] {"".getClass().getName()}); 269 } catch (Exception e) { 270 throw new HeroException(e.getMessage()); 271 } 272 } 273 274 public void updateHistoric(String value) throws HeroException 275 { 276 try { 277 server.invoke(config, "updateHistoric", new Object [] { value},new String [] {"".getClass().getName()}); 278 } catch (Exception e) { 279 throw new HeroException(e.getMessage()); 280 } 281 } 282 283 } | Popular Tags |