00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 package org.objectweb.proactive.jmx;
00032
00033 import java.io.IOException;
00034 import java.io.Serializable;
00035 import java.util.HashMap;
00036 import java.util.Set;
00037
00038 import javax.management.Attribute;
00039 import javax.management.AttributeList;
00040 import javax.management.AttributeNotFoundException;
00041 import javax.management.InstanceAlreadyExistsException;
00042 import javax.management.InstanceNotFoundException;
00043 import javax.management.IntrospectionException;
00044 import javax.management.InvalidAttributeValueException;
00045 import javax.management.ListenerNotFoundException;
00046 import javax.management.MBeanException;
00047 import javax.management.MBeanInfo;
00048 import javax.management.MBeanRegistrationException;
00049 import javax.management.MBeanServer;
00050 import javax.management.MBeanServerConnection;
00051 import javax.management.NotCompliantMBeanException;
00052 import javax.management.NotificationFilter;
00053 import javax.management.NotificationListener;
00054 import javax.management.ObjectInstance;
00055 import javax.management.ObjectName;
00056 import javax.management.QueryExp;
00057 import javax.management.ReflectionException;
00058
00059 import org.objectweb.proactive.core.util.wrapper.GenericTypeWrapper;
00060 import org.objectweb.proactive.jmx.listeners.ListenerAdapter;
00061
00062
00073 public class ProActiveConnection implements Serializable, MBeanServerConnection {
00074
00078 protected static final long serialVersionUID = 1245L;
00079 private transient MBeanServer mbs;
00080 private HashMap<NotificationListener, ListenerAdapter> listenerMap = new HashMap<NotificationListener, ListenerAdapter>();
00081
00086 public ProActiveConnection() {
00087 }
00088
00093 public ProActiveConnection(MBeanServer server) {
00094 this.mbs = server;
00095 }
00096
00097
00098
00099
00100 public ObjectInstance createMBean(String arg0, ObjectName arg1,
00101 ObjectName arg2)
00102 throws InstanceAlreadyExistsException, MBeanRegistrationException,
00103 NotCompliantMBeanException, InstanceNotFoundException,
00104 ReflectionException, MBeanException {
00105 return this.mbs.createMBean(arg0, arg1, arg2);
00106 }
00107
00108
00109
00110
00111 public ObjectInstance createMBean(String className, ObjectName name,
00112 Object[] params, String[] signature)
00113 throws InstanceAlreadyExistsException, MBeanRegistrationException,
00114 NotCompliantMBeanException, ReflectionException, MBeanException {
00115 return this.mbs.createMBean(className, name, params, signature);
00116 }
00117
00121 public ObjectInstance createMBean(String className, ObjectName name,
00122 ObjectName loaderName, Object[] params, String[] signature)
00123 throws InstanceAlreadyExistsException, MBeanRegistrationException,
00124 NotCompliantMBeanException, InstanceNotFoundException,
00125 ReflectionException, MBeanException {
00126 return this.mbs.createMBean(className, name, loaderName, params,
00127 signature);
00128 }
00129
00130
00131
00132
00133 public void unregisterMBean(ObjectName name)
00134 throws InstanceNotFoundException, MBeanRegistrationException {
00135 this.mbs.unregisterMBean(name);
00136 }
00137
00141 @SuppressWarnings("unused")
00142 public ObjectInstance getObjectInstance(ObjectName name)
00143 throws InstanceNotFoundException, IOException {
00144 return this.mbs.getObjectInstance(name);
00145 }
00146
00150 @SuppressWarnings("unused")
00151 public Set <ObjectInstance> queryMBeans(ObjectName name, QueryExp query)
00152 throws IOException {
00153 return this.mbs.queryMBeans(name, query);
00154 }
00155
00159 @SuppressWarnings("unused")
00160 public Set queryNames(ObjectName name, QueryExp query)
00161 throws IOException {
00162 return this.mbs.queryNames(name, query);
00163 }
00164
00168 @SuppressWarnings("unused")
00169 public boolean isRegistered(ObjectName name) throws IOException {
00170 return this.mbs.isRegistered(name);
00171 }
00172
00176 @SuppressWarnings("unused")
00177 public Integer getMBeanCount() throws IOException {
00178 return this.mbs.getMBeanCount();
00179 }
00180
00184 @SuppressWarnings("unused")
00185 public Object getAttribute(ObjectName name, String attribute)
00186 throws MBeanException, AttributeNotFoundException,
00187 InstanceNotFoundException, ReflectionException, IOException {
00188 return this.mbs.getAttribute(name, attribute);
00189 }
00190
00194 @SuppressWarnings("unused")
00195 public AttributeList getAttributes(ObjectName name, String[] attributes)
00196 throws InstanceNotFoundException, ReflectionException, IOException {
00197 return mbs.getAttributes(name, attributes);
00198 }
00199
00203 @SuppressWarnings("unused")
00204 public void setAttribute(ObjectName name, Attribute attribute)
00205 throws InstanceNotFoundException, AttributeNotFoundException,
00206 InvalidAttributeValueException, MBeanException, ReflectionException,
00207 IOException {
00208 this.mbs.setAttribute(name, attribute);
00209 }
00210
00214 @SuppressWarnings("unused")
00215 public AttributeList setAttributes(ObjectName name, AttributeList attributes)
00216 throws InstanceNotFoundException, ReflectionException, IOException {
00217 return this.mbs.setAttributes(name, attributes);
00218 }
00219
00223 @SuppressWarnings("unused")
00224 public Object invoke(ObjectName name, String operationName,
00225 Object[] params, String[] signature)
00226 throws InstanceNotFoundException, MBeanException, ReflectionException,
00227 IOException {
00228 return this.mbs.invoke(name, operationName, params, signature);
00229 }
00230
00234 @SuppressWarnings("unused")
00235 public String getDefaultDomain() throws IOException {
00236 return this.mbs.getDefaultDomain();
00237 }
00238
00242 @SuppressWarnings("unused")
00243 public String[] getDomains() throws IOException {
00244 return this.mbs.getDomains();
00245 }
00246
00250 @SuppressWarnings("unused")
00251 public void addNotificationListener(ObjectName name, ObjectName listener,
00252 NotificationFilter filter, Object handback)
00253 throws InstanceNotFoundException, IOException {
00254 this.mbs.addNotificationListener(name, listener, filter, handback);
00255 }
00256
00260 @SuppressWarnings("unused")
00261 public void addNotificationListener(ObjectName name,
00262 NotificationListener listener, NotificationFilter filter,
00263 Object handback) throws InstanceNotFoundException, IOException {
00264 System.out.println("ProActiveConnection.addNotificationListener()");
00265 try {
00266 ListenerAdapter tl = new ListenerAdapter(listener);
00267
00268 this.listenerMap.put(listener, tl);
00269 this.mbs.addNotificationListener(name, tl, filter, handback);
00270 } catch (Exception e) {
00271 e.printStackTrace();
00272 }
00273 }
00274
00278 @SuppressWarnings("unused")
00279 public void removeNotificationListener(ObjectName name, ObjectName listener)
00280 throws InstanceNotFoundException, ListenerNotFoundException, IOException {
00281 ListenerAdapter tl = this.listenerMap.get(listener);
00282 this.mbs.removeNotificationListener(name, tl);
00283 }
00284
00288 @SuppressWarnings("unused")
00289 public void removeNotificationListener(ObjectName name,
00290 ObjectName listener, NotificationFilter filter, Object handback)
00291 throws InstanceNotFoundException, ListenerNotFoundException, IOException {
00292 ListenerAdapter tl = this.listenerMap.get(listener);
00293 this.mbs.removeNotificationListener(name, tl, filter, handback);
00294 }
00295
00299 @SuppressWarnings("unused")
00300 public void removeNotificationListener(ObjectName name,
00301 NotificationListener listener)
00302 throws InstanceNotFoundException, ListenerNotFoundException, IOException {
00303 ListenerAdapter tl = this.listenerMap.get(listener);
00304 this.mbs.removeNotificationListener(name, tl);
00305 }
00306
00310 @SuppressWarnings("unused")
00311 public void removeNotificationListener(ObjectName name,
00312 NotificationListener listener, NotificationFilter filter,
00313 Object handback)
00314 throws InstanceNotFoundException, ListenerNotFoundException, IOException {
00315 ListenerAdapter tl = this.listenerMap.get(listener);
00316 this.mbs.removeNotificationListener(name, tl, filter, handback);
00317 }
00318
00322 @SuppressWarnings("unused")
00323 public MBeanInfo getMBeanInfo(ObjectName name)
00324 throws InstanceNotFoundException, IntrospectionException,
00325 ReflectionException, IOException {
00326 return this.mbs.getMBeanInfo(name);
00327 }
00328
00332 @SuppressWarnings("unused")
00333 public boolean isInstanceOf(ObjectName name, String className)
00334 throws InstanceNotFoundException, IOException {
00335 return this.mbs.isInstanceOf(name, className);
00336 }
00337
00341 @SuppressWarnings("unused")
00342 public ObjectInstance createMBean(String className, ObjectName name)
00343 throws ReflectionException, InstanceAlreadyExistsException,
00344 MBeanRegistrationException, MBeanException,
00345 NotCompliantMBeanException, IOException {
00346 return this.mbs.createMBean(className, name);
00347 }
00348
00353 public GenericTypeWrapper createMBeanAsynchronous(String className,
00354 ObjectName name) {
00355 try {
00356 return new GenericTypeWrapper<ObjectInstance>(this.createMBean(
00357 className, name));
00358 } catch (Exception e) {
00359 return new GenericTypeWrapper<Exception>(e);
00360 }
00361 }
00362
00367 public GenericTypeWrapper createMBeanAsynchronous(String className,
00368 ObjectName name, ObjectName loaderName) {
00369 try {
00370 return new GenericTypeWrapper<ObjectInstance>(this.createMBean(
00371 className, name, loaderName));
00372 } catch (Exception e) {
00373 return new GenericTypeWrapper<Exception>(e);
00374 }
00375 }
00376
00377
00378
00379
00380
00381 public GenericTypeWrapper createMBeanAsynchronous(String className,
00382 ObjectName name, Object[] params, String[] signature) {
00383 try {
00384 return new GenericTypeWrapper<ObjectInstance>(this.createMBean(
00385 className, name, params, signature));
00386 } catch (Exception e) {
00387 return new GenericTypeWrapper<Exception>(e);
00388 }
00389 }
00390
00395 public GenericTypeWrapper createMBeanAsynchronous(String className,
00396 ObjectName name, ObjectName loaderName, Object[] params,
00397 String[] signature) {
00398 try {
00399 return new GenericTypeWrapper<ObjectInstance>(this.createMBean(
00400 className, name, loaderName, params, signature));
00401 } catch (Exception e) {
00402 return new GenericTypeWrapper<Exception>(e);
00403 }
00404 }
00405
00410 public GenericTypeWrapper getObjectInstanceAsynchronous(ObjectName name) {
00411 try {
00412 return new GenericTypeWrapper<ObjectInstance>(this.getObjectInstance(
00413 name));
00414 } catch (Exception e) {
00415 return new GenericTypeWrapper<Exception>(e);
00416 }
00417 }
00418
00423 public GenericTypeWrapper queryMBeansAsynchronous(ObjectName name, QueryExp query) {
00424 try {
00425 return new GenericTypeWrapper<Set>(this.queryMBeans(name, query));
00426 } catch (IOException e) {
00427 return new GenericTypeWrapper<Exception>(e);
00428 }
00429 }
00430
00435 public GenericTypeWrapper queryNamesAsynchronous(ObjectName name, QueryExp query) {
00436 try {
00437 return new GenericTypeWrapper<Set>(this.queryNames(name, query));
00438 } catch (IOException e) {
00439 return new GenericTypeWrapper<Exception> (e);
00440 }
00441 }
00442
00447 public GenericTypeWrapper getMBeanCountAsynchronous() {
00448 try {
00449 return new GenericTypeWrapper<Integer>(this.getMBeanCount());
00450 } catch (IOException e) {
00451 return new GenericTypeWrapper<Exception> (e);
00452 }
00453 }
00454
00459 public GenericTypeWrapper getAttributeAsynchronous(ObjectName name,
00460 String attribute) {
00461 try {
00462 return new GenericTypeWrapper <Object>(this.getAttribute(name, attribute));
00463 } catch (Exception e) {
00464 return new GenericTypeWrapper<Exception> (e);
00465 }
00466 }
00467
00472 public GenericTypeWrapper getAttributesAsynchronous(ObjectName name,
00473 String[] attributes) {
00474 try {
00475 return new GenericTypeWrapper<AttributeList>(this.getAttributes(name, attributes));
00476 } catch (Exception e) {
00477 return new GenericTypeWrapper<Exception> (e);
00478 }
00479 }
00480
00485 public GenericTypeWrapper setAttributesAsynchronous(ObjectName name,
00486 AttributeList attributes) {
00487 try {
00488 return new GenericTypeWrapper<AttributeList>(this.setAttributes(name, attributes));
00489 } catch (Exception e) {
00490 return new GenericTypeWrapper<Exception>(e);
00491 }
00492 }
00493
00498 public GenericTypeWrapper invokeAsynchronous(ObjectName name,
00499 String operationName, Object[] params, String[] signature) {
00500 try {
00501 return new GenericTypeWrapper <Object>(this.invoke(name, operationName, params,
00502 signature));
00503 } catch (Exception e) {
00504 return new GenericTypeWrapper<Exception> (e);
00505 }
00506 }
00507
00512 public GenericTypeWrapper getDefaultDomainAsynchronous() {
00513 try {
00514 return new GenericTypeWrapper<String>(this.getDefaultDomain());
00515 } catch (IOException e) {
00516 return new GenericTypeWrapper<Exception> (e);
00517 }
00518 }
00519
00524 public GenericTypeWrapper getDomainsAsynchronous() {
00525 try {
00526 return new GenericTypeWrapper <String [] >(this.getDomains());
00527 } catch (IOException e) {
00528 return new GenericTypeWrapper<Exception > (e);
00529 }
00530 }
00531
00536 public GenericTypeWrapper getMBeanInfoAsynchronous(ObjectName name) {
00537 try {
00538 return new GenericTypeWrapper<MBeanInfo>(this.getMBeanInfo(name));
00539 } catch (Exception e) {
00540 return new GenericTypeWrapper <Exception > (e);
00541 }
00542 }
00543 }