List of usage examples for javax.management MBeanException MBeanException
public MBeanException(java.lang.Exception e)
MBeanException
that wraps the actual java.lang.Exception
. From source file:org.parallelj.launching.transport.jmx.DynamicLegacyProgram.java
/** * Initialize the JobDataMap with the Program arguments * //from w w w.j a va2s. co m * @param job * The JobDetail for the JobDataMap initialization * @param params * The parameters Objects for the Program * @param signature * The parameters type * @throws MBeanException * If an error appends when initializing the JobDataMap */ protected Map<String, Object> buildJobDataMap(final JmxCommand jmxCommand, final Object[] params) throws MBeanException { final Map<String, Object> jobDataMap = new HashMap<String, Object>(); try { int ind = 0; // Options are before the AdapterArguments for (JmxOption option : JmxOptions.getOptions()) { option.process(jobDataMap, String.valueOf(params[ind++])); } for (Argument arg : this.remoteProgram.getArguments()) { arg.setValueUsingParser(String.valueOf(params[ind++])); } } catch (Exception e) { throw new MBeanException(e); } return jobDataMap; }
From source file:catalina.mbeans.ContextEnvironmentMBean.java
/** * Set the value of a specific attribute of this MBean. * * @param attribute The identification of the attribute to be set * and the new value/*ww w .j a v a 2s. c o m*/ * * @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 void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { super.setAttribute(attribute); ContextEnvironment ce = null; try { ce = (ContextEnvironment) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } // cannot use side-efects. It's removed and added back each time // there is a modification in a resource. NamingResources nr = ce.getNamingResources(); nr.removeEnvironment(ce.getName()); nr.addEnvironment(ce); }
From source file:catalina.mbeans.ContextResourceLinkMBean.java
/** * Set the value of a specific attribute of this MBean. * * @param attribute The identification of the attribute to be set * and the new value// w w w. j av a 2 s . c o m * * @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 void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { super.setAttribute(attribute); ContextResourceLink crl = null; try { crl = (ContextResourceLink) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } // cannot use side-efects. It's removed and added back each time // there is a modification in a resource. NamingResources nr = crl.getNamingResources(); nr.removeResourceLink(crl.getName()); nr.addResourceLink(crl); }
From source file:catalina.mbeans.ContextResourceMBean.java
/** * 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/*from w w w.jav a 2 s . c o m*/ * @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"); ContextResource cr = null; try { cr = (ContextResource) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } String value = null; if ("auth".equals(name)) { return (cr.getAuth()); } else if ("description".equals(name)) { return (cr.getDescription()); } else if ("name".equals(name)) { return (cr.getName()); } else if ("scope".equals(name)) { return (cr.getScope()); } else if ("type".equals(name)) { return (cr.getType()); } else { NamingResources nr = cr.getNamingResources(); if (nr == null) { throw new AttributeNotFoundException("Cannot find naming resource " + cr.getName()); } ResourceParams rp = nr.findResourceParams(cr.getName()); if (rp == null) { throw new AttributeNotFoundException("Cannot find resource param " + cr.getName()); } value = (String) rp.getParameters().get(name); if (value == null) { throw new AttributeNotFoundException("Cannot find attribute " + name + rp); } } return value; }
From source file:com.wakacommerce.common.cache.StatisticsServiceImpl.java
@Override public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException { if (actionName.equals("activate")) { activateLogging();/* w ww . java 2 s. co m*/ return null; } else if (actionName.equals("disable")) { disableLogging(); return null; } throw new MBeanException(new RuntimeException("Not Supported")); }
From source file:org.eclipse.gyrex.monitoring.internal.mbeans.MetricSetMBean.java
@Override public Object getAttribute(final String attributeName) throws AttributeNotFoundException, MBeanException, ReflectionException { if (ID.equals(attributeName)) { return metricSet.getId(); } else if (DESCRIPTION.equals(attributeName)) { return metricSet.getDescription(); } else if (PROPERTIES.equals(attributeName)) { return properties; } else if (metricTypesByAttributeName.containsKey(attributeName)) { final CompositeType type = metricTypesByAttributeName.get(attributeName); final BaseMetric metric = metricByAttributeName.get(attributeName); if ((type != null) && (metric != null)) { final Map<String, ?> rawValues = metric.getAttributeValues(); final String[] metricAttributeNames = type.keySet().toArray(new String[0]); final Object[] metricValues = new Object[metricAttributeNames.length]; for (int i = 0; i < metricValues.length; i++) { Object rawValue = rawValues.get(metricAttributeNames[i]); // convert if necessary if (null != rawValue) { final OpenType detectedTyp = detectType(rawValue.getClass()); if ((SimpleType.STRING == detectedTyp) && !(rawValue instanceof String)) { rawValue = String.valueOf(rawValue); }/* ww w .jav a2s .co m*/ } metricValues[i] = rawValue; } try { return new CompositeDataSupport(type, metricAttributeNames, metricValues); } catch (final OpenDataException e) { throw new MBeanException(e); } } } throw new AttributeNotFoundException(String.format("attribute %s not found", attributeName)); }
From source file:org.jolokia.http.HttpRequestHandlerTest.java
@Test public void requestErrorHandling() throws MalformedObjectNameException, InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException { Object[] exceptions = new Object[] { new ReflectionException(new NullPointerException()), 404, 500, new InstanceNotFoundException(), 404, 500, new MBeanException(new NullPointerException()), 500, 500, new AttributeNotFoundException(), 404, 500, new UnsupportedOperationException(), 500, 500, new IOException(), 500, 500, new IllegalArgumentException(), 400, 400, new SecurityException(), 403, 403, new RuntimeMBeanException(new NullPointerException()), 500, 500 }; for (int i = 0; i < exceptions.length; i += 3) { Exception e = (Exception) exceptions[i]; reset(backend);//from w w w. ja v a 2 s.c o m expect(backend.isDebug()).andReturn(true).anyTimes(); backend.error(find("" + exceptions[i + 1]), EasyMock.<Throwable>anyObject()); backend.error(find("" + exceptions[i + 2]), EasyMock.<Throwable>anyObject()); expect(backend.handleRequest(EasyMock.<JmxRequest>anyObject())).andThrow(e); replay(backend); JSONObject resp = (JSONObject) handler.handleGetRequest("/jolokia", "/read/java.lang:type=Memory/HeapMemoryUsage", null); assertEquals(resp.get("status"), exceptions[i + 1]); resp = handler.handleThrowable(e); assertEquals(resp.get("status"), exceptions[i + 2], e.getClass().getName()); } }
From source file:catalina.mbeans.ContextResourceMBean.java
/** * Set the value of a specific attribute of this MBean. * * @param attribute The identification of the attribute to be set * and the new value//from w w w .j a v a2 s . c o m * * @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 void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException { // Validate the input parameters if (attribute == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null"); String name = attribute.getName(); Object value = attribute.getValue(); if (name == null) throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null"); ContextResource cr = null; try { cr = (ContextResource) getManagedResource(); } catch (InstanceNotFoundException e) { throw new MBeanException(e); } catch (InvalidTargetObjectTypeException e) { throw new MBeanException(e); } if ("auth".equals(name)) { cr.setAuth((String) value); } else if ("description".equals(name)) { cr.setDescription((String) value); } else if ("name".equals(name)) { cr.setName((String) value); } else if ("scope".equals(name)) { cr.setScope((String) value); } else if ("type".equals(name)) { cr.setType((String) value); } else { ResourceParams rp = cr.getNamingResources().findResourceParams(cr.getName()); if (rp != null) { String valueStr = "" + value; rp.addParameter(name, valueStr); cr.getNamingResources().removeResourceParams(cr.getName()); } else { rp = new ResourceParams(); rp.setName(cr.getName()); String valueStr = "" + value; rp.addParameter(name, valueStr); } cr.getNamingResources().addResourceParams(rp); } // cannot use side-efects. It's removed and added back each time // there is a modification in a resource. NamingResources nr = cr.getNamingResources(); nr.removeResource(cr.getName()); nr.addResource(cr); }
From source file:catalina.mbeans.MBeanUtils.java
/** * Create, register, and return an MBean for this * <code>Connector</code> object. * * @param connector The Connector to be managed * * @exception Exception if an MBean cannot be created or registered *///from w w w . ja v a 2 s .co m public static ModelMBean createMBean(Connector connector) throws Exception { String mname = createManagedName(connector); 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(connector); ObjectName oname = createObjectName(domain, connector); mserver.registerMBean(mbean, oname); return (mbean); }
From source file:catalina.mbeans.MBeanUtils.java
/** * 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 *///from w w w.j av a 2 s .c om 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); }