@Override public void setAttribute(Attribute attr) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { try { put(attr.getName(),attr.getValue()); } catch (Exception e) { throw new MBeanException(e); } }
private void throwExceptionWithTarget(String m, MBeanException e) { if (!ignoreErrors) { throw new GroovyRuntimeException(m + e, e.getTargetException()); } } }
ObjectName rmiRegistryNamingName = getRMIRegistryNamingName(); if (this.agentConfig.isRmiRegistryEnabled() && mBeanServer.isRegistered(rmiRegistryNamingName)) { String[] empty = new String[0]; mBeanServer.invoke(rmiRegistryNamingName, "stop", empty, empty); MBeanUtil.unregisterMBean(rmiRegistryNamingName); logger.warn(e.getMessage(), e); } catch (ReflectionException e) { logger.warn(e.getMessage(), e); } catch (MBeanException e) { logger.warn(e.getMessage(), e); if (mBeanServer.isRegistered(rmiConnectorServerName)) { MBeanUtil.unregisterMBean(rmiConnectorServerName);
/** * Create, register, and return an MBean for this * <code>ContextEnvironment</code> object. * * @param environment The ContextEnvironment to be managed * @return a new MBean * @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; }
@Override public void setAttribute(Attribute att) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException { Method setter = methods.get("set" + att.getName() + "/1"); if (setter == null) { throw new ReflectionException(null, "no setter for " + att); } try { setter.invoke(target, att.getValue()); } catch (Exception e) { throw new MBeanException(e, "error setting att " + att); } }
throw new RuntimeOperationsException(new IllegalArgumentException("attribute cannot be null")); try m = attributes[resolver.lookup(attribute.getName()).intValue()].setter; m.invoke(resource, new Object[]{attribute.getValue()}); throw new AttributeNotFoundException("Writable attribute '" + attribute.getName() + "' not found"); throw new AttributeNotFoundException("Writable attribute '" + attribute.getName() + "' not found"); throw new MBeanException((Exception) t, "Exception in MBean when setting attribute '" + attribute.getName() + "'"); throw new RuntimeErrorException((Error) t, "Error in MBean when setting attribute '" + attribute.getName() + "'"); throw new ReflectionException(e, "Exception in AttributeProvider for setting '" + attribute.getName() + "'"); throw new RuntimeErrorException(e, "Error in AttributeProvider for setting '" + attribute.getName() + "'");
@Test @DirtiesContext public void changeMessageHistoryPatterns() throws Exception { Set<ObjectInstance> mbeans = server.queryMBeans(null, null); boolean tested = false; for (ObjectInstance mbean : mbeans) { if (mbean.toString().contains("MessageHistoryConfigurer")) { ObjectName objectName = mbean.getObjectName(); try { server.setAttribute(objectName, new Attribute("ComponentNamePatternsString", "foo, bar")); fail("Exception expected"); } catch (MBeanException e) { assertThat(e.getTargetException(), instanceOf(IllegalStateException.class)); assertThat(e.getTargetException().getMessage(), containsString("cannot be changed")); } catch (Exception e) { throw e; } server.invoke(objectName, "stop", new Object[]{}, new String[]{}); server.setAttribute(objectName, new Attribute("ComponentNamePatternsString", "foo, bar")); assertEquals("bar,foo", server.getAttribute(objectName, "ComponentNamePatternsString")); tested = true; break; } } assertTrue(tested); }
InvalidAttributeValueException, MBeanException, ReflectionException { if (attribute == null) throw new RuntimeOperationsException(new IllegalArgumentException( "Attribute cannot be null.")); throw new AttributeNotFoundException( "ModelMBeanInfo is null"); if (logger.isEnabledFor(Logger.DEBUG)) logger.debug("ModelMBeanInfo is: " + info); String attrName = attribute.getName(); Object attrValue = attribute.getValue(); throw new AttributeNotFoundException( String.format("Cannot find ModelMBeanAttributeInfo for attribute %s", attrName)); throw new AttributeNotFoundException( String.format("Attribute %s is not writable", attrName)); sendAttributeChangeNotification(new Attribute(attrName, oldValue), attribute); throw (MBeanException) x; else throw new MBeanException(x);
@Override public double getSystemLoadAverage() throws MonitoringException { double result = 0; final MBeanServer mbeanServer = MBeanUtil.getMBeanServer(); try { result = (Double) mbeanServer.getAttribute(new ObjectName(JvmMBean.JVM_MBEAN_NAME), "SystemLoadAverage"); } catch (final MalformedObjectNameException e) { throw new MonitoringException(e.getMessage(), e); } catch (final MBeanException e) { throw new MonitoringException(e.getMessage(), e); } catch (final ReflectionException e) { throw new MonitoringException(e.getMessage(), e); } catch (final AttributeNotFoundException e) { throw new MonitoringException(e.getMessage(), e); } catch (final javax.management.InstanceNotFoundException e) { throw new MonitoringException(e.getMessage(), e); } return result; }
throw new RuntimeOperationsException(new IllegalArgumentException("attribute cannot be null")); throw new AttributeNotFoundException("Readable attribute '" + attribute + "' not found"); throw new AttributeNotFoundException("Readable attribute '" + attribute + "' not found"); throw new MBeanException((Exception) t, "Exception in MBean when getting attribute '" + attribute + "'"); throw new RuntimeErrorException((Error) t, "Error in MBean when getting attribute '" + attribute + "'"); throw new AttributeNotFoundException("Readable attribute '" + attribute + "' not found"); throw new ReflectionException(e, "Exception in AttributeProvider for getting '" + attribute + "'"); throw new RuntimeErrorException(e, "Error in AttributeProvider for getting '" + attribute + "'");
/** * Appends the given interceptor, provided by the client, to the existing interceptor chain and registers it as MBean. * @see #addInterceptor */ public void registerInterceptor(MBeanServerInterceptor interceptor, ObjectName name) throws MBeanException { // First, try register this interceptor. The call will use the old interceptor chain try { server.registerMBean(interceptor, name); addInterceptor(interceptor); } catch (Exception x) { throw new MBeanException(x, "Could not register interceptor with name " + name); } }
throw new MBeanException(new IllegalStateException( "MX4JModelMBean is not registered.")); if (server.isRegistered(objectName) && server.isInstanceOf(objectName, PersisterMBean.class.getName())) {
MBeanServer server = getMBeanServer(); if (server == null) throw new MBeanException(new IllegalStateException( "MX4JModelMBean is not registered.")); if (server.isRegistered(objectName)) { MBeanLogger l = new MBeanLogger(server, objectName); if (logger.isEnabledFor(Logger.DEBUG))
private Object invoke(JmxOperation operation, Object[] params) throws MBeanException, ReflectionException { try { String[] parameterNames = operation.getParameters().stream() .map(JmxOperationParameter::getName).toArray(String[]::new); Map<String, Object> arguments = getArguments(parameterNames, params); InvocationContext context = new InvocationContext(SecurityContext.NONE, arguments); Object result = operation.invoke(context); if (REACTOR_PRESENT) { result = ReactiveHandler.handle(result); } return this.responseMapper.mapResponse(result); } catch (InvalidEndpointRequestException ex) { throw new ReflectionException(new IllegalArgumentException(ex.getMessage()), ex.getMessage()); } catch (Exception ex) { throw new MBeanException(translateIfNecessary(ex), ex.getMessage()); } }
@Override public synchronized void setAttribute(Attribute attribute) throws InvalidAttributeValueException, MBeanException, AttributeNotFoundException { throw new MBeanException(new RuntimeException("BTrace attributes are read-only")); }
private void disablePersistanceOnTarget(String server) throws MBeanException { try { // get the mbean server for the given instance MBeanServerConnection mBeanServer = mPlatformContext.getMBeanServerConnection(server); if(mBeanServer == null) { return; } Attribute lAttribute = new Attribute(ENABLE_PERSISTENCE_ATTRIBUTE_NAME,new Boolean(false)); mBeanServer.setAttribute(mEventForwardObjcetName, lAttribute); } catch (Exception e) { throw new MBeanException(e); } }
@Override public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException { MAttribute a = this.attributes.get(name); if(null == a) { throw new AttributeNotFoundException("Attribute '" + name + "' not found in '" + bean.getClass() + "'"); } try{ Object value = a.valued().getValue(bean); if(a.isOpen()) { value = MConverts.convert(value, a.getOpenType()); } return value; }catch(ReflectException e) { throw new ReflectionException(e); }catch(Exception e) { throw new MBeanException(e); } }
throw new MBeanException(new ServiceNotFoundException( "Could not find target")); method = realTarget.getClass().getMethod(methodName, params); } catch (NoSuchMethodException x) { throw new ReflectionException(x); return value; } catch (IllegalAccessException x) { throw new ReflectionException(x); } catch (IllegalArgumentException x) { throw new MBeanException(x); } catch (InvocationTargetException x) { Throwable t = x.getTargetException(); if (t instanceof Error) throw new MBeanException(new RuntimeErrorException((Error) t)); else throw new MBeanException((Exception) t);
public static Object invoke(ObjectName objectName, String method, Object[] arguments, String[] signature) throws MBeanException { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); try { return mBeanServer.invoke(objectName, method, arguments, signature); } catch (InstanceNotFoundException | ReflectionException e) { throw new MBeanException(e); } }
/** * Obtain and return the value of a specific attribute of this MBean. * * @param name Name of the requested attribute * * @exception AttributeNotFoundException if this attribute is not * supported by this MBean * @exception MBeanException if the initializer of an object * throws an exception * @exception ReflectionException if a Java reflection exception * occurs when invoking the getter */ public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException { // Validate the input parameters if (name == null) throw new RuntimeOperationsException(new IllegalArgumentException( "Attribute name is null"), "Attribute name is null"); Object result = null; try { Connector connector = (Connector) getManagedResource(); result = IntrospectionUtils.getProperty(connector, name); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } return result; }