List of usage examples for javax.management MalformedObjectNameException getMessage
public String getMessage()
From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java
public static void registerMbean(Object mbean, MetricName name) { ObjectName on;// ww w .java 2 s . c om try { on = new ObjectName(name.getMBeanName()); } catch (MalformedObjectNameException e) { log.error("Failed to obtain object name for '" + name.getMBeanName() + "': " + e.getMessage(), e); return; } registerMbean(mbean, on); }
From source file:com.espertech.esper.metrics.jmx.CommonJMXUtil.java
public static void unregisterMbean(MetricName name) { ObjectName on;//from w ww. j a va 2 s . c o m try { on = new ObjectName(name.getMBeanName()); } catch (MalformedObjectNameException e) { log.error("Failed to obtain object name for '" + name.getMBeanName() + "': " + e.getMessage(), e); return; } unregisterMbean(on); }
From source file:gr.cslab.Metric_test.java
static public void addMetric(String name, String attribute, String label, String units) { Metric m = null;/*from www. j a va 2 s .c om*/ try { ObjectName OName = new ObjectName(name); m = new Metric(OName, attribute, label, units); } catch (MalformedObjectNameException ex) { System.err.println("ERROR: Malformed MBean name: " + name); System.err.println(ex.getMessage()); } if (m != null) metrics.add(m); }
From source file:org.hyperic.hq.plugin.websphere.WebsphereUtil.java
public static Object getRemoteMBeanValue(Metric metric, String attributeName) throws MetricNotFoundException, MetricUnreachableException, PluginException { AdminClient mServer = getMBeanServer(metric); ObjectName objName;// w w w . j av a 2 s .co m try { objName = new ObjectName(metric.getObjectName()); } catch (MalformedObjectNameException e) { throw new MetricInvalidException(e.getMessage(), e); } try { return mServer.getAttribute(objName, metric.getAttributeName()); } catch (MBeanException e) { String msg = "MBeanException: " + e.getMessage(); throw new PluginException(msg, e); } catch (AttributeNotFoundException e) { String msg = "Attribute '" + attributeName + "' " + "not found for '" + objName + "'"; throw new MetricNotFoundException(msg, e); } catch (InstanceNotFoundException e) { String msg = "MBean '" + objName + "' not found"; throw new MetricNotFoundException(msg, e); } catch (ReflectionException e) { String msg = "ReflectionException: " + e.getMessage(); throw new PluginException(msg, e); } catch (ConnectorException e) { String msg = "ConnectorException: " + e.getMessage(); throw new PluginException(msg, e); } }
From source file:org.hyperic.hq.plugin.websphere.WebsphereUtil.java
public static Object invoke(AdminClient mServer, String objectName, String method, Object[] args, String[] sig) throws PluginException { ObjectName obj;//w w w. ja v a 2 s .co m try { obj = new ObjectName(objectName); } catch (MalformedObjectNameException e) { throw new PluginException(e); } try { if (obj.isPattern()) { obj = resolve(mServer, obj); } return mServer.invoke(obj, method, args, sig); } catch (InstanceNotFoundException e) { throw new PluginException(e.getMessage(), e); } catch (MBeanException e) { throw new PluginException(e.getMessage(), e); } catch (ReflectionException e) { throw new PluginException(e.getMessage(), e); } catch (ConnectorException e) { throw new PluginException(e.getMessage(), e); } catch (IllegalArgumentException e) { throw new PluginException(e.getMessage(), e); } }
From source file:org.apache.geode.admin.jmx.internal.MBeanUtil.java
/** * Creates and registers a <code>ModelMBean</code> for the specified <code>ManagedResource</code>. * State changing callbacks into the <code>ManagedResource</code> will also be made. * * @param resource the ManagedResource to create a managing MBean for * @param managed the ManagedBean definition to create the MBean with * @see ManagedResource#setModelMBean/*from ww w . j a v a2 s. c om*/ */ static ObjectName createMBean(ManagedResource resource, ManagedBean managed) { try { DynamicManagedBean mb = new DynamicManagedBean(managed); resource.setModelMBean(mb.createMBean(resource)); // create the ObjectName and register the MBean... final ObjectName objName; try { objName = ObjectName.getInstance(resource.getMBeanName()); } catch (MalformedObjectNameException e) { throw new MalformedObjectNameException(LocalizedStrings.MBeanUtil_0_IN_1 .toLocalizedString(new Object[] { e.getMessage(), resource.getMBeanName() })); } synchronized (MBeanUtil.class) { // Only register a bean once. Otherwise, you risk race // conditions with things like the RMI connector accessing it. if (mbeanServer != null && !mbeanServer.isRegistered(objName)) { mbeanServer.registerMBean(resource.getModelMBean(), objName); synchronized (managedResources) { managedResources.put(objName, resource); } } } return objName; } catch (java.lang.Exception e) { throw new RuntimeAdminException(LocalizedStrings.MBeanUtil_FAILED_TO_CREATE_MBEAN_FOR_0 .toLocalizedString(new Object[] { resource.getMBeanName() }), e); } }
From source file:cc.kune.core.server.mbean.MBeanRegistry.java
/** * Register this object itself in the JVM MBean Server. * /* ww w . j a v a 2 s . c om*/ * @param object * the object * @param objectName * the object name */ public void registerAsMBean(final Object object, final String objectName) { ObjectName mbeanName = null; try { mbeanName = new ObjectName(objectName); } catch (final MalformedObjectNameException e) { LOG.error("Error creating MBean ObjectName: " + objectName + ", " + e.getMessage()); } catch (final NullPointerException e) { LOG.error("Error creating MBean ObjectName: " + objectName + ", " + e.getMessage()); } try { mbeanServer.registerMBean(object, mbeanName); } catch (final InstanceAlreadyExistsException e) { LOG.error("Error registering MBean: " + objectName + ", " + e.getMessage()); } catch (final MBeanRegistrationException e) { LOG.error("Error registering MBean: " + objectName + ", " + e.getMessage()); } catch (final NotCompliantMBeanException e) { LOG.error("Error registering MBean: " + objectName + ", " + e.getMessage()); } LOG.info("Registered " + objectName + " as MBean sucessfully"); }
From source file:org.apache.tajo.util.metrics.TajoJMXObjectNameFactory.java
@Override public ObjectName createName(String type, String domain, String name) { try {//from ww w .j av a 2 s . c o m StringBuilder sb = new StringBuilder(); sb.append(domain).append(":"); String[] nameSplit = name.split(SEPARATOR_RGX, 3); ObjectName objectName = null; if (nameSplit.length == 1) { objectName = new ObjectName(domain, "name", name); } else { for (int i = 0; i < nameSplit.length - 1 && i < jmxHierarchies.length; i++) { sb.append(jmxHierarchies[i]).append("=").append(nameSplit[i]).append(","); } sb.append("name=").append(nameSplit[nameSplit.length - 1]); objectName = new ObjectName(sb.toString()); } if (objectName.isPattern()) { objectName = new ObjectName(domain, "name", ObjectName.quote(name)); } return objectName; } catch (MalformedObjectNameException e) { try { return new ObjectName(domain, "name", ObjectName.quote(name)); } catch (MalformedObjectNameException e1) { if (LOG.isDebugEnabled()) { LOG.warn("Unable to register for " + type + " " + name + " " + e1.getMessage(), e1); } else { LOG.warn("Unable to register for " + type + " " + name + " " + e1.getMessage()); } throw new RuntimeException(e1); } } }
From source file:org.wso2.carbon.metrics.impl.ReporterTest.java
private AttributeList getAttributes(String name, String... attributeNames) { ObjectName n;//from ww w .j a va 2s . c o m try { n = new ObjectName("org.wso2.carbon.metrics", "name", name); return mBeanServer.getAttributes(n, attributeNames); } catch (MalformedObjectNameException e) { fail(e.getMessage()); } catch (InstanceNotFoundException e) { fail(e.getMessage()); } catch (ReflectionException e) { fail(e.getMessage()); } return null; }
From source file:org.rhq.plugins.jbosscache.JBossCacheSubsystemComponent.java
public CreateResourceReport createResource(CreateResourceReport report) { JBossASServerComponent parentResourceComponent = (JBossASServerComponent) ctx.getParentResourceComponent(); Configuration config = report.getResourceConfiguration(); String name = report.getUserSpecifiedResourceName(); // String name = config.getSimple("MBeanName").getStringValue(); // PropertySimple nameTemplateProp = report.getPluginConfiguration().getSimple("nameTemplate"); // String rName = nameTemplateProp.getStringValue(); //noinspection ConstantConditions // rName = rName.replace("{name}", name); // TODO check for duplcicate name/mbean // PropertySimple pluginNameProperty = new PropertySimple("name", rName); // ctx.getPluginConfiguration().put(pluginNameProperty); File deployDir = new File(parentResourceComponent.getConfigurationPath() + "/deploy"); File deploymentFile = new File(deployDir, FileNameUtility.formatFileName(name) + "-cache-service.xml"); String flavour = config.getSimple("Flavour").getStringValue(); boolean isTc = false; if (flavour != null && flavour.startsWith("tree")) isTc = true;/* w w w.j a v a 2 s .c om*/ String mbeanName = "jboss.cache:name=" + name; try { CacheConfigurationHelper helper = new CacheConfigurationHelper(); helper.writeConfig(deploymentFile, config, mbeanName, false); } catch (Exception ioe) { ioe.printStackTrace(); // TODO remove later report.setErrorMessage(ioe.getLocalizedMessage()); report.setException(ioe); report.setStatus(CreateResourceStatus.FAILURE); return report; } String objectName = mbeanName; if (isTc) objectName += ",treecache-interceptor=CacheMgmtInterceptor"; else objectName += ",cache-interceptor=CacheMgmtInterceptor"; try { ObjectName on = new ObjectName(objectName); objectName = on.getCanonicalName(); report.setResourceKey(objectName); } catch (MalformedObjectNameException e) { log.warn("Invalid key [" + objectName + "]: " + e.getMessage()); return report; } report.setResourceName(name); // TODO ok? or better objectName? // try { // parentResourceComponent.deployFile(deploymentFile); // } // catch (Exception e) { // JBossASServerComponent.setErrorOnCreateResourceReport(report, e.getLocalizedMessage(), e); // return report; // } report.setStatus(CreateResourceStatus.SUCCESS); return report; }