Search in sources :

Example 36 with JMException

use of javax.management.JMException in project fabric8 by fabric8io.

the class ManagedApiFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
    InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
    if (iMgr != null) {
        try {
            iMgr.register(mApi);
            ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
            if (slcMgr != null) {
                slcMgr.registerListener(mApi);
                slcMgr.startServer(server);
            }
        } catch (JMException jmex) {
            jmex.printStackTrace();
            LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
        }
    }
}
Also used : ServerLifeCycleManager(org.apache.cxf.endpoint.ServerLifeCycleManager) JMException(javax.management.JMException) InstrumentationManager(org.apache.cxf.management.InstrumentationManager)

Example 37 with JMException

use of javax.management.JMException in project presto by prestodb.

the class JmxMetadata method getJmxTableHandle.

private JmxTableHandle getJmxTableHandle(SchemaTableName tableName) {
    try {
        String objectNamePattern = toPattern(tableName.getTableName().toLowerCase(ENGLISH));
        List<ObjectName> objectNames = mbeanServer.queryNames(WILDCARD, null).stream().filter(name -> name.getCanonicalName().toLowerCase(ENGLISH).matches(objectNamePattern)).collect(toImmutableList());
        if (objectNames.isEmpty()) {
            return null;
        }
        List<JmxColumnHandle> columns = new ArrayList<>();
        columns.add(new JmxColumnHandle(NODE_COLUMN_NAME, createUnboundedVarcharType()));
        columns.add(new JmxColumnHandle(OBJECT_NAME_NAME, createUnboundedVarcharType()));
        for (ObjectName objectName : objectNames) {
            MBeanInfo mbeanInfo = mbeanServer.getMBeanInfo(objectName);
            getColumnHandles(mbeanInfo).forEach(columns::add);
        }
        // Since this method is being called on all nodes in the cluster, we must ensure (by sorting)
        // that attributes are in the same order on all of them.
        columns = columns.stream().distinct().sorted(comparing(JmxColumnHandle::getColumnName)).collect(toImmutableList());
        return new JmxTableHandle(tableName, objectNames.stream().map(ObjectName::toString).collect(toImmutableList()), columns, true);
    } catch (JMException e) {
        return null;
    }
}
Also used : Arrays(java.util.Arrays) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) MBeanAttributeInfo(javax.management.MBeanAttributeInfo) SchemaTableName(com.facebook.presto.spi.SchemaTableName) Map(java.util.Map) Splitter(com.google.common.base.Splitter) ENGLISH(java.util.Locale.ENGLISH) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) WILDCARD(javax.management.ObjectName.WILDCARD) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) ObjectName(javax.management.ObjectName) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) ConnectorSession(com.facebook.presto.spi.ConnectorSession) MalformedObjectNameException(javax.management.MalformedObjectNameException) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Stream(java.util.stream.Stream) JMException(javax.management.JMException) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Builder(com.google.common.collect.ImmutableList.Builder) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) MBeanServer(javax.management.MBeanServer) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) Comparator.comparing(java.util.Comparator.comparing) Type(com.facebook.presto.common.type.Type) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Constraint(com.facebook.presto.spi.Constraint) Maps(com.google.common.collect.Maps) MBeanInfo(javax.management.MBeanInfo) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) Collectors.toList(java.util.stream.Collectors.toList) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) MBeanInfo(javax.management.MBeanInfo) ArrayList(java.util.ArrayList) JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 38 with JMException

use of javax.management.JMException in project kafka by apache.

the class AppInfoParser method unregisterAppInfo.

public static synchronized void unregisterAppInfo(String prefix, String id, Metrics metrics) {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    try {
        ObjectName name = new ObjectName(prefix + ":type=app-info,id=" + Sanitizer.jmxSanitize(id));
        if (server.isRegistered(name))
            server.unregisterMBean(name);
        unregisterMetrics(metrics);
    } catch (JMException e) {
        log.warn("Error unregistering AppInfo mbean", e);
    } finally {
        log.info("App info {} for {} unregistered", prefix, id);
    }
}
Also used : JMException(javax.management.JMException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 39 with JMException

use of javax.management.JMException in project kafka by apache.

the class AppInfoParser method registerAppInfo.

public static synchronized void registerAppInfo(String prefix, String id, Metrics metrics, long nowMs) {
    try {
        ObjectName name = new ObjectName(prefix + ":type=app-info,id=" + Sanitizer.jmxSanitize(id));
        AppInfo mBean = new AppInfo(nowMs);
        ManagementFactory.getPlatformMBeanServer().registerMBean(mBean, name);
        // prefix will be added later by JmxReporter
        registerMetrics(metrics, mBean);
    } catch (JMException e) {
        log.warn("Error registering AppInfo mbean", e);
    }
}
Also used : JMException(javax.management.JMException) ObjectName(javax.management.ObjectName)

Example 40 with JMException

use of javax.management.JMException in project wildfly by wildfly.

the class EndpointService method registerEndpoint.

private void registerEndpoint(final Endpoint endpoint) {
    MBeanServer mbeanServer = serverConfigService.get().getMbeanServer();
    if (mbeanServer != null) {
        try {
            ManagedEndpoint jmxEndpoint = new ManagedEndpoint(endpoint, mbeanServer);
            mbeanServer.registerMBean(jmxEndpoint, endpoint.getName());
        } catch (final JMException ex) {
            WSLogger.ROOT_LOGGER.trace("Cannot register endpoint in JMX server", ex);
            WSLogger.ROOT_LOGGER.cannotRegisterEndpoint(endpoint.getShortName());
        }
    } else {
        WSLogger.ROOT_LOGGER.mBeanServerNotAvailable(endpoint.getShortName());
    }
}
Also used : JMException(javax.management.JMException) ManagedEndpoint(org.jboss.ws.common.management.ManagedEndpoint) MBeanServer(javax.management.MBeanServer)

Aggregations

JMException (javax.management.JMException)114 ObjectName (javax.management.ObjectName)65 MBeanServer (javax.management.MBeanServer)35 IOException (java.io.IOException)21 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)13 MalformedObjectNameException (javax.management.MalformedObjectNameException)12 MBeanInfo (javax.management.MBeanInfo)10 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)8 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 StandardMBean (javax.management.StandardMBean)7 RequiredModelMBean (javax.management.modelmbean.RequiredModelMBean)6 Date (java.util.Date)5 Attribute (javax.management.Attribute)5 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)5 Element (org.w3c.dom.Element)5 PostConstruct (javax.annotation.PostConstruct)4 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)4