Java Code Examples for javax.management.MBeanException

The following are top voted examples for showing how to use javax.management.MBeanException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jerrydog   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Context</code> object.
 *
 * @param context The Context to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(Context context)
    throws Exception {

    String mname = createManagedName(context);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(context);
    ObjectName oname = createObjectName(domain, context);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 2
Project: hadoop-oss   File: MetricsDynamicMBeanBase.java   Source Code and License 6 votes vote down vote up
@Override
public Object invoke(String actionName, Object[] parms, String[] signature)
    throws MBeanException, ReflectionException {
  
  if (actionName == null || actionName.isEmpty()) 
    throw new IllegalArgumentException();
  
  
  // Right now we support only one fixed operation (if it applies)
  if (!(actionName.equals(RESET_ALL_MIN_MAX_OP)) || 
      mbeanInfo.getOperations().length != 1) {
    throw new ReflectionException(new NoSuchMethodException(actionName));
  }
  for (MetricsBase m : metricsRegistry.getMetricsList())  {
    if ( MetricsTimeVaryingRate.class.isInstance(m) ) {
      MetricsTimeVaryingRate.class.cast(m).resetMinMax();
    }
  }
  return null;
}
 
Example 3
Project: hashsdn-controller   File: DynamicWritableWrapper.java   Source Code and License 6 votes vote down vote up
@Override
public synchronized void setAttribute(final Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    Attribute newAttribute = attribute;
    if (configBeanModificationDisabled.get()) {
        throw new IllegalStateException("Operation is not allowed now");
    }

    if ("Attribute".equals(newAttribute.getName())) {
        setAttribute((Attribute) newAttribute.getValue());
        return;
    }

    try {
        if (newAttribute.getValue() instanceof ObjectName) {
            newAttribute = fixDependencyAttribute(newAttribute);
        } else if (newAttribute.getValue() instanceof ObjectName[]) {
            newAttribute = fixDependencyListAttribute(newAttribute);
        }

        internalServer.setAttribute(objectNameInternal, newAttribute);
    } catch (final InstanceNotFoundException e) {
        throw new MBeanException(e);
    }

}
 
Example 4
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name)
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name);
    }
}
 
Example 5
Project: OpenJSharp   File: PerInterface.java   Source Code and License 6 votes vote down vote up
void setAttribute(Object resource, String attribute, Object value,
                  Object cookie)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {

    final M cm = setters.get(attribute);
    if (cm == null) {
        final String msg;
        if (getters.containsKey(attribute))
            msg = "Read-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    introspector.invokeSetter(attribute, cm, resource, value, cookie);
}
 
Example 6
Project: lazycat   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>ContextEnvironment</code> object.
 *
 * @param environment
 *            The ContextEnvironment to be managed
 *
 * @exception Exception
 *                if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextEnvironment environment) throws Exception {

	String mname = createManagedName(environment);
	ManagedBean managed = registry.findManagedBean(mname);
	if (managed == null) {
		Exception e = new Exception("ManagedBean is not found with " + mname);
		throw new MBeanException(e);
	}
	String domain = managed.getDomain();
	if (domain == null)
		domain = mserver.getDefaultDomain();
	DynamicMBean mbean = managed.createMBean(environment);
	ObjectName oname = createObjectName(domain, environment);
	if (mserver.isRegistered(oname)) {
		mserver.unregisterMBean(oname);
	}
	mserver.registerMBean(mbean, oname);
	return (mbean);

}
 
Example 7
Project: apache-tomcat-7.0.73-with-comment   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Group</code> object.
 *
 * @param group The Group to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Group group)
    throws Exception {

    String mname = createManagedName(group);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(group);
    ObjectName oname = createObjectName(domain, group);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 8
Project: monarch   File: MX4JModelMBean.java   Source Code and License 6 votes vote down vote up
public void sendAttributeChangeNotification(Attribute oldAttribute, Attribute newAttribute)
    throws MBeanException, RuntimeOperationsException {
  if (oldAttribute == null || newAttribute == null)
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_ATTRIBUTE_CANNOT_BE_NULL.toLocalizedString()));
  if (!oldAttribute.getName().equals(newAttribute.getName()))
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_ATTRIBUTE_NAMES_CANNOT_BE_DIFFERENT.toLocalizedString()));

  // TODO: the source must be the object name of the MBean if the listener was registered through
  // MBeanServer
  Object oldValue = oldAttribute.getValue();
  AttributeChangeNotification n = new AttributeChangeNotification(this, 1,
      System.currentTimeMillis(), "Attribute value changed", oldAttribute.getName(),
      oldValue == null ? null : oldValue.getClass().getName(), oldValue, newAttribute.getValue());
  sendAttributeChangeNotification(n);
}
 
Example 9
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 6 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className, ObjectName name,
                                  Object params[], String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name,
                                            params, signature);
    }
}
 
Example 10
Project: apache-tomcat-7.0.73-with-comment   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>ContextResource</code> object.
 *
 * @param resource The ContextResource to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static DynamicMBean createMBean(ContextResource resource)
    throws Exception {

    String mname = createManagedName(resource);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(resource);
    ObjectName oname = createObjectName(domain, resource);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 11
Project: jdk8u-jdk   File: RMIConnector.java   Source Code and License 6 votes vote down vote up
public Object getAttribute(ObjectName name,
        String attribute)
        throws MBeanException,
        AttributeNotFoundException,
        InstanceNotFoundException,
        ReflectionException,
        IOException {
    if (logger.debugOn()) logger.debug("getAttribute",
            "name=" + name + ", attribute="
            + attribute);

    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.getAttribute(name,
                attribute,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.getAttribute(name,
                attribute,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 12
Project: lams   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Engine</code> object.
 *
 * @param engine The Engine to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Engine engine)
    throws Exception {

    String mname = createManagedName(engine);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(engine);
    ObjectName oname = createObjectName(domain, engine);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 13
Project: jerrydog   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Service</code> object.
 *
 * @param service The Service to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public static ModelMBean createMBean(Service service)
    throws Exception {

    String mname = createManagedName(service);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ModelMBean mbean = managed.createMBean(service);
    ObjectName oname = createObjectName(domain, service);
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 14
Project: lams   File: MBeanUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Create, register, and return an MBean for this
 * <code>Valve</code> object.
 *
 * @param valve The Valve to be managed
 *
 * @exception Exception if an MBean cannot be created or registered
 */
static DynamicMBean createMBean(Valve valve)
    throws Exception {

    String mname = createManagedName(valve);
    ManagedBean managed = registry.findManagedBean(mname);
    if (managed == null) {
        Exception e = new Exception("ManagedBean is not found with "+mname);
        throw new MBeanException(e);
    }
    String domain = managed.getDomain();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    DynamicMBean mbean = managed.createMBean(valve);
    ObjectName oname = createObjectName(domain, valve);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    mserver.registerMBean(mbean, oname);
    return (mbean);

}
 
Example 15
Project: Pogamut3   File: DynamicProxy.java   Source Code and License 5 votes vote down vote up
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    try {
        mbsc.setAttribute(objectName, attribute);
    } catch (Exception ex) {
        throw new MBeanException(ex);
    }
}
 
Example 16
Project: OpenJSharp   File: RMIConnector.java   Source Code and License 5 votes vote down vote up
public ObjectInstance createMBean(String className,
        ObjectName name,
        Object params[],
        String signature[])
        throws ReflectionException,
        InstanceAlreadyExistsException,
        MBeanRegistrationException,
        MBeanException,
        NotCompliantMBeanException,
        IOException {
    if (logger.debugOn())
        logger.debug("createMBean(String,ObjectName,Object[],String[])",
                "className=" + className + ", name="
                + name + ", params="
                + objects(params) + ", signature="
                + strings(signature));

    final MarshalledObject<Object[]> sParams =
            new MarshalledObject<Object[]>(params);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        return connection.createMBean(className,
                name,
                sParams,
                signature,
                delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        return connection.createMBean(className,
                name,
                sParams,
                signature,
                delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 17
Project: monarch   File: MBeanServerWrapper.java   Source Code and License 5 votes vote down vote up
@Override
public void setAttribute(ObjectName name, Attribute attribute)
    throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException,
    MBeanException, ReflectionException {
  ResourcePermission ctx = getOperationContext(name, attribute.getName(), false);
  this.securityService.authorize(ctx);
  mbs.setAttribute(name, attribute);
}
 
Example 18
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   Source Code and License 5 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  ObjectName loaderName,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException, InstanceNotFoundException  {

    return createMBean(className, name, loaderName, false,
                       params, signature);
}
 
Example 19
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 5 votes vote down vote up
@Override
public synchronized ObjectInstance createMBean(String className, ObjectName name,
		ObjectName loaderName, Object[] params, String[] signature)
		throws ReflectionException, InstanceAlreadyExistsException,
		MBeanRegistrationException, MBeanException,
		NotCompliantMBeanException, InstanceNotFoundException {
	throw new UnsupportedOperationException("Not supported by PogamutMBeanServer yet...");		
}
 
Example 20
Project: hadoop   File: MetricsSourceAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
  updateJmxCache();
  synchronized(this) {
    Attribute a = attrCache.get(attribute);
    if (a == null) {
      throw new AttributeNotFoundException(attribute +" not found");
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(attribute +": "+ a);
    }
    return a.getValue();
  }
}
 
Example 21
Project: openjdk-jdk10   File: TestUnifiedLoggingSwitchStress.java   Source Code and License 5 votes vote down vote up
@Override
public void run() {

    while (!shouldStop) {
        int fileNum = RND.nextInt(logCount);
        int logLevel = RND.nextInt(LOG_LEVELS.length);

        String outputCommand = String.format("output=%s_%d.log", logFilePrefix, fileNum);
        String logLevelCommand = "what='gc*=" + LOG_LEVELS[logLevel] + "'";

        try {
            Object out = MBS.invoke(new ObjectName("com.sun.management:type=DiagnosticCommand"),
                                    "vmLog",
                                    new Object[]{new String[]{outputCommand, logLevelCommand}},
                                    new String[]{String[].class.getName()});

            if (!out.toString().isEmpty()) {
                System.out.format("WARNING: Diagnostic command vmLog with arguments %s,%s returned not empty"
                                + " output %s\n",
                        outputCommand, logLevelCommand, out);
            }
        } catch (InstanceNotFoundException | MBeanException | ReflectionException | MalformedObjectNameException e) {
            System.out.println("Got exception trying to change log level:" + e);
            e.printStackTrace();
            throw new Error(e);
        }
        Thread.yield();
    }
    System.out.println("Log Switcher finished");
}
 
Example 22
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   Source Code and License 5 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  ObjectName loaderName,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException, InstanceNotFoundException  {

    return createMBean(className, name, loaderName, false,
                       params, signature);
}
 
Example 23
Project: hadoop-oss   File: MetricsSourceAdapter.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute)
    throws AttributeNotFoundException, MBeanException, ReflectionException {
  updateJmxCache();
  synchronized(this) {
    Attribute a = attrCache.get(attribute);
    if (a == null) {
      throw new AttributeNotFoundException(attribute +" not found");
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug(attribute +": "+ a);
    }
    return a.getValue();
  }
}
 
Example 24
Project: openjdk-jdk10   File: ModelMBeanInfoSupport.java   Source Code and License 5 votes vote down vote up
public ModelMBeanOperationInfo getOperation(String inName)
throws MBeanException, RuntimeOperationsException {
    ModelMBeanOperationInfo retInfo = null;
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "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.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }

    return retInfo;
}
 
Example 25
Project: tomcat7   File: JMXProxyServlet.java   Source Code and License 5 votes vote down vote up
/**
 * Sets an MBean attribute's value.
 */
private void setAttributeInternal(String onameStr,
                                  String attributeName,
                                  String value)
    throws OperationsException, MBeanException, ReflectionException {
    ObjectName oname=new ObjectName( onameStr );
    String type=registry.getType(oname, attributeName);
    Object valueObj=registry.convertValue(type, value );
    mBeanServer.setAttribute( oname, new Attribute(attributeName, valueObj));
}
 
Example 26
Project: hashsdn-controller   File: ConfigTransactionClientsTest.java   Source Code and License 5 votes vote down vote up
@Test(expected = ValidationException.class)
public void testValidateBean2() throws Exception {
    MBeanServer mbsLocal = mock(MBeanServer.class);
    MBeanException mBeanException = new MBeanException(new ValidationException(
            Collections.<String, Map<String, ExceptionMessageWithStackTrace>>emptyMap()));
    doThrow(mBeanException).when(mbsLocal).invoke(transactionControllerON, "validate", null, null);

    ConfigTransactionJMXClient jmxTransactionClientFake = new ConfigTransactionJMXClient(null,
            transactionControllerON,
            mbsLocal);
    jmxTransactionClientFake.validateBean(transactionControllerON);
}
 
Example 27
Project: tqdev-metrics   File: JmxReporterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Should throw exception on unknown type.
 *
 * @throws MBeanException
 *             the MBean exception
 * @throws AttributeNotFoundException
 *             the attribute not found exception
 * @throws ReflectionException
 *             the reflection exception
 */
@Test
public void shouldThrowExceptionOnUnknownType()
		throws MBeanException, AttributeNotFoundException, ReflectionException {
	try {
		readJmx("jdbc.Statement.Invocations", "select");
		Assert.fail("readJmx should have thrown an AttributeNotFoundException");
	} catch (Exception e) {
		assertThat(e.getClass().getSimpleName()).isEqualTo("AttributeNotFoundException");
	}
}
 
Example 28
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public ObjectInstance createMBean(String className,
                                  ObjectName name,
                                  ObjectName loaderName,
                                  Object params[],
                                  String signature[])
    throws
    ReflectionException,
    InstanceAlreadyExistsException,
    MBeanRegistrationException,
    MBeanException,
    NotCompliantMBeanException,
    InstanceNotFoundException {
    checkCreate(className);
    SecurityManager sm = System.getSecurityManager();
    if (sm == null) {
        Object object = getMBeanServer().instantiate(className,
                                                     loaderName,
                                                     params,
                                                     signature);
        checkClassLoader(object);
        return getMBeanServer().registerMBean(object, name);
    } else {
        return getMBeanServer().createMBean(className, name, loaderName,
                                            params, signature);
    }
}
 
Example 29
Project: lazycat   File: BaseModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Send an <code>AttributeChangeNotification</code> to all registered
 * listeners.
 *
 * @param notification
 *            The <code>AttributeChangeNotification</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 sendAttributeChangeNotification(AttributeChangeNotification notification)
		throws MBeanException, RuntimeOperationsException {

	if (notification == null)
		throw new RuntimeOperationsException(new IllegalArgumentException("Notification is null"),
				"Notification is null");
	if (attributeBroadcaster == null)
		return; // This means there are no registered listeners
	if (log.isDebugEnabled())
		log.debug("AttributeChangeNotification " + notification);
	attributeBroadcaster.sendNotification(notification);

}
 
Example 30
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className,
                          Object params[],
                          String signature[])
    throws ReflectionException, MBeanException {
    checkCreate(className);
    return getMBeanServer().instantiate(className, params, signature);
}
 
Example 31
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 5 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name,
                                  ObjectName loaderName,
                                  Object[] params, String[] signature)
    throws ReflectionException, InstanceAlreadyExistsException,
           MBeanRegistrationException, MBeanException,
           NotCompliantMBeanException, InstanceNotFoundException  {

    return createMBean(className, name, loaderName, false,
                       params, signature);
}
 
Example 32
Project: hashsdn-controller   File: AbstractDynamicWrapper.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAttribute(final String attributeName)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if ("MBeanInfo".equals(attributeName)) {
        return getMBeanInfo();
    }

    Object obj = null;
    try {
        obj = internalServer.getAttribute(objectNameInternal, attributeName);
    } catch (final InstanceNotFoundException e) {
        throw new MBeanException(e);
    }

    if (obj instanceof ObjectName) {
        AttributeHolder attributeHolder = attributeHolderMap.get(attributeName);
        if (attributeHolder.getRequireInterfaceOrNull() != null) {
            obj = fixObjectName((ObjectName) obj);
        }
        return obj;
    }

    if (isDependencyListAttr(attributeName, obj)) {
        obj = fixDependencyListAttribute(obj);
    }

    return obj;
}
 
Example 33
Project: openjdk-jdk10   File: AvoidGetMBeanInfoCallsTest.java   Source Code and License 5 votes vote down vote up
public Object invoke(String actionName,
                     Object params[],
                     String signature[])
    throws MBeanException,
           ReflectionException {
    return null;
}
 
Example 34
Project: oscm   File: SetConfigurationSetting.java   Source Code and License 5 votes vote down vote up
@Override
public Object invoke(String actionName, Object[] params, String[] signature)
        throws MBeanException, ReflectionException {
    Object result = null;
    if (actionName.equals(SET_CONFIGURATION_SETTING)) {
        result = setConfigurationSetting((String) params[0],
                (String) params[1]);
    } else {
        throw new ReflectionException(new NoSuchMethodException(actionName));
    }
    return result;
}
 
Example 35
Project: OpenJSharp   File: SnmpGenericObjectServer.java   Source Code and License 5 votes vote down vote up
/**
 * Set the value of an SNMP variable.
 *
 * <p><b><i>
 * You should never need to use this method directly.
 * </i></b></p>
 *
 * @param meta  The impacted metadata object
 * @param name  The ObjectName of the impacted MBean
 * @param x     The new requested SnmpValue
 * @param id    The OID arc identifying the variable we're trying to set.
 * @param data  User contextual data allocated through the
 *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}
 *
 * @return The new value of the variable after the operation.
 *
 * @exception SnmpStatusException whenever an SNMP exception must be
 *      raised. Raising an exception will abort the request. <br>
 *      Exceptions should never be raised directly, but only by means of
 * <code>
 * req.registerSetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
 * </code>
 **/
public SnmpValue set(SnmpGenericMetaServer meta, ObjectName name,
                     SnmpValue x, long id, Object data)
    throws SnmpStatusException {
    final String attname = meta.getAttributeName(id);
    final Object attvalue=
        meta.buildAttributeValue(id,x);
    final Attribute att = new Attribute(attname,attvalue);

    Object result = null;

    try {
        server.setAttribute(name,att);
        result = server.getAttribute(name,attname);
    } catch(InvalidAttributeValueException iv) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspWrongValue);
    } catch (InstanceNotFoundException f) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (ReflectionException r) {
        throw new
            SnmpStatusException(SnmpStatusException.snmpRspInconsistentName);
    } catch (MBeanException m) {
        Exception t = m.getTargetException();
        if (t instanceof SnmpStatusException)
            throw (SnmpStatusException) t;
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    } catch (Exception e) {
        throw new
            SnmpStatusException(SnmpStatusException.noAccess);
    }

    return meta.buildSnmpValue(id,result);
}
 
Example 36
Project: openjdk-jdk10   File: MBeanExceptionTest.java   Source Code and License 5 votes vote down vote up
public Object getAttribute(String attrName)
        throws MBeanException {
    if (attrName.equals("UncheckedException"))
        throw theUncheckedException;
    else
        throw new AssertionError();
}
 
Example 37
Project: lams   File: SpringModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Sets managed resource to expose and stores its {@link ClassLoader}.
 */
@Override
public void setManagedResource(Object managedResource, String managedResourceType)
		throws MBeanException, InstanceNotFoundException, InvalidTargetObjectTypeException {

	this.managedResourceClassLoader = managedResource.getClass().getClassLoader();
	super.setManagedResource(managedResource, managedResourceType);
}
 
Example 38
Project: jdk8u-jdk   File: RequiredModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the instance handle of the object against which to
 * execute all methods in this ModelMBean management interface
 * (MBeanInfo and Descriptors).
 *
 * @param mr Object that is the managed resource
 * @param mr_type The type of reference for the managed resource.
 *     <br>Can be: "ObjectReference", "Handle", "IOR", "EJBHandle",
 *         or "RMIReference".
 *     <br>In this implementation only "ObjectReference" is supported.
 *
 * @exception MBeanException The initializer of the object has
 *            thrown an exception.
 * @exception InstanceNotFoundException The managed resource
 *            object could not be found
 * @exception InvalidTargetObjectTypeException The managed
 *            resource type should be "ObjectReference".
 * @exception RuntimeOperationsException Wraps a {@link
 *            RuntimeException} when setting the resource.
 **/
public void setManagedResource(Object mr, String mr_type)
    throws MBeanException, RuntimeOperationsException,
           InstanceNotFoundException, InvalidTargetObjectTypeException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setManagedResource(Object,String)","Entry");
    }

    // check that the mr_type is supported by this JMXAgent
    // only "objectReference" is supported
    if ((mr_type == null) ||
        (! mr_type.equalsIgnoreCase("objectReference"))) {
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
            MODELMBEAN_LOGGER.logp(Level.FINER,
                    RequiredModelMBean.class.getName(),
                "setManagedResource(Object,String)",
                "Managed Resource Type is not supported: " + mr_type);
        }
        throw new InvalidTargetObjectTypeException(mr_type);
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setManagedResource(Object,String)",
            "Managed Resource is valid");
    }
    managedResource = mr;

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setManagedResource(Object, String)", "Exit");
    }
}
 
Example 39
Project: monarch   File: MX4JModelMBean.java   Source Code and License 5 votes vote down vote up
public void load() throws MBeanException, RuntimeOperationsException, InstanceNotFoundException {
  PersisterMBean persister = findPersister();
  if (persister != null) {
    ModelMBeanInfo info = (ModelMBeanInfo) persister.load();
    setModelMBeanInfo(info);
  }
}
 
Example 40
Project: lams   File: BaseModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Send a <code>Notification</code> which contains the specified string
 * as a <code>jmx.modelmbean.generic</code> notification.
 *
 * @param message The message string to 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
 */
public void sendNotification(String message)
    throws MBeanException, RuntimeOperationsException {

    if (message == null)
        throw new RuntimeOperationsException
            (new IllegalArgumentException("Message is null"),
             "Message is null");
    Notification notification = new Notification
        ("jmx.modelmbean.generic", this, 1, message);
    sendNotification(notification);

}
 
Example 41
Project: OpenJSharp   File: DefaultMBeanServerInterceptor.java   Source Code and License 4 votes vote down vote up
public Object instantiate(String className) throws ReflectionException,
                                                   MBeanException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example 42
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 4 votes vote down vote up
@Override
public Object instantiate(String className) throws ReflectionException,
		MBeanException {
	return mbs.instantiate(className);
}
 
Example 43
Project: monarch   File: MBeanServerWrapper.java   Source Code and License 4 votes vote down vote up
@Override
public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
    InstanceAlreadyExistsException, MBeanException, NotCompliantMBeanException {
  checkDomain(name);
  return mbs.createMBean(className, name);
}
 
Example 44
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 4 votes vote down vote up
@Override
public void setAttribute(ObjectName name, Attribute attribute)
		throws InstanceNotFoundException, AttributeNotFoundException,
		InvalidAttributeValueException, MBeanException, ReflectionException {
	mbs.setAttribute(name, attribute);
}
 
Example 45
Project: hadoop-oss   File: MetricsDynamicMBeanBase.java   Source Code and License 4 votes vote down vote up
@Override
public Object getAttribute(String attributeName) throws AttributeNotFoundException,
    MBeanException, ReflectionException {
  if (attributeName == null || attributeName.isEmpty()) 
    throw new IllegalArgumentException();
  
  updateMbeanInfoIfMetricsListChanged();
  
  Object o = metricsRateAttributeMod.get(attributeName);
  if (o == null) {
    o = metricsRegistry.get(attributeName);
  }
  if (o == null)
    throw new AttributeNotFoundException();
  
  if (o instanceof MetricsIntValue)
    return ((MetricsIntValue) o).get();
  else if (o instanceof MetricsLongValue)
    return ((MetricsLongValue) o).get();
  else if (o instanceof MetricsTimeVaryingInt)
    return ((MetricsTimeVaryingInt) o).getPreviousIntervalValue();
  else if (o instanceof MetricsTimeVaryingLong)
    return ((MetricsTimeVaryingLong) o).getPreviousIntervalValue();
  else if (o instanceof MetricsTimeVaryingRate) {
    MetricsTimeVaryingRate or = (MetricsTimeVaryingRate) o;
    if (attributeName.endsWith(NUM_OPS))
      return or.getPreviousIntervalNumOps();
    else if (attributeName.endsWith(AVG_TIME))
      return or.getPreviousIntervalAverageTime();
    else if (attributeName.endsWith(MIN_TIME))
      return or.getMinTime();
    else if (attributeName.endsWith(MAX_TIME))
      return or.getMaxTime();
    else {
      MetricsUtil.LOG.error("Unexpected attribute suffix");
      throw new AttributeNotFoundException();
    }
  } else {
      MetricsUtil.LOG.error("unknown metrics type: " + o.getClass().getName());
      throw new AttributeNotFoundException();
  }
}
 
Example 46
Project: csap-core   File: JavaCommonCollector.java   Source Code and License 4 votes vote down vote up
private void collectTomcatConnections (	MBeanServerConnection mbeanConn, ServiceCollectionResults jmxResults,
										String serviceNamePort )
		throws IOException, MalformedObjectNameException, MBeanException,
		AttributeNotFoundException, InstanceNotFoundException, ReflectionException {
	String mbeanName;

	String tomcatJmxRoot = jmxResults.getServiceInstance().getTomcatJmxName();

	// **************** Tomcat connections
	mbeanName = tomcatJmxRoot + ":type=ThreadPool,name=*";
	Set<ObjectInstance> tomcatThreadPoolBeans = mbeanConn.queryMBeans(
		new ObjectName( mbeanName ), null );

	for ( ObjectInstance objectInstance : tomcatThreadPoolBeans ) {
		logger.debug( "Service: {} ObjectName: {}", serviceNamePort, objectInstance.getObjectName() );

		if ( jmxResults.getHttpConn() < 0 ) {
			// get rid of -10 init
			jmxResults.setHttpConn( 0 );
			jmxResults.setThreadsBusy( 0 );
			jmxResults.setThreadCount( 0 );
		}

		try {
			jmxResults.setHttpConn( jmxResults.getHttpConn() + (Long) mbeanConn.getAttribute(
				objectInstance.getObjectName(),
				"connectionCount" ) );
		} catch (Exception e) {
			// tomcat 6 might not have.
			logger.debug( "Failed to get jmx data for service: {} Reason: {}", serviceNamePort, e.getMessage() );
		}

		jmxResults.setThreadsBusy( jmxResults.getThreadsBusy() + (int) mbeanConn.getAttribute(
			objectInstance.getObjectName(),
			"currentThreadsBusy" ) );

		jmxResults.setThreadCount( jmxResults.getThreadCount() + (int) mbeanConn.getAttribute(
			objectInstance.getObjectName(),
			"currentThreadCount" ) );
	}
}
 
Example 47
Project: jdk8u-jdk   File: RequiredModelMBean.java   Source Code and License 4 votes vote down vote up
public void sendAttributeChangeNotification(Attribute inOldVal,
                                            Attribute inNewVal)
    throws MBeanException, RuntimeOperationsException {
    final String mth =
        "sendAttributeChangeNotification(Attribute, Attribute)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),mth,
            "Entry");
    }

    // do we really want to do this?
    if ((inOldVal == null) || (inNewVal == null))
        throw new RuntimeOperationsException(new
           IllegalArgumentException("Attribute object must not be null"),
           "Exception occurred trying to send " +
           "attribute change notification of a ModelMBean");


    if (!(inOldVal.getName().equals(inNewVal.getName())))
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Attribute names are not the same"),
            "Exception occurred trying to send " +
            "attribute change notification of a ModelMBean");


    Object newVal = inNewVal.getValue();
    Object oldVal = inOldVal.getValue();
    String className = "unknown";
    if (newVal != null)
        className = newVal.getClass().getName();
    if (oldVal != null)
        className = oldVal.getClass().getName();

    AttributeChangeNotification myNtfyObj = new
        AttributeChangeNotification(this,
                                    1,
                                    ((new Date()).getTime()),
                                    "AttributeChangeDetected",
                                    inOldVal.getName(),
                                    className,
                                    inOldVal.getValue(),
                                    inNewVal.getValue());

    sendAttributeChangeNotification(myNtfyObj);

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),mth,
            "Exit");
    }

}
 
Example 48
Project: jerrydog   File: MBeanFactory.java   Source Code and License 4 votes vote down vote up
/**
 * Create a new AjpConnector
 *
 * @param parent MBean Name of the associated parent component
 * @param address The IP address on which to bind
 * @param port TCP port number to listen on
 *
 * @exception Exception if an MBean cannot be created or registered
 */
public String createAjpConnector(String parent, String address, int port)
    throws Exception {

    Object retobj = null;

    try {

        // Create a new CoyoteConnector instance for AJP
        // use reflection to avoid j-t-c compile-time circular dependencies
        Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector");
        Constructor ct = cls.getConstructor(null);
        retobj = ct.newInstance(null);
        Class partypes1 [] = new Class[1];
        // Set address
        String str = new String();
        partypes1[0] = str.getClass();
        Method meth1 = cls.getMethod("setAddress", partypes1);
        Object arglist1[] = new Object[1];
        arglist1[0] = address;
        meth1.invoke(retobj, arglist1);
        // Set port number
        Class partypes2 [] = new Class[1];
        partypes2[0] = Integer.TYPE;
        Method meth2 = cls.getMethod("setPort", partypes2);
        Object arglist2[] = new Object[1];
        arglist2[0] = new Integer(port);
        meth2.invoke(retobj, arglist2);
        // set protocolHandlerClassName for AJP
        Class partypes3 [] = new Class[1];
        partypes3[0] = str.getClass();
        Method meth3 = cls.getMethod("setProtocolHandlerClassName", partypes3);
        Object arglist3[] = new Object[1];
        arglist3[0] = new String("org.apache.jk.server.JkCoyoteHandler");
        meth3.invoke(retobj, arglist3);

    } catch (Exception e) {
        throw new MBeanException(e);
    }

    // Add the new instance to its parent component
    ObjectName pname = new ObjectName(parent);
    Server server = ServerFactory.getServer();
    Service service = server.findService(pname.getKeyProperty("name"));
    service.addConnector((Connector)retobj);

    // Return the corresponding MBean name
    ManagedBean managed = registry.findManagedBean("CoyoteConnector");
    ObjectName oname =
        MBeanUtils.createObjectName(managed.getDomain(), (Connector)retobj);
    return (oname.toString());

}
 
Example 49
Project: openjdk-jdk10   File: RequiredModelMBean.java   Source Code and License 4 votes vote down vote up
public void removeAttributeChangeNotificationListener(
        NotificationListener inlistener, String inAttributeName)
    throws MBeanException, RuntimeOperationsException,
           ListenerNotFoundException {
    if (inlistener == null) throw new
        ListenerNotFoundException("Notification listener is null");

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE,
                RequiredModelMBean.class.getName(), "Entry");
    }


    if (attributeBroadcaster == null)
        throw new ListenerNotFoundException(
              "No attribute change notification listeners registered");


    MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
    boolean found = false;
    if ((attrInfo != null) && (attrInfo.length>0)) {
        for (int i=0; i<attrInfo.length; i++) {
            if (attrInfo[i].getName().equals(inAttributeName)) {
                found = true;
                break;
            }
        }
    }

    if ((!found) && (inAttributeName != null)) {
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Invalid attribute name"),
            "Exception occurred trying to remove "+
            "attribute change notification listener");
    }

    /* note: */
    /* this may be a problem if the same listener is registered for
       multiple attributes with multiple filters and/or handback
       objects.  It may remove all of them */

    attributeBroadcaster.removeNotificationListener(inlistener);

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }
}
 
Example 50
Project: openjdk-jdk10   File: GmbalMBeanNOPImpl.java   Source Code and License 4 votes vote down vote up
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException {

    // NO-OP
}
 
Example 51
Project: jdk8u-jdk   File: Monitor.java   Source Code and License 4 votes vote down vote up
Object getAttribute(MBeanServerConnection mbsc,
                    ObjectName object,
                    String attribute)
    throws AttributeNotFoundException,
           InstanceNotFoundException,
           MBeanException,
           ReflectionException,
           IOException {
    // Check for "ObservedAttribute" replacement.
    // This could happen if a thread A called setObservedAttribute()
    // while other thread B was in the middle of the monitor() method
    // and received the old observed attribute value.
    //
    final boolean lookupMBeanInfo;
    synchronized (this) {
        if (!isActive())
            throw new IllegalArgumentException(
                "The monitor has been stopped");
        if (!attribute.equals(getObservedAttribute()))
            throw new IllegalArgumentException(
                "The observed attribute has been changed");
        lookupMBeanInfo =
            (firstAttribute == null && attribute.indexOf('.') != -1);
    }

    // Look up MBeanInfo if needed
    //
    final MBeanInfo mbi;
    if (lookupMBeanInfo) {
        try {
            mbi = mbsc.getMBeanInfo(object);
        } catch (IntrospectionException e) {
            throw new IllegalArgumentException(e);
        }
    } else {
        mbi = null;
    }

    // Check for complex type attribute
    //
    final String fa;
    synchronized (this) {
        if (!isActive())
            throw new IllegalArgumentException(
                "The monitor has been stopped");
        if (!attribute.equals(getObservedAttribute()))
            throw new IllegalArgumentException(
                "The observed attribute has been changed");
        if (firstAttribute == null) {
            if (attribute.indexOf('.') != -1) {
                MBeanAttributeInfo mbaiArray[] = mbi.getAttributes();
                for (MBeanAttributeInfo mbai : mbaiArray) {
                    if (attribute.equals(mbai.getName())) {
                        firstAttribute = attribute;
                        break;
                    }
                }
                if (firstAttribute == null) {
                    String tokens[] = attribute.split("\\.", -1);
                    firstAttribute = tokens[0];
                    for (int i = 1; i < tokens.length; i++)
                        remainingAttributes.add(tokens[i]);
                    isComplexTypeAttribute = true;
                }
            } else {
                firstAttribute = attribute;
            }
        }
        fa = firstAttribute;
    }
    return mbsc.getAttribute(object, fa);
}
 
Example 52
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 4 votes vote down vote up
public Object instantiate(String className, ObjectName loaderName,
        Object[] params, String[] signature) throws ReflectionException,
                                                    MBeanException,
                                                    InstanceNotFoundException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example 53
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License 4 votes vote down vote up
public ObjectInstance createMBean(String className, ObjectName name)
throws ReflectionException, InstanceAlreadyExistsException,
        MBeanRegistrationException, MBeanException,
        NotCompliantMBeanException {
    return createMBean(className, name, null, null);
}
 
Example 54
Project: openjdk-jdk10   File: RequiredModelMBean.java   Source Code and License 4 votes vote down vote up
public void sendNotification(Notification ntfyObj)
    throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }

    if (ntfyObj == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException("notification object must not be "+
                                     "null"),
            "Exception occurred trying to send a notification from a "+
            "RequiredModelMBean");


    // log notification if specified in descriptor
    Descriptor ntfyDesc =
        modelMBeanInfo.getDescriptor(ntfyObj.getType(),"notification");
    Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();

    if (ntfyDesc != null) {
        String logging = (String) ntfyDesc.getFieldValue("log");

        if (logging == null) {
            if (mmbDesc != null)
                logging = (String) mmbDesc.getFieldValue("log");
        }

        if ((logging != null) &&
            (logging.equalsIgnoreCase("t") ||
             logging.equalsIgnoreCase("true"))) {

            String logfile = (String) ntfyDesc.getFieldValue("logfile");
            if (logfile == null) {
                if (mmbDesc != null)
                    logfile = (String)mmbDesc.getFieldValue("logfile");
            }
            if (logfile != null) {
                try {
                    writeToLog(logfile,"LogMsg: " +
                        ((new Date(ntfyObj.getTimeStamp())).toString())+
                        " " + ntfyObj.getType() + " " +
                        ntfyObj.getMessage() + " Severity = " +
                        (String)ntfyDesc.getFieldValue("severity"));
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.DEBUG)) {
                        MODELMBEAN_LOGGER.log(Level.DEBUG,
                                "Failed to log " +
                                ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    }
    if (generalBroadcaster != null) {
        generalBroadcaster.sendNotification(ntfyObj);
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE,
                "sendNotification sent provided notification object");
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }

}
 
Example 55
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 4 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className)
    throws ReflectionException, MBeanException {
    checkCreate(className);
    return getMBeanServer().instantiate(className);
}
 
Example 56
Project: tomcat7   File: BaseModelMBean.java   Source Code and License 4 votes vote down vote up
/**
 * 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);

}
 
Example 57
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 4 votes vote down vote up
private static void rethrowMaybeMBeanException(Throwable t)
        throws ReflectionException, MBeanException {
    if (t instanceof MBeanException)
        throw (MBeanException) t;
    rethrow(t);
}
 
Example 58
Project: OpenJSharp   File: RequiredModelMBean.java   Source Code and License 4 votes vote down vote up
public void sendAttributeChangeNotification(Attribute inOldVal,
                                            Attribute inNewVal)
    throws MBeanException, RuntimeOperationsException {
    final String mth =
        "sendAttributeChangeNotification(Attribute, Attribute)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),mth,
            "Entry");
    }

    // do we really want to do this?
    if ((inOldVal == null) || (inNewVal == null))
        throw new RuntimeOperationsException(new
           IllegalArgumentException("Attribute object must not be null"),
           "Exception occurred trying to send " +
           "attribute change notification of a ModelMBean");


    if (!(inOldVal.getName().equals(inNewVal.getName())))
        throw new RuntimeOperationsException(new
            IllegalArgumentException("Attribute names are not the same"),
            "Exception occurred trying to send " +
            "attribute change notification of a ModelMBean");


    Object newVal = inNewVal.getValue();
    Object oldVal = inOldVal.getValue();
    String className = "unknown";
    if (newVal != null)
        className = newVal.getClass().getName();
    if (oldVal != null)
        className = oldVal.getClass().getName();

    AttributeChangeNotification myNtfyObj = new
        AttributeChangeNotification(this,
                                    1,
                                    ((new Date()).getTime()),
                                    "AttributeChangeDetected",
                                    inOldVal.getName(),
                                    className,
                                    inOldVal.getValue(),
                                    inNewVal.getValue());

    sendAttributeChangeNotification(myNtfyObj);

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),mth,
            "Exit");
    }

}
 
Example 59
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 4 votes vote down vote up
/**
 * Call <code>checkCreate(className)</code>, then forward this method to the
 * wrapped object.
 */
public Object instantiate(String className, ObjectName loaderName)
    throws ReflectionException, MBeanException, InstanceNotFoundException {
    checkCreate(className);
    return getMBeanServer().instantiate(className, loaderName);
}
 
Example 60
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License 4 votes vote down vote up
public Object instantiate(
        String className, ObjectName loaderName,
        Object[] params, String[] signature)
throws ReflectionException, MBeanException, InstanceNotFoundException {

    if (params == null)
        params = new Object[0];
    if (signature == null)
        signature = new String[0];

    ClassLoader loader;
    if (loaderName == null)
        loader = this.getClass().getClassLoader();
    else if (loaderName.equals(clrName))
        loader = clr;
    else
        loader = (ClassLoader) getMBean(loaderName);

    Class<?> c;
    try {
        c = Class.forName(className, false, loader);
    } catch (ClassNotFoundException e) {
        throw new ReflectionException(e);
    }

    Constructor[] constrs = c.getConstructors();
    Constructor found = null;
    findconstr:
    for (Constructor constr : constrs) {
        Class<?>[] cTypes = constr.getParameterTypes();
        if (cTypes.length == signature.length) {
            for (int i = 0; i < cTypes.length; i++) {
                if (!cTypes[i].getName().equals(signature[i]))
                    continue findconstr;
            }
            found = constr;
            break findconstr;
        }
    }
    if (found == null) {
        Exception x = new NoSuchMethodException(
                className + Arrays.toString(signature));
        throw new ReflectionException(x);
    }
    return invokeSomething(found, null, params);
}