private static int mbeanCreation(MBeanServer mbs, String name) throws Exception { int error = 0; try { System.out.println("Test: createMBean(" + name + ")"); mbs.createMBean(classname, ObjectName.getInstance(name)); error++; System.out.println("Didn't get expected exception!"); System.out.println("Test failed!"); } catch (RuntimeOperationsException e) { System.out.println("Got expected exception = " + e.getCause().toString()); System.out.println("Test passed!"); } return error; }
/** * Obtain and return the values of several attributes of this MBean. * * @param names * Names of the requested attributes */ @Override public AttributeList getAttributes(String names[]) { // Validate the input parameters if (names == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute names list is null"), "Attribute names list is null"); // Prepare our response, eating all exceptions AttributeList response = new AttributeList(); for (int i = 0; i < names.length; i++) { try { response.add(new Attribute(names[i], getAttribute(names[i]))); } catch (Exception e) { // Not having a particular attribute in the response // is the indication of a getter problem } } return (response); }
/** * Obtain and return the values of several attributes of this MBean. * * @param names Names of the requested attributes */ @Override public AttributeList getAttributes(String names[]) { // Validate the input parameters if (names == null) throw new RuntimeOperationsException (new IllegalArgumentException("Attribute names list is null"), "Attribute names list is null"); // Prepare our response, eating all exceptions AttributeList response = new AttributeList(); for (int i = 0; i < names.length; i++) { try { response.add(new Attribute(names[i],getAttribute(names[i]))); } catch (Exception e) { // Not having a particular attribute in the response // is the indication of a getter problem } } return (response); }
private NotificationListener getListener(ObjectName listener) throws ListenerNotFoundException { // ---------------- // Get listener object // ---------------- DynamicMBean instance; try { instance = getMBean(listener); } catch (InstanceNotFoundException e) { throw EnvHelp.initCause( new ListenerNotFoundException(e.getMessage()), e); } Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { final RuntimeException exc = new IllegalArgumentException(listener.getCanonicalName()); final String msg = "MBean " + listener.getCanonicalName() + " does not " + "implement " + NotificationListener.class.getName(); throw new RuntimeOperationsException(exc, msg); } return (NotificationListener) resource; }
protected void notifyJmx(String query, String type) { try { long sequence = notifySequence.incrementAndGet(); if (isNotifyPool()) { if (this.pool!=null && this.pool.getJmxPool()!=null) { this.pool.getJmxPool().notify(type, query); } } else { if (notifier!=null) { Notification notification = new Notification(type, this, sequence, System.currentTimeMillis(), query); notifier.sendNotification(notification); } } } catch (RuntimeOperationsException e) { if (log.isDebugEnabled()) { log.debug("Unable to send failed query notification.",e); } } }
/** * Loads the class with the specified name using this object's * Default Loader Repository. **/ public Class<?> findClassWithDefaultLoaderRepository(String className) throws ReflectionException { Class<?> theClass; if (className == null) { throw new RuntimeOperationsException(new IllegalArgumentException("The class name cannot be null"), "Exception occurred during object instantiation"); } ReflectUtil.checkPackageAccess(className); try { if (clr == null) throw new ClassNotFoundException(className); theClass = clr.loadClass(className); } catch (ClassNotFoundException ee) { throw new ReflectionException(ee, "The MBean class could not be loaded by the default loader repository"); } return theClass; }
/** * Load a class with the specified loader, or with this object * class loader if the specified loader is null. **/ static Class<?> loadClass(String className, ClassLoader loader) throws ReflectionException { Class<?> theClass; if (className == null) { throw new RuntimeOperationsException(new IllegalArgumentException("The class name cannot be null"), "Exception occurred during object instantiation"); } ReflectUtil.checkPackageAccess(className); try { if (loader == null) loader = MBeanInstantiator.class.getClassLoader(); if (loader != null) { theClass = Class.forName(className, false, loader); } else { theClass = Class.forName(className); } } catch (ClassNotFoundException e) { throw new ReflectionException(e, "The MBean class could not be loaded"); } return theClass; }
/** * Send an <code>AttributeChangeNotification</code> to all registered * listeners. * * @param oldValue The original value of the <code>Attribute</code> * @param newValue The new value of the <code>Attribute</code> * * @exception MBeanException if an object initializer throws an * exception * @exception RuntimeOperationsException wraps IllegalArgumentException * when the specified notification is <code>null</code> or invalid */ public void sendAttributeChangeNotification (Attribute oldValue, Attribute newValue) throws MBeanException, RuntimeOperationsException { // Calculate the class name for the change notification String type = null; if (newValue.getValue() != null) type = newValue.getValue().getClass().getName(); else if (oldValue.getValue() != null) type = oldValue.getValue().getClass().getName(); else return; // Old and new are both null == no change AttributeChangeNotification notification = new AttributeChangeNotification (this, 1, System.currentTimeMillis(), "Attribute value has changed", oldValue.getName(), type, oldValue.getValue(), newValue.getValue()); sendAttributeChangeNotification(notification); }
public void addAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws MBeanException, RuntimeOperationsException, IllegalArgumentException { if (listener == null) throw new RuntimeOperationsException(new IllegalArgumentException( LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString())); AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter(); if (attributeName != null) { filter.enableAttribute(attributeName); } else { MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes(); for (int i = 0; i < ai.length; i++) { Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor(); filter.enableAttribute((String) d.getFieldValue("name")); } } getAttributeChangeBroadcaster().addNotificationListener(listener, filter, handback); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Listener " + listener + " for attribute " + attributeName + " added successfully, handback is " + handback); }
public void sendAttributeChangeNotification(AttributeChangeNotification notification) throws MBeanException, RuntimeOperationsException { if (notification == null) throw new RuntimeOperationsException(new IllegalArgumentException( LocalizedStrings.MX4JModelMBean_NOTIFICATION_CANNOT_BE_NULL.toLocalizedString())); getAttributeChangeBroadcaster().sendNotification(notification); Logger modelMBeanLogger = getModelMBeanLogger(notification.getType()); if (modelMBeanLogger != null) if (modelMBeanLogger.isEnabledFor(Logger.DEBUG)) modelMBeanLogger.debug("ModelMBean log: " + new Date() + " - " + notification); Logger logger = getLogger(); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("Attribute change notification " + notification + " sent"); }
/** * Send an <code>AttributeChangeNotification</code> to all registered * listeners. * * @param oldValue * The original value of the <code>Attribute</code> * @param newValue * The new value of the <code>Attribute</code> * * @exception MBeanException * if an object initializer throws an exception * @exception RuntimeOperationsException * wraps IllegalArgumentException when the specified * notification is <code>null</code> or invalid */ @Override public void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue) throws MBeanException, RuntimeOperationsException { // Calculate the class name for the change notification String type = null; if (newValue.getValue() != null) type = newValue.getValue().getClass().getName(); else if (oldValue.getValue() != null) type = oldValue.getValue().getClass().getName(); else return; // Old and new are both null == no change AttributeChangeNotification notification = new AttributeChangeNotification(this, 1, System.currentTimeMillis(), "Attribute value has changed", oldValue.getName(), type, oldValue.getValue(), newValue.getValue()); sendAttributeChangeNotification(notification); }
private static <T extends NotificationBroadcaster> T getNotificationBroadcaster(ObjectName name, Object instance, Class<T> reqClass) { if (reqClass.isInstance(instance)) return reqClass.cast(instance); if (instance instanceof DynamicMBean2) instance = ((DynamicMBean2) instance).getResource(); if (reqClass.isInstance(instance)) return reqClass.cast(instance); final RuntimeException exc = new IllegalArgumentException(name.getCanonicalName()); final String msg = "MBean " + name.getCanonicalName() + " does not " + "implement " + reqClass.getName(); throw new RuntimeOperationsException(exc, msg); }
/** * Registers a ClassLoader with the CLR. * This method is called by the ResourceContext from within the * repository lock. * @param loader The ClassLoader. * @param logicalName The ClassLoader MBean ObjectName. */ private void addClassLoader(ClassLoader loader, final ObjectName logicalName) { /** * Called when the newly registered MBean is a ClassLoader * If so, tell the ClassLoaderRepository (CLR) about it. We do * this even if the loader is a PrivateClassLoader. In that * case, the CLR remembers the loader for use when it is * explicitly named (e.g. as the loader in createMBean) but * does not add it to the list that is consulted by * ClassLoaderRepository.loadClass. */ final ModifiableClassLoaderRepository clr = getInstantiatorCLR(); if (clr == null) { final RuntimeException wrapped = new IllegalArgumentException( "Dynamic addition of class loaders" + " is not supported"); throw new RuntimeOperationsException(wrapped, "Exception occurred trying to register" + " the MBean as a class loader"); } clr.addClassLoader(logicalName, loader); }
@Override public AttributeList getAttributes(String[] attributeNames) { if (attributeNames == null) { throw new RuntimeOperationsException(new IllegalArgumentException("attributeNames[] cannot be null"), "Cannot call getAttributes with null attribute names"); } AttributeList resultList = new AttributeList(); if (attributeNames.length == 0) { return resultList; } for (String attributeName : attributeNames) { try { Object value = getAttribute(attributeName); resultList.add(new Attribute(attributeName, value)); } catch (Exception e) { e.printStackTrace(); } } return (resultList); }
public synchronized Object getFieldValue(String fieldName) throws RuntimeOperationsException { if ((fieldName == null) || (fieldName.equals(""))) { if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) { MODELMBEAN_LOGGER.logp(Level.FINEST, DescriptorSupport.class.getName(), "getFieldValue(String fieldName)", "Illegal arguments: null field name"); } final String msg = "Fieldname requested is null"; final RuntimeException iae = new IllegalArgumentException(msg); throw new RuntimeOperationsException(iae, msg); } Object retValue = descriptorMap.get(fieldName); if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) { MODELMBEAN_LOGGER.logp(Level.FINEST, DescriptorSupport.class.getName(), "getFieldValue(String fieldName = " + fieldName + ")", "Returns '" + retValue + "'"); } return(retValue); }
/** * Gets the class for the specified class name using the specified * class loader */ public Class<?> findClass(String className, ObjectName aLoader) throws ReflectionException, InstanceNotFoundException { if (aLoader == null) throw new RuntimeOperationsException(new IllegalArgumentException(), "Null loader passed in parameter"); // Retrieve the class loader from the repository ClassLoader loader = null; synchronized (this) { loader = getClassLoader(aLoader); } if (loader == null) { throw new InstanceNotFoundException("The loader named " + aLoader + " is not registered in the MBeanServer"); } return findClass(className,loader); }
/** * Constructor taking field names and field values. Neither array * can be null. * * @param fieldNames String array of field names. No elements of * this array can be null. * @param fieldValues Object array of the corresponding field * values. Elements of the array can be null. The * <code>fieldValue</code> must be valid for the * <code>fieldName</code> (as defined in method {@link #isValid * isValid}) * * <p>Note: array sizes of parameters should match. If both arrays * are empty, then an empty descriptor is created.</p> * * @exception RuntimeOperationsException for illegal value for * field Names or field Values. The array lengths must be equal. * If the descriptor construction fails for any reason, this * exception will be thrown. * */ public DescriptorSupport(String[] fieldNames, Object[] fieldValues) throws RuntimeOperationsException { if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) { MODELMBEAN_LOGGER.logp(Level.FINEST, DescriptorSupport.class.getName(), "Descriptor(fieldNames,fieldObjects)", "Constructor"); } if ((fieldNames == null) || (fieldValues == null) || (fieldNames.length != fieldValues.length)) { if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) { MODELMBEAN_LOGGER.logp(Level.FINEST, DescriptorSupport.class.getName(), "Descriptor(fieldNames,fieldObjects)", "Illegal arguments"); } final String msg = "Null or invalid fieldNames or fieldValues"; final RuntimeException iae = new IllegalArgumentException(msg); throw new RuntimeOperationsException(iae, msg); } /* populate internal structure with fields */ init(null); for (int i=0; i < fieldNames.length; i++) { // setField will throw an exception if a fieldName is be null. // the fieldName and fieldValue will be validated in setField. setField(fieldNames[i], fieldValues[i]); } if (MODELMBEAN_LOGGER.isLoggable(Level.FINEST)) { MODELMBEAN_LOGGER.logp(Level.FINEST, DescriptorSupport.class.getName(), "Descriptor(fieldNames,fieldObjects)", "Exit"); } }
/** * This method always fail since all MBeanServerDelegateMBean attributes * are read-only. * * @param attribute The identification of the attribute to * be set and the value it is to be set to. * * @exception AttributeNotFoundException */ public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { // Now we will always fail: // Either because the attribute is null or because it is not // accessible (or does not exist). // final String attname = (attribute==null?null:attribute.getName()); if (attname == null) { final RuntimeException r = new IllegalArgumentException("Attribute name cannot be null"); throw new RuntimeOperationsException(r, "Exception occurred trying to invoke the setter on the MBean"); } // This is a hack: we call getAttribute in order to generate an // AttributeNotFoundException if the attribute does not exist. // Object val = getAttribute(attname); // If we reach this point, we know that the requested attribute // exists. However, since all attributes are read-only, we throw // an AttributeNotFoundException. // throw new AttributeNotFoundException(attname + " not accessible"); }
/** * Set the instance handle of the object against which we will execute * all methods in this ModelMBean management interface. * * <strike>This method will detect and call "setModelMbean" method. A resource * can implement this method to get a reference to the model mbean. * The reference can be used to send notification and access the * registry. * </strike> The caller can provide the mbean instance or the object name to * the resource, if needed. * * @param resource The resource object to be managed * @param type The type of reference for the managed resource * ("ObjectReference", "Handle", "IOR", "EJBHandle", or * "RMIReference") * * @exception InstanceNotFoundException if the managed resource object * cannot be found * @exception MBeanException if the initializer of the object throws * an exception * @exception RuntimeOperationsException if the managed resource or the * resource type is <code>null</code> or invalid */ public void setManagedResource(Object resource, String type) throws InstanceNotFoundException, MBeanException, RuntimeOperationsException { if (resource == null) throw new RuntimeOperationsException (new IllegalArgumentException("Managed resource is null"), "Managed resource is null"); // if (!"objectreference".equalsIgnoreCase(type)) // throw new InvalidTargetObjectTypeException(type); this.resource = resource; this.resourceType = resource.getClass().getName(); // // Make the resource aware of the model mbean. // try { // Method m=resource.getClass().getMethod("setModelMBean", // new Class[] {ModelMBean.class}); // if( m!= null ) { // m.invoke(resource, new Object[] {this}); // } // } catch( NoSuchMethodException t ) { // // ignore // } catch( Throwable t ) { // log.error( "Can't set model mbean ", t ); // } }
/** * Send a <code>Notification</code> to all registered listeners as a * <code>jmx.modelmbean.general</code> notification. * * @param notification The <code>Notification</code> that will be passed * * @exception MBeanException if an object initializer throws an * exception * @exception RuntimeOperationsException wraps IllegalArgumentException * when the specified notification is <code>null</code> or invalid */ @Override public void sendNotification(Notification notification) throws MBeanException, RuntimeOperationsException { if (notification == null) throw new RuntimeOperationsException (new IllegalArgumentException("Notification is null"), "Notification is null"); if (generalBroadcaster == null) return; // This means there are no registered listeners generalBroadcaster.sendNotification(notification); }
/** * Returns the ModelMBeanConstructorInfo requested by name. * If no ModelMBeanConstructorInfo exists for this name null is returned. * * @param inName the name of the constructor. * * @return the constructor info for the named constructor, or null * if there is none. * * @exception MBeanException Wraps a distributed communication Exception. * @exception RuntimeOperationsException Wraps an IllegalArgumentException * for a null constructor name. */ public ModelMBeanConstructorInfo getConstructor(String inName) throws MBeanException, RuntimeOperationsException { ModelMBeanConstructorInfo retInfo = null; if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); } if (inName == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Constructor name is null"), "Exception occurred trying to get the " + "ModelMBeanConstructorInfo of the MBean"); } MBeanConstructorInfo[] consList = modelMBeanConstructors; //this.getConstructors(); int numCons = 0; if (consList != null) numCons = consList.length; for (int i=0; (i < numCons) && (retInfo == null); i++) { if (inName.equals(consList[i].getName())) { retInfo = ((ModelMBeanConstructorInfo) consList[i].clone()); } } if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { MODELMBEAN_LOGGER.log(Level.TRACE, "Exit"); } return retInfo; }
/** * Sets the values of an array of attributes of this ModelMBean. * Executes the setAttribute() method for each attribute in the list. * * @param attributes A list of attributes: The identification of the * attributes to be set and the values they are to be set to. * * @return The array of attributes that were set, with their new * values in Attribute instances. * * @exception RuntimeOperationsException Wraps an * {@link IllegalArgumentException}: The object name in parameter * is null or attributes in parameter is null. * * @see #getAttributes **/ public AttributeList setAttributes(AttributeList attributes) { if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); } if (attributes == null) throw new RuntimeOperationsException(new IllegalArgumentException("attributes must not be null"), "Exception occurred trying to set attributes of a "+ "RequiredModelMBean"); final AttributeList responseList = new AttributeList(); // Go through the list of attributes for (Attribute attr : attributes.asList()) { try { setAttribute(attr); responseList.add(attr); } catch (Exception excep) { responseList.remove(attr); } } return responseList; }
public void store() throws MBeanException, RuntimeOperationsException, InstanceNotFoundException { PersisterMBean persister = findPersister(); if (persister != null) { // Take a clone to avoid synchronization problems ModelMBeanInfo info = (ModelMBeanInfo) getMBeanInfo(); persister.store(info); } }
/** * Write the configuration information for this entire <code>Server</code> * out to the server.xml configuration file. * * @exception InstanceNotFoundException if the managed resource object * cannot be found * @exception MBeanException if the initializer of the object throws * an exception, or persistence is not supported * @exception RuntimeOperationsException if an exception is reported * by the persistence mechanism */ public synchronized void store() throws InstanceNotFoundException, MBeanException, RuntimeOperationsException { Server server = ServerFactory.getServer(); if (server instanceof StandardServer) { try { ((StandardServer) server).storeConfig(); } catch (Exception e) { throw new MBeanException(e, "Error updating conf/server.xml"); } } }
/** * Set the instance handle of the object against which we will execute * all methods in this ModelMBean management interface. * * <strike>This method will detect and call "setModelMbean" method. A resource * can implement this method to get a reference to the model mbean. * The reference can be used to send notification and access the * registry. * </strike> The caller can provide the mbean instance or the object name to * the resource, if needed. * * @param resource The resource object to be managed * @param type The type of reference for the managed resource * ("ObjectReference", "Handle", "IOR", "EJBHandle", or * "RMIReference") * * @exception InstanceNotFoundException if the managed resource object * cannot be found * @exception InvalidTargetObjectTypeException if this ModelMBean is * asked to handle a reference type it cannot deal with * @exception MBeanException if the initializer of the object throws * an exception * @exception RuntimeOperationsException if the managed resource or the * resource type is <code>null</code> or invalid */ public void setManagedResource(Object resource, String type) throws InstanceNotFoundException, MBeanException, RuntimeOperationsException { if (resource == null) throw new RuntimeOperationsException (new IllegalArgumentException("Managed resource is null"), "Managed resource is null"); // if (!"objectreference".equalsIgnoreCase(type)) // throw new InvalidTargetObjectTypeException(type); this.resource = resource; this.resourceType = resource.getClass().getName(); // // Make the resource aware of the model mbean. // try { // Method m=resource.getClass().getMethod("setModelMBean", // new Class[] {ModelMBean.class}); // if( m!= null ) { // m.invoke(resource, new Object[] {this}); // } // } catch( NoSuchMethodException t ) { // // ignore // } catch( Throwable t ) { // log.error( "Can't set model mbean ", t ); // } }
public boolean isRegistered(ObjectName name) { if (name == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Object name cannot be null"), "Object name cannot be null"); } name = nonDefaultDomain(name); /* No Permission check */ // isRegistered is always unchecked as per JMX spec. return (repository.contains(name)); }
public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException { if (name == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Object name cannot be null"), "Exception occurred trying to invoke the getter on the MBean"); } if (attribute == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Attribute cannot be null"), "Exception occurred trying to invoke the getter on the MBean"); } name = nonDefaultDomain(name); if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "getAttribute", "Attribute = " + attribute + ", ObjectName = " + name); } final DynamicMBean instance = getMBean(name); checkMBeanPermission(instance, attribute, name, "getAttribute"); try { return instance.getAttribute(attribute); } catch (AttributeNotFoundException e) { throw e; } catch (Throwable t) { rethrowMaybeMBeanException(t); throw new AssertionError(); // not reached } }
public ModelMBeanAttributeInfo getAttribute(String inName) throws MBeanException, RuntimeOperationsException { ModelMBeanAttributeInfo retInfo = null; if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { MODELMBEAN_LOGGER.log(Level.TRACE, "Entry"); } if (inName == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Attribute Name is null"), "Exception occurred trying to get the " + "ModelMBeanAttributeInfo of the MBean"); } MBeanAttributeInfo[] attrList = modelMBeanAttributes; int numAttrs = 0; if (attrList != null) numAttrs = attrList.length; for (int i=0; (i < numAttrs) && (retInfo == null); i++) { if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { final StringBuilder strb = new StringBuilder() .append("\t\n this.getAttributes() MBeanAttributeInfo Array ") .append(i).append(":") .append(((ModelMBeanAttributeInfo)attrList[i]).getDescriptor()) .append("\t\n this.modelMBeanAttributes MBeanAttributeInfo Array ") .append(i).append(":") .append(((ModelMBeanAttributeInfo)modelMBeanAttributes[i]).getDescriptor()); MODELMBEAN_LOGGER.log(Level.TRACE, strb::toString); } if (inName.equals(attrList[i].getName())) { retInfo = ((ModelMBeanAttributeInfo)attrList[i].clone()); } } if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) { MODELMBEAN_LOGGER.log(Level.TRACE, "Exit"); } return retInfo; }
public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name); } DynamicMBean instance = getMBean(name); checkMBeanPermission(instance, null, name, "addNotificationListener"); NotificationBroadcaster broadcaster = getNotificationBroadcaster(name, instance, NotificationBroadcaster.class); // ------------------ // Check listener // ------------------ if (listener == null) { throw new RuntimeOperationsException(new IllegalArgumentException("Null listener"),"Null listener"); } NotificationListener listenerWrapper = getListenerWrapper(listener, name, instance, true); broadcaster.addNotificationListener(listenerWrapper, filter, handback); }
public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException { // ------------------------------ // ------------------------------ // ---------------- // Get listener object // ---------------- DynamicMBean instance = getMBean(listener); Object resource = getResource(instance); if (!(resource instanceof NotificationListener)) { throw new RuntimeOperationsException(new IllegalArgumentException(listener.getCanonicalName()), "The MBean " + listener.getCanonicalName() + "does not implement the NotificationListener interface") ; } // ---------------- // Add a listener on an MBean // ---------------- if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) { MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "addNotificationListener", "ObjectName = " + name + ", Listener = " + listener); } server.addNotificationListener(name,(NotificationListener) resource, filter, handback) ; }
public MX4JModelMBean() throws MBeanException, RuntimeOperationsException { try { load(); } catch (Exception x) { Logger logger = getLogger(); logger.warn(LocalizedStrings.MX4JModelMBean_CANNOT_RESTORE_PREVIOUSLY_SAVED_STATUS .toLocalizedString(), x); } }
public ModelMBeanOperationInfo getOperation(String inName) throws MBeanException, RuntimeOperationsException { ModelMBeanOperationInfo retInfo = null; if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getOperation(String)", "Entry"); } if (inName == null) { throw new RuntimeOperationsException( new IllegalArgumentException("inName is null"), "Exception occurred trying to get the " + "ModelMBeanOperationInfo of the MBean"); } MBeanOperationInfo[] operList = modelMBeanOperations; //this.getOperations(); int numOpers = 0; if (operList != null) numOpers = operList.length; for (int i=0; (i < numOpers) && (retInfo == null); i++) { if (inName.equals(operList[i].getName())) { retInfo = ((ModelMBeanOperationInfo) operList[i].clone()); } } if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getOperation(String)", "Exit"); } return retInfo; }
/** * Returns the ModelMBeanConstructorInfo requested by name. * If no ModelMBeanConstructorInfo exists for this name null is returned. * * @param inName the name of the constructor. * * @return the constructor info for the named constructor, or null * if there is none. * * @exception MBeanException Wraps a distributed communication Exception. * @exception RuntimeOperationsException Wraps an IllegalArgumentException * for a null constructor name. */ public ModelMBeanConstructorInfo getConstructor(String inName) throws MBeanException, RuntimeOperationsException { ModelMBeanConstructorInfo retInfo = null; if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getConstructor(String)", "Entry"); } if (inName == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Constructor name is null"), "Exception occurred trying to get the " + "ModelMBeanConstructorInfo of the MBean"); } MBeanConstructorInfo[] consList = modelMBeanConstructors; //this.getConstructors(); int numCons = 0; if (consList != null) numCons = consList.length; for (int i=0; (i < numCons) && (retInfo == null); i++) { if (inName.equals(consList[i].getName())) { retInfo = ((ModelMBeanConstructorInfo) consList[i].clone()); } } if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getConstructor(String)", "Exit"); } return retInfo; }
public ModelMBeanNotificationInfo getNotification(String inName) throws MBeanException, RuntimeOperationsException { ModelMBeanNotificationInfo retInfo = null; if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getNotification(String)", "Entry"); } if (inName == null) { throw new RuntimeOperationsException( new IllegalArgumentException("Notification name is null"), "Exception occurred trying to get the " + "ModelMBeanNotificationInfo of the MBean"); } MBeanNotificationInfo[] notifList = modelMBeanNotifications; //this.getNotifications(); int numNotifs = 0; if (notifList != null) numNotifs = notifList.length; for (int i=0; (i < numNotifs) && (retInfo == null); i++) { if (inName.equals(notifList[i].getName())) { retInfo = ((ModelMBeanNotificationInfo) notifList[i].clone()); } } if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) { MODELMBEAN_LOGGER.logp(Level.FINER, ModelMBeanInfoSupport.class.getName(), "getNotification(String)", "Exit"); } return retInfo; }