Java Code Examples for javax.management.AttributeNotFoundException

The following are top voted examples for showing how to use javax.management.AttributeNotFoundException. 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: OpenJSharp   File: PerInterface.java   Source Code and License 6 votes vote down vote up
Object getAttribute(Object resource, String attribute, Object cookie)
        throws AttributeNotFoundException,
               MBeanException,
               ReflectionException {

    final M cm = getters.get(attribute);
    if (cm == null) {
        final String msg;
        if (setters.containsKey(attribute))
            msg = "Write-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    return introspector.invokeM(cm, resource, (Object[]) null, cookie);
}
 
Example 2
Project: OpenJSharp   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 3
Project: OpenJSharp   File: RMIConnector.java   Source Code and License 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute="
            + attribute);

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 4
Project: hadoop   File: JMXGet.java   Source Code and License 6 votes vote down vote up
/**
 * get single value by key
 */
public String getValue(String key) throws Exception {

  Object val = null;

  for (ObjectName oname : hadoopObjectNames) {
    try {
      val = mbsc.getAttribute(oname, key);
    } catch (AttributeNotFoundException anfe) {
      /* just go to the next */
      continue;
    } catch (ReflectionException re) {
      if (re.getCause() instanceof NoSuchMethodException) {
        continue;
      }
    }
    err("Info: key = " + key + "; val = " +
        (val == null ? "null" : val.getClass()) + ":" + val);
    break;
  }

  return (val == null) ? "" : val.toString();
}
 
Example 5
Project: hadoop   File: TestSecondaryWebUi.java   Source Code and License 6 votes vote down vote up
@Test
public void testSecondaryWebUi()
        throws IOException, MalformedObjectNameException,
               AttributeNotFoundException, MBeanException,
               ReflectionException, InstanceNotFoundException {
  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  ObjectName mxbeanName = new ObjectName(
          "Hadoop:service=SecondaryNameNode,name=SecondaryNameNodeInfo");

  String[] checkpointDir = (String[]) mbs.getAttribute(mxbeanName,
          "CheckpointDirectories");
  Assert.assertArrayEquals(checkpointDir, snn.getCheckpointDirectories());
  String[] checkpointEditlogDir = (String[]) mbs.getAttribute(mxbeanName,
          "CheckpointEditlogDirectories");
  Assert.assertArrayEquals(checkpointEditlogDir,
          snn.getCheckpointEditlogDirectories());
}
 
Example 6
Project: jdk8u-jdk   File: PerInterface.java   Source Code and License 6 votes vote down vote up
Object getAttribute(Object resource, String attribute, Object cookie)
        throws AttributeNotFoundException,
               MBeanException,
               ReflectionException {

    final M cm = getters.get(attribute);
    if (cm == null) {
        final String msg;
        if (setters.containsKey(attribute))
            msg = "Write-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    return introspector.invokeM(cm, resource, (Object[]) null, cookie);
}
 
Example 7
Project: jdk8u-jdk   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 8
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 9
Project: jdk8u-jdk   File: RMIConnector.java   Source Code and License 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 10
Project: jdk8u-jdk   File: RMIConnectorLogAttributesTest.java   Source Code and License 6 votes vote down vote up
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
Example 11
Project: openjdk-jdk10   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: openjdk-jdk10   File: RMIConnector.java   Source Code and License 6 votes vote down vote up
public void setAttribute(ObjectName name,
        Attribute attribute)
        throws InstanceNotFoundException,
        AttributeNotFoundException,
        InvalidAttributeValueException,
        MBeanException,
        ReflectionException,
        IOException {

    if (logger.debugOn()) logger.debug("setAttribute",
            "name=" + name + ", attribute name="
            + attribute.getName());

    final MarshalledObject<Attribute> sAttribute =
            new MarshalledObject<Attribute>(attribute);
    final ClassLoader old = pushDefaultClassLoader();
    try {
        connection.setAttribute(name, sAttribute, delegationSubject);
    } catch (IOException ioe) {
        communicatorAdmin.gotIOException(ioe);

        connection.setAttribute(name, sAttribute, delegationSubject);
    } finally {
        popDefaultClassLoader(old);
    }
}
 
Example 13
Project: openjdk-jdk10   File: PerInterface.java   Source Code and License 6 votes vote down vote up
Object getAttribute(Object resource, String attribute, Object cookie)
        throws AttributeNotFoundException,
               MBeanException,
               ReflectionException {

    final M cm = getters.get(attribute);
    if (cm == null) {
        final String msg;
        if (setters.containsKey(attribute))
            msg = "Write-only attribute: " + attribute;
        else
            msg = "No such attribute: " + attribute;
        throw new AttributeNotFoundException(msg);
    }
    return introspector.invokeM(cm, resource, (Object[]) null, cookie);
}
 
Example 14
Project: openjdk-jdk10   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 15
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 16
Project: hashsdn-controller   File: DynamicWritableWrapper.java   Source Code and License 6 votes vote down vote up
@Override
public AttributeList setAttributes(final AttributeList attributes) {
    AttributeList result = new AttributeList();
    for (Object attributeObject : attributes) {
        Attribute attribute = (Attribute) attributeObject;
        try {
            setAttribute(attribute);
            result.add(attribute);
        } catch (final InvalidAttributeValueException | AttributeNotFoundException | MBeanException
                | ReflectionException e) {
            LOG.warn("Setting attribute {} failed on {}", attribute.getName(), moduleIdentifier, e);
            throw new IllegalArgumentException(
                    "Setting attribute failed - " + attribute.getName() + " on " + moduleIdentifier, e);
        }
    }
    return result;
}
 
Example 17
Project: openjdk-jdk10   File: RMIConnectorLogAttributesTest.java   Source Code and License 6 votes vote down vote up
private void doTest(JMXConnector connector) throws IOException,
MalformedObjectNameException, ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException,
MBeanException, NotCompliantMBeanException, InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException {
    MBeanServerConnection  mbsc = connector.getMBeanServerConnection();


    ObjectName objName = new ObjectName("com.redhat.test.jmx:type=NameMBean");
    System.out.println("DEBUG: Calling createMBean");
    mbsc.createMBean(Name.class.getName(), objName);

    System.out.println("DEBUG: Calling setAttributes");
    AttributeList attList = new AttributeList();
    attList.add(new Attribute("FirstName", ANY_NAME));
    attList.add(new Attribute("LastName", ANY_NAME));
    mbsc.setAttributes(objName, attList);
}
 
Example 18
Project: Pogamut3   File: DynamicProxy.java   Source Code and License 5 votes vote down vote up
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    try {
        return mbsc.getAttribute(objectName, attribute);
    } catch (Exception ex) {
        throw new MBeanException(ex);
    }
}
 
Example 19
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 20
Project: Pogamut3   File: FolderMBean.java   Source Code and License 5 votes vote down vote up
@Override
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    try {
        return folder.getProperty(attribute).getValue();
    } catch (IntrospectionException ex) {
        throw new MBeanException(ex);
    }
}
 
Example 21
Project: Pogamut3   File: FolderMBean.java   Source Code and License 5 votes vote down vote up
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    try {
        folder.getProperty(attribute.getName()).setValue(attribute.getValue());
    } catch (IntrospectionException ex) {
        throw new MBeanException(ex);
    }
}
 
Example 22
Project: tqdev-metrics   File: JmxReporter.java   Source Code and License 5 votes vote down vote up
@Override
public void setAttribute(Attribute attribute)
		throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
	if (attribute.getName().equals("enabled")) {
		registry.setEnabled((boolean) attribute.getValue());
	} else {
		throw new AttributeNotFoundException("No writable attribute has been found");
	}
}
 
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: lams   File: SpringModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Switches the {@link Thread#getContextClassLoader() context ClassLoader} for the
 * managed resources {@link ClassLoader} before allowing the invocation to occur.
 * @see javax.management.modelmbean.ModelMBean#getAttribute
 */
@Override
public Object getAttribute(String attrName)
		throws AttributeNotFoundException, MBeanException, ReflectionException {

	ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
	try {
		Thread.currentThread().setContextClassLoader(this.managedResourceClassLoader);
		return super.getAttribute(attrName);
	}
	finally {
		Thread.currentThread().setContextClassLoader(currentClassLoader);
	}
}
 
Example 25
Project: lams   File: SpringModelMBean.java   Source Code and License 5 votes vote down vote up
/**
 * Switches the {@link Thread#getContextClassLoader() context ClassLoader} for the
 * managed resources {@link ClassLoader} before allowing the invocation to occur.
 * @see javax.management.modelmbean.ModelMBean#setAttribute
 */
@Override
public void setAttribute(Attribute attribute)
		throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {

	ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
	try {
		Thread.currentThread().setContextClassLoader(this.managedResourceClassLoader);
		super.setAttribute(attribute);
	}
	finally {
		Thread.currentThread().setContextClassLoader(currentClassLoader);
	}
}
 
Example 26
Project: OpenJSharp   File: MBeanServerDelegateImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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");
}
 
Example 27
Project: OpenJSharp   File: MBeanSupport.java   Source Code and License 5 votes vote down vote up
public final void setAttribute(Attribute attribute)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {
    final String name = attribute.getName();
    final Object value = attribute.getValue();
    perInterface.setAttribute(resource, name, value, getCookie());
}
 
Example 28
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 29
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public Object getAttribute(ObjectName name, String attribute)
    throws
    MBeanException,
    AttributeNotFoundException,
    InstanceNotFoundException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getAttribute(name, attribute);
}
 
Example 30
Project: OpenJSharp   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
Example 31
Project: OpenJSharp   File: Monitor.java   Source Code and License 5 votes vote down vote up
Comparable<?> getComparableFromAttribute(ObjectName object,
                                         String attribute,
                                         Object value)
    throws AttributeNotFoundException {
    if (isComplexTypeAttribute) {
        Object v = value;
        for (String attr : remainingAttributes)
            v = Introspector.elementFromComplex(v, attr);
        return (Comparable<?>) v;
    } else {
        return (Comparable<?>) value;
    }
}
 
Example 32
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License 5 votes vote down vote up
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException {
    AttrMethods am = attrMap.get(attribute);
    if (am == null || am.getter == null)
        throw new AttributeNotFoundException(attribute);
    return invokeMethod(am.getter);
}
 
Example 33
Project: tqdev-metrics   File: JmxReporterTest.java   Source Code and License 5 votes vote down vote up
/**
 * Should throw exception on unknown key.
 *
 * @throws MBeanException
 *             the MBean exception
 * @throws AttributeNotFoundException
 *             the attribute not found exception
 * @throws ReflectionException
 *             the reflection exception
 */
@Test
public void shouldThrowExceptionOnUnknownKey()
		throws MBeanException, AttributeNotFoundException, ReflectionException {
	registry.increment("jdbc.Statement.Invocations", "update");
	try {
		readJmx("jdbc.Statement.Invocations", "select");
		Assert.fail("readJmx should have thrown an InvalidKeyException");
	} catch (Exception e) {
		assertThat(e.getClass().getSimpleName()).isEqualTo("InvalidKeyException");
	}
}
 
Example 34
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 35
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 36
Project: jdk8u-jdk   File: DefaultMBeanServerInterceptor.java   Source Code and License 5 votes vote down vote up
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
    }
}
 
Example 37
Project: jdk8u-jdk   File: MBeanServerDelegateImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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");
}
 
Example 38
Project: jdk8u-jdk   File: MBeanSupport.java   Source Code and License 5 votes vote down vote up
public final void setAttribute(Attribute attribute)
        throws AttributeNotFoundException,
               InvalidAttributeValueException,
               MBeanException,
               ReflectionException {
    final String name = attribute.getName();
    final Object value = attribute.getValue();
    perInterface.setAttribute(resource, name, value, getCookie());
}
 
Example 39
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public Object getAttribute(ObjectName name, String attribute)
    throws
    MBeanException,
    AttributeNotFoundException,
    InstanceNotFoundException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getAttribute(name, attribute);
}
 
Example 40
Project: jdk8u-jdk   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
Example 41
Project: openjdk-jdk10   File: OldMBeanServerTest.java   Source Code and License 5 votes vote down vote up
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException {
    String name = attribute.getName();
    AttrMethods am = attrMap.get(name);
    if (am == null || am.setter == null)
        throw new AttributeNotFoundException(name);
    invokeMethod(am.setter, attribute.getValue());
}
 
Example 42
Project: jdk8u-jdk   File: Monitor.java   Source Code and License 5 votes vote down vote up
Comparable<?> getComparableFromAttribute(ObjectName object,
                                         String attribute,
                                         Object value)
    throws AttributeNotFoundException {
    if (isComplexTypeAttribute) {
        Object v = value;
        for (String attr : remainingAttributes)
            v = Introspector.elementFromComplex(v, attr);
        return (Comparable<?>) v;
    } else {
        return (Comparable<?>) value;
    }
}
 
Example 43
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License 5 votes vote down vote up
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException {
    AttrMethods am = attrMap.get(attribute);
    if (am == null || am.getter == null)
        throw new AttributeNotFoundException(attribute);
    return invokeMethod(am.getter);
}
 
Example 44
Project: jdk8u-jdk   File: OldMBeanServerTest.java   Source Code and License 5 votes vote down vote up
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException {
    String name = attribute.getName();
    AttrMethods am = attrMap.get(name);
    if (am == null || am.setter == null)
        throw new AttributeNotFoundException(name);
    invokeMethod(am.setter, attribute.getValue());
}
 
Example 45
Project: jwala   File: JwalaAuthenticationProvider.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @param authentication
 * @return Authentication
 */
@Override
public Authentication authenticate(Authentication authentication) {
    Realm realm;
    Set<GrantedAuthority> auths = new HashSet<>();
    try {
        realm = getTomcatContextRealm();
        if(realm instanceof NullRealm) {
            throw new ProviderNotFoundException("No Realms configured for Jwala to Authenticate");
        }
        Principal principal = realm.authenticate(authentication.getName(),
                authentication.getCredentials().toString());
        if (principal == null) {
            throw new BadCredentialsException("Username or Password not found.");
        } else {
            if (principal instanceof GenericPrincipal) {
                String[] roles = ((GenericPrincipal) principal).getRoles();
                for (String role : roles) {
                    auths.add(new SimpleGrantedAuthority(role));
                }
            }
            GrantedAuthoritiesMapperImpl grantedAuthoritiesMapper = new GrantedAuthoritiesMapperImpl();
            return new UsernamePasswordAuthenticationToken(authentication.getName(),
                    authentication.getCredentials(), grantedAuthoritiesMapper.mapAuthorities(auths));
        }
    } catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
        LOGGER.error("Error getting realms", e);
        throw new ProviderNotFoundException(e.getMessage());
    }
}
 
Example 46
Project: jwala   File: JwalaAuthenticationProvider.java   Source Code and License 5 votes vote down vote up
/**
 *
 * @return Tomcat Realms
 * @throws AttributeNotFoundException
 * @throws InstanceNotFoundException
 * @throws MBeanException
 * @throws ReflectionException
 */
public Realm getTomcatContextRealm() throws AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    try {
        ObjectName name = new ObjectName("Catalina", "type", "Engine");
        Engine engine = (Engine) JwalaAuthenticationProvider.getmBeanServer().getAttribute(name, "managedResource");
        return engine.getRealm();
    } catch (MalformedObjectNameException ex) {
        LOGGER.error("Invalid Realm", ex);
    }
    return null;
}
 
Example 47
Project: openjdk-jdk10   File: DefaultMBeanServerInterceptor.java   Source Code and License 5 votes vote down vote up
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.TRACE)) {
        MBEANSERVER_LOGGER.log(Level.TRACE,
                "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
    }
}
 
Example 48
Project: openjdk-jdk10   File: MBeanServerDelegateImpl.java   Source Code and License 5 votes vote down vote up
/**
 * 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");
}
 
Example 49
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkRead()</code>, then forward this method to the
 * wrapped object.
 */
public Object getAttribute(ObjectName name, String attribute)
    throws
    MBeanException,
    AttributeNotFoundException,
    InstanceNotFoundException,
    ReflectionException {
    checkRead();
    return getMBeanServer().getAttribute(name, attribute);
}
 
Example 50
Project: openjdk-jdk10   File: MBeanServerAccessController.java   Source Code and License 5 votes vote down vote up
/**
 * Call <code>checkWrite()</code>, then forward this method to the
 * wrapped object.
 */
public void setAttribute(ObjectName name, Attribute attribute)
    throws
    InstanceNotFoundException,
    AttributeNotFoundException,
    InvalidAttributeValueException,
    MBeanException,
    ReflectionException {
    checkWrite();
    getMBeanServer().setAttribute(name, attribute);
}
 
Example 51
Project: openjdk-jdk10   File: Monitor.java   Source Code and License 5 votes vote down vote up
Comparable<?> getComparableFromAttribute(ObjectName object,
                                         String attribute,
                                         Object value)
    throws AttributeNotFoundException {
    if (isComplexTypeAttribute) {
        Object v = value;
        for (String attr : remainingAttributes)
            v = Introspector.elementFromComplex(v, attr);
        return (Comparable<?>) v;
    } else {
        return (Comparable<?>) value;
    }
}
 
Example 52
Project: Pogamut3   File: PogamutMBeanServer.java   Source Code and License 4 votes vote down vote up
@Override
public Object getAttribute(ObjectName name, String attribute)
		throws MBeanException, AttributeNotFoundException,
		InstanceNotFoundException, ReflectionException {
	return mbs.getAttribute(name, attribute);
}
 
Example 53
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 54
Project: Pogamut3   File: Test01_JMXLogCategories.java   Source Code and License 4 votes vote down vote up
@Test
public void receiveLogEventThroughJMX()
		throws InstanceAlreadyExistsException, MBeanRegistrationException,
		NotCompliantMBeanException, MalformedObjectNameException,
		PogamutException, MalformedURLException, IOException,
		InterruptedException, MBeanException, InstanceNotFoundException,
		AttributeNotFoundException, ReflectionException {
	
	final String testMsg = "TEST LOG MESSAGE FROM receiveLogEventThroughJMX()";
	
	ObjectName parentName = PogamutJMX.getObjectName("testDomain", "root", "test");
	
	
	// export the log on the MBean server
	ILogCategories logCategories = new LogCategories();
	
	String testLogCategoryNameStr = "testLogCategory";
	LogCategory testLog = logCategories.getCategory(testLogCategoryNameStr);
			
	JMXLogCategories jmxLogCategories = new JMXLogCategories(
			logCategories,
			Pogamut.getPlatform().getMBeanServer(),
			parentName
	);

	// connect through RMI and get the proxy
	MBeanServerConnection mbsc = Pogamut.getPlatform().getMBeanServerConnection();
	ObjectName logCatsName = jmxLogCategories.getJMXLogCategoriesName();
	
	// get the name of all log category names
	String[] catNames = (String[]) mbsc.getAttribute(logCatsName, "CategoryNames");		
	boolean found = false;
	for (String catName : catNames) {
		if (catName.equals(testLogCategoryNameStr)) {
			found = true;
			break;
		}
	}
	Assert.assertTrue(testLogCategoryNameStr + " must be among exported log category names", found);
	
	// get the object name for the test log category
	ObjectName testCategoryName = 
		(ObjectName) 
		mbsc.invoke(
			logCatsName, 
			"getJMXLogCategoryName", 
			new Object[]{ testLogCategoryNameStr }, 
			new String[] { "java.lang.String" }
		);
	
	// add the listener
	mbsc.addNotificationListener(testCategoryName,
		new NotificationListener() {

			public void handleNotification(Notification notification,
					Object handback) {
				receivedMessage = notification.getMessage();
				messageReceivedLatch.countDown();
			}
		}, null, this
	);

	// send log event
	if (testLog.isLoggable(Level.INFO)) testLog.info(testMsg);
	// wait
	messageReceivedLatch.await(30000, TimeUnit.MILLISECONDS);
	// compare
	assertTrue("Received message must contain testMsg", receivedMessage.contains(testMsg));
	
	System.out.println("---/// TEST OK ///---");
	
	Pogamut.getPlatform().close();
}
 
Example 55
Project: hadoop-oss   File: MetricsDynamicMBeanBase.java   Source Code and License 4 votes vote down vote up
@Override
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
    MBeanException, ReflectionException {
  throw new ReflectionException(new NoSuchMethodException("set" + attribute));
}
 
Example 56
Project: hadoop-oss   File: MetricsSourceAdapter.java   Source Code and License 4 votes vote down vote up
@Override
public void setAttribute(Attribute attribute)
    throws AttributeNotFoundException, InvalidAttributeValueException,
           MBeanException, ReflectionException {
  throw new UnsupportedOperationException("Metrics are read-only.");
}
 
Example 57
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 58
Project: oscm   File: SetConfigurationSetting.java   Source Code and License 4 votes vote down vote up
@Override
public synchronized Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException {
    return null;
}
 
Example 59
Project: rocketmq-flink-plugin   File: Client.java   Source Code and License 4 votes vote down vote up
public static void main(String[] args) throws IOException,
        MalformedObjectNameException, InstanceNotFoundException,
        AttributeNotFoundException, InvalidAttributeValueException,
        MBeanException, ReflectionException, IntrospectionException {
    String domainName = "MyMBean";
    int rmiPort = 1099;
    JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:"+rmiPort+"/"+domainName);
    // 可以类比HelloAgent.java中的那句:
    // JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
    JMXConnector jmxc = JMXConnectorFactory.connect(url);
    MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

    //print domains
    System.out.println("Domains:------------------");
    String domains[] = mbsc.getDomains();
    for(int i=0;i<domains.length;i++){
        System.out.println("\tDomain["+i+"] = "+domains[i]);
    }
    //MBean count
    System.out.println("MBean count = "+mbsc.getMBeanCount());
    //process attribute
    ObjectName mBeanName = new ObjectName(domainName+":name=HelloWorld");
    mbsc.setAttribute(mBeanName, new Attribute("Name","zzh"));//注意这里是Name而不是name
    System.out.println("Name = "+mbsc.getAttribute(mBeanName, "Name"));

    //接下去是执行Hello中的printHello方法,分别通过代理和rmi的方式执行
    //via proxy
    HelloMBean proxy = MBeanServerInvocationHandler.newProxyInstance(mbsc, mBeanName, HelloMBean.class, false);
    proxy.printHello();
    proxy.printHello("jizhi boy");
    //via rmi
    mbsc.invoke(mBeanName, "printHello", null, null);
    mbsc.invoke(mBeanName, "printHello", new String[]{"jizhi gril"}, new String[]{String.class.getName()});

    //get mbean information
    MBeanInfo info = mbsc.getMBeanInfo(mBeanName);
    System.out.println("Hello Class: "+info.getClassName());
    for(int i=0;i<info.getAttributes().length;i++){
        System.out.println("Hello Attribute:"+info.getAttributes()[i].getName());
    }
    for(int i=0;i<info.getOperations().length;i++){
        System.out.println("Hello Operation:"+info.getOperations()[i].getName());
    }

    //ObjectName of MBean
    System.out.println("all ObjectName:--------------");
    Set<ObjectInstance> set = mbsc.queryMBeans(null, null);
    for(Iterator<ObjectInstance> it = set.iterator();it.hasNext();){
        ObjectInstance oi = it.next();
        System.out.println("\t"+oi.getObjectName());
    }
    jmxc.close();
}
 
Example 60
Project: oscm   File: StartBillingRun.java   Source Code and License 4 votes vote down vote up
@Override
public synchronized String getAttribute(String name)
        throws AttributeNotFoundException {
    return null;
}