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); }
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); } }
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); } }
/** * 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(); }
@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()); }
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); }
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); } }
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); }
@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); } }
@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; }
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { try { return mbsc.getAttribute(objectName, attribute); } catch (Exception ex) { throw new MBeanException(ex); } }
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { try { mbsc.setAttribute(objectName, attribute); } catch (Exception ex) { throw new MBeanException(ex); } }
@Override public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { try { return folder.getProperty(attribute).getValue(); } catch (IntrospectionException ex) { throw new MBeanException(ex); } }
@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); } }
@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"); } }
@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(); } }
/** * 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); } }
/** * 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); } }
/** * 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"); }
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()); }
/** * 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"); } }
/** * 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); }
/** * 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); }
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; } }
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); }
/** * 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"); } }
@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); }
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 } }