Example usage for javax.management ObjectName quote

List of usage examples for javax.management ObjectName quote

Introduction

In this page you can find the example usage for javax.management ObjectName quote.

Prototype

public static String quote(String s) 

Source Link

Document

Returns a quoted form of the given String, suitable for inclusion in an ObjectName.

Usage

From source file:io.fabric8.mq.util.BrokerJmxUtils.java

public static Hashtable<String, String> getProperties(String string) {
    Hashtable<String, String> result = new Hashtable<>();
    String[] props = string.split(",");
    for (String prop : props) {
        String[] keyValues = prop.split("=");
        result.put(keyValues[0].trim(), ObjectName.quote(keyValues[1].trim()));
    }//  ww  w.ja v a2 s .  com
    return result;
}

From source file:io.fabric8.mq.controller.util.BrokerJmxUtils.java

public static Hashtable<String, String> getProperties(String string) {
    Hashtable<String, String> result = new Hashtable<>();
    String[] props = string.split(",");
    for (int i = 0; i < props.length; i++) {
        String[] keyValues = props[i].split("=");
        result.put(keyValues[0].trim(), ObjectName.quote(keyValues[1].trim()));
    }/*from  ww  w . java 2 s.  co  m*/
    return result;
}

From source file:fr.xebia.springframework.jms.ManagedCachingConnectionFactory.java

public ObjectName getObjectName() throws MalformedObjectNameException {
    if (objectName == null) {
        objectName = ObjectName//from   w  w  w.  j av  a 2  s  .  c om
                .getInstance("javax.jms:type=CachingConnectionFactory,name=" + ObjectName.quote(this.beanName));
    }
    return objectName;
}

From source file:fr.xebia.springframework.jmx.ServletContextAwareObjectNamingStrategy.java

/**
 * <p>/*from w w  w  . ja  va  2 s .com*/
 * Compose <code>ObjectName</code> with underlying <code>objectNamingStrategy</code>'s
 * result and the following parameters: "<code>application=${servletcontextName},bean=${beanKey}</code>".
 * </p>
 */
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
    ObjectName objectName = this.objectNamingStrategy.getObjectName(managedBean, beanKey);
    String canonicalName = objectName.getCanonicalName();
    canonicalName += ",application=" + ObjectName.quote(this.servletContextName) + ",bean="
            + ObjectName.quote(beanKey);
    ObjectName result = ObjectName.getInstance(canonicalName);
    return result;
}

From source file:org.apache.tajo.util.metrics.TajoJMXObjectNameFactory.java

@Override
public ObjectName createName(String type, String domain, String name) {
    try {/*w w  w .  j  av  a 2s.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:fr.xebia.springframework.jms.ManagedDefaultMessageListenerContainer.java

public ObjectName getObjectName() throws MalformedObjectNameException {
    if (objectName == null) {
        String destinationName = getDestinationName();
        Destination destination = getDestination();
        if (destinationName == null && destination != null) {
            try {
                if (destination instanceof Queue) {
                    Queue queue = (Queue) destination;
                    destinationName = queue.getQueueName();

                } else if (destination instanceof Topic) {
                    Topic topic = (Topic) destination;
                    destinationName = topic.getTopicName();
                }//w  w w. j  a  v  a  2 s.  c  o m
            } catch (JMSException e) {
                throw new UncategorizedJmsException(e);
            }
        }
        objectName = ObjectName.getInstance("javax.jms:type=MessageListenerContainer,name="
                + ObjectName.quote(getBeanName()) + ",destination=" + destinationName);
    }
    return objectName;
}

From source file:org.mule.module.management.mbean.ServiceStats.java

@Override
public void postRegister(Boolean registrationDone) {
    super.postRegister(registrationDone);

    try {//from w ww .j av  a  2  s.c o m
        RouterStatistics is = statistics.getInboundRouterStat();
        if (is != null) {
            String quotedStatsName = ObjectName.quote(statistics.getName());
            inboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,service="
                    + quotedStatsName + ",router=inbound");

            // unregister old version if exists
            if (server.isRegistered(inboundName)) {
                server.unregisterMBean(inboundName);
            }
            server.registerMBean(new RouterStats(is), this.inboundName);
        }

        RouterStatistics os = this.statistics.getOutboundRouterStat();
        if (os != null) {
            String quotedStatsName = ObjectName.quote(statistics.getName());
            outboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,service="
                    + quotedStatsName + ",router=outbound");

            // unregister old version if exists
            if (server.isRegistered(outboundName)) {
                server.unregisterMBean(outboundName);
            }
            server.registerMBean(new RouterStats(os), this.outboundName);
        }
    } catch (Exception e) {
        LOGGER.error("Error post-registering MBean", e);
    }
}

From source file:com.fatwire.gst.web.status.StatusRequestListener.java

public void contextInitialized(ServletContextEvent sce) {
    String n = sce.getServletContext().getContextPath();
    if (n == null || n.length() == 0) {
        n = "/";//from w  ww  . ja  v a2  s  .  c om
    }

    requestCounter = new RequestCounter(n);
    ConcurrencyCounter<?, ?> old = ConcurrencyCounterLocator.getInstance().register(requestCounter);
    if (old != null) {
        requestCounter = (RequestCounter) old;
    }
    try {
        name = new ObjectName("com.fatwire.gst.web:type=RequestCounter,name=" + ObjectName.quote(n));
        ManagementFactory.getPlatformMBeanServer().registerMBean(new StatusCounter(requestCounter), name);
    } catch (Throwable e) {
        log.warn(e.getMessage(), e);
    }

}

From source file:org.rhq.plugins.jslee.ServiceSbbUsageParameterSetDiscoveryComponent.java

public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<ServiceSbbComponent> context)
        throws InvalidPluginConfigurationException, Exception {
    MBeanServerUtils mbeanUtils = context.getParentResourceComponent().getMBeanServerUtils();
    try {/*  w  w  w .j  a  va2 s. com*/
        if (log.isDebugEnabled()) {
            log.debug("RAEntityDiscoveryComponent.discoverResources() called");
        }
        Set<DiscoveredResourceDetails> discoveredUsageParameterSets = new HashSet<DiscoveredResourceDetails>();

        MBeanServerConnection connection = mbeanUtils.getConnection();
        mbeanUtils.login();

        ServiceID serviceId = context.getParentResourceComponent().getServiceID();

        // As an example, if a particular service has the name FooService, vendor FooCompany, and version 1.0,
        // then the Object Name of a ServiceUsageMBean for that service would be:
        // javax.slee.management.usage:type=ServiceUsage,serviceName="FooService", serviceVendor="FooCompany",serviceVersion="1.0"
        ObjectName serviceUsageON = new ObjectName(ServiceUsageMBean.BASE_OBJECT_NAME + ','
                + ServiceUsageMBean.SERVICE_NAME_KEY + '=' + ObjectName.quote(serviceId.getName()) + ','
                + ServiceUsageMBean.SERVICE_VENDOR_KEY + '=' + ObjectName.quote(serviceId.getVendor()) + ','
                + ServiceUsageMBean.SERVICE_VERSION_KEY + '=' + ObjectName.quote(serviceId.getVersion()));

        ServiceUsageMBean serviceUsageMBean = (ServiceUsageMBean) MBeanServerInvocationHandler.newProxyInstance(
                connection, serviceUsageON, javax.slee.management.ServiceUsageMBean.class, false);

        SbbID sbbId = context.getParentResourceComponent().getSbbID();
        String[] usageParameterSets = serviceUsageMBean.getUsageParameterSets(sbbId);

        // This is default one
        String defaultDescription = "Usage Parameter Set : " + "<default>" + " for " + sbbId + " @"
                + serviceId;
        String defaultKey = "<default>" + "@" + sbbId + "@" + serviceId;

        DiscoveredResourceDetails defaultDiscoveredEntity = new DiscoveredResourceDetails(
                context.getResourceType(), defaultKey, "<default>" + " Usage Paramaters Set",
                sbbId.getVersion(), defaultDescription, null, null);
        defaultDiscoveredEntity.getPluginConfiguration()
                .put(new PropertySimple("usageParameterSet", "<default>"));
        defaultDiscoveredEntity.getPluginConfiguration().put(new PropertySimple("name", sbbId.getName()));
        defaultDiscoveredEntity.getPluginConfiguration().put(new PropertySimple("version", sbbId.getVersion()));
        defaultDiscoveredEntity.getPluginConfiguration().put(new PropertySimple("vendor", sbbId.getVendor()));
        discoveredUsageParameterSets.add(defaultDiscoveredEntity);

        for (String usageParameterSet : usageParameterSets) {
            String description = "Usage Parameter Set : " + usageParameterSet + " for " + sbbId + " @"
                    + serviceId;
            String key = usageParameterSet + "@" + sbbId + "@" + serviceId;

            DiscoveredResourceDetails discoveredEntity = new DiscoveredResourceDetails(
                    context.getResourceType(), key, usageParameterSet + " Usage Paramaters Set",
                    sbbId.getVersion(), description, null, null);
            discoveredEntity.getPluginConfiguration()
                    .put(new PropertySimple("usageParameterSet", usageParameterSet));
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("name", sbbId.getName()));
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("version", sbbId.getVersion()));
            discoveredEntity.getPluginConfiguration().put(new PropertySimple("vendor", sbbId.getVendor()));
            discoveredUsageParameterSets.add(discoveredEntity);
        }

        if (log.isInfoEnabled()) {
            log.info("Discovered " + discoveredUsageParameterSets.size()
                    + " JAIN SLEE Usage Parameter Sets for " + sbbId + " @" + serviceId + ".");
        }
        return discoveredUsageParameterSets;
    } finally {
        try {
            mbeanUtils.logout();
        } catch (LoginException e) {
            if (log.isDebugEnabled()) {
                log.debug("Failed to logout from secured JMX", e);
            }
        }
    }
}

From source file:fr.xebia.management.maven.WebApplicationMavenInformation.java

public ObjectName getObjectName() throws MalformedObjectNameException {
    if (objectName == null) {
        String objectNameString = jmxDomain + ":type=WebApplicationMavenInformation";
        if (StringUtils.hasText(this.beanName)) {
            objectNameString += ",name=" + ObjectName.quote(this.beanName);
        }//from   w w w. j  a  va 2 s  . co m
        objectName = ObjectName.getInstance(objectNameString);
    }
    return objectName;
}