Search in sources :

Example 81 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedRoute method dumpRouteStatsAsXml.

public String dumpRouteStatsAsXml(boolean fullStats, boolean includeProcessors) throws Exception {
    // in this logic we need to calculate the accumulated processing time for the processor in the route
    // and hence why the logic is a bit more complicated to do this, as we need to calculate that from
    // the bottom -> top of the route but this information is valuable for profiling routes
    StringBuilder sb = new StringBuilder();
    // need to calculate this value first, as we need that value for the route stat
    Long processorAccumulatedTime = 0L;
    // gather all the processors for this route, which requires JMX
    if (includeProcessors) {
        sb.append("  <processorStats>\n");
        MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
        if (server != null) {
            // get all the processor mbeans and sort them accordingly to their index
            String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
            ObjectName query = ObjectName.getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
            Set<ObjectName> names = server.queryNames(query, null);
            List<ManagedProcessorMBean> mps = new ArrayList<ManagedProcessorMBean>();
            for (ObjectName on : names) {
                ManagedProcessorMBean processor = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedProcessorMBean.class);
                // the processor must belong to this route
                if (getRouteId().equals(processor.getRouteId())) {
                    mps.add(processor);
                }
            }
            mps.sort(new OrderProcessorMBeans());
            // walk the processors in reverse order, and calculate the accumulated total time
            Map<String, Long> accumulatedTimes = new HashMap<String, Long>();
            Collections.reverse(mps);
            for (ManagedProcessorMBean processor : mps) {
                processorAccumulatedTime += processor.getTotalProcessingTime();
                accumulatedTimes.put(processor.getProcessorId(), processorAccumulatedTime);
            }
            // and reverse back again
            Collections.reverse(mps);
            // and now add the sorted list of processors to the xml output
            for (ManagedProcessorMBean processor : mps) {
                sb.append("    <processorStat").append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\"", processor.getProcessorId(), processor.getIndex(), processor.getState()));
                // do we have an accumulated time then append that
                Long accTime = accumulatedTimes.get(processor.getProcessorId());
                if (accTime != null) {
                    sb.append(" accumulatedProcessingTime=\"").append(accTime).append("\"");
                }
                // use substring as we only want the attributes
                sb.append(" ").append(processor.dumpStatsAsXml(fullStats).substring(7)).append("\n");
            }
        }
        sb.append("  </processorStats>\n");
    }
    // route self time is route total - processor accumulated total)
    long routeSelfTime = getTotalProcessingTime() - processorAccumulatedTime;
    if (routeSelfTime < 0) {
        // ensure we don't calculate that as negative
        routeSelfTime = 0;
    }
    StringBuilder answer = new StringBuilder();
    answer.append("<routeStat").append(String.format(" id=\"%s\"", route.getId())).append(String.format(" state=\"%s\"", getState()));
    // use substring as we only want the attributes
    String stat = dumpStatsAsXml(fullStats);
    answer.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");
    answer.append(" selfProcessingTime=\"").append(routeSelfTime).append("\"");
    InFlightKey oldestInflightEntry = getOldestInflightEntry();
    if (oldestInflightEntry == null) {
        answer.append(" oldestInflightExchangeId=\"\"");
        answer.append(" oldestInflightDuration=\"\"");
    } else {
        answer.append(" oldestInflightExchangeId=\"").append(oldestInflightEntry.exchangeId).append("\"");
        answer.append(" oldestInflightDuration=\"").append(System.currentTimeMillis() - oldestInflightEntry.timeStamp).append("\"");
    }
    answer.append(" ").append(stat.substring(7, stat.length() - 2)).append(">\n");
    if (includeProcessors) {
        answer.append(sb);
    }
    answer.append("</routeStat>");
    return answer.toString();
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) ManagedProcessorMBean(org.apache.camel.api.management.mbean.ManagedProcessorMBean) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer)

Example 82 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedManagementStrategy method getManagedObjectName.

public <T> T getManagedObjectName(Object managedObject, String customName, Class<T> nameType) throws Exception {
    if (managedObject == null) {
        return null;
    }
    ObjectName objectName = null;
    if (managedObject instanceof ManagedCamelContext) {
        ManagedCamelContext mcc = (ManagedCamelContext) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForCamelContext(mcc.getContext());
    } else if (managedObject instanceof ManagedComponent) {
        ManagedComponent mc = (ManagedComponent) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForComponent(mc.getComponent(), mc.getComponentName());
    } else if (managedObject instanceof ManagedDataFormat) {
        ManagedDataFormat md = (ManagedDataFormat) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForDataFormat(md.getContext(), md.getDataFormat());
    } else if (managedObject instanceof ManagedEndpoint) {
        ManagedEndpoint me = (ManagedEndpoint) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForEndpoint(me.getEndpoint());
    } else if (managedObject instanceof Endpoint) {
        objectName = getManagementNamingStrategy().getObjectNameForEndpoint((Endpoint) managedObject);
    } else if (managedObject instanceof ManagedRoute) {
        ManagedRoute mr = (ManagedRoute) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForRoute(mr.getRoute());
    } else if (managedObject instanceof ManagedErrorHandler) {
        ManagedErrorHandler meh = (ManagedErrorHandler) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForErrorHandler(meh.getRouteContext(), meh.getErrorHandler(), meh.getErrorHandlerBuilder());
    } else if (managedObject instanceof ManagedProcessor) {
        ManagedProcessor mp = (ManagedProcessor) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForProcessor(mp.getContext(), mp.getProcessor(), mp.getDefinition());
    } else if (managedObject instanceof ManagedConsumer) {
        ManagedConsumer ms = (ManagedConsumer) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForConsumer(ms.getContext(), ms.getConsumer());
    } else if (managedObject instanceof ManagedProducer) {
        ManagedProducer ms = (ManagedProducer) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForProducer(ms.getContext(), ms.getProducer());
    } else if (managedObject instanceof ManagedTracer) {
        ManagedTracer mt = (ManagedTracer) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForTracer(mt.getContext(), mt.getTracer());
    } else if (managedObject instanceof ManagedBacklogTracer) {
        ManagedBacklogTracer mt = (ManagedBacklogTracer) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForTracer(mt.getContext(), mt.getBacklogTracer());
    } else if (managedObject instanceof ManagedBacklogDebugger) {
        ManagedBacklogDebugger md = (ManagedBacklogDebugger) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForTracer(md.getContext(), md.getBacklogDebugger());
    } else if (managedObject instanceof ManagedEventNotifier) {
        ManagedEventNotifier men = (ManagedEventNotifier) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForEventNotifier(men.getContext(), men.getEventNotifier());
    } else if (managedObject instanceof ManagedThreadPool) {
        ManagedThreadPool mes = (ManagedThreadPool) managedObject;
        objectName = getManagementNamingStrategy().getObjectNameForThreadPool(mes.getContext(), mes.getThreadPool(), mes.getId(), mes.getSourceId());
    } else if (managedObject instanceof ManagedService) {
        // check for managed service should be last
        ManagedService ms = (ManagedService) managedObject;
        // skip endpoints as they are already managed
        if (ms.getService() instanceof Endpoint) {
            return null;
        }
        objectName = getManagementNamingStrategy().getObjectNameForService(ms.getContext(), ms.getService());
    }
    return nameType.cast(objectName);
}
Also used : ManagedService(org.apache.camel.management.mbean.ManagedService) ManagedCamelContext(org.apache.camel.management.mbean.ManagedCamelContext) ManagedErrorHandler(org.apache.camel.management.mbean.ManagedErrorHandler) ManagedBacklogDebugger(org.apache.camel.management.mbean.ManagedBacklogDebugger) ManagedComponent(org.apache.camel.management.mbean.ManagedComponent) ManagedEventNotifier(org.apache.camel.management.mbean.ManagedEventNotifier) ManagedThreadPool(org.apache.camel.management.mbean.ManagedThreadPool) ManagedTracer(org.apache.camel.management.mbean.ManagedTracer) ManagedDataFormat(org.apache.camel.management.mbean.ManagedDataFormat) ManagedEndpoint(org.apache.camel.management.mbean.ManagedEndpoint) ObjectName(javax.management.ObjectName) ManagedProducer(org.apache.camel.management.mbean.ManagedProducer) Endpoint(org.apache.camel.Endpoint) ManagedEndpoint(org.apache.camel.management.mbean.ManagedEndpoint) ManagedConsumer(org.apache.camel.management.mbean.ManagedConsumer) ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) ManagedProcessor(org.apache.camel.management.mbean.ManagedProcessor) ManagedBacklogTracer(org.apache.camel.management.mbean.ManagedBacklogTracer)

Example 83 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedManagementStrategy method unmanageObject.

public void unmanageObject(Object managedObject) throws Exception {
    ObjectName objectName = getManagedObjectName(managedObject, null, ObjectName.class);
    unmanageNamedObject(objectName);
}
Also used : ObjectName(javax.management.ObjectName)

Example 84 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class DefaultManagementLifecycleStrategy method findFreeName.

private String findFreeName(Object mc, ManagementNameStrategy strategy, String name) throws MalformedObjectNameException {
    // we cannot find a free name for fixed named strategies
    if (strategy.isFixedName()) {
        return null;
    }
    // okay try to find a free name
    boolean done = false;
    String newName = null;
    while (!done) {
        // compute the next name
        newName = strategy.getNextName();
        ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(newName, name);
        done = !getManagementStrategy().isManaged(mc, on);
        if (LOG.isTraceEnabled()) {
            LOG.trace("Using name: {} in ObjectName[{}] exists? {}", new Object[] { name, on, done });
        }
    }
    return newName;
}
Also used : ObjectName(javax.management.ObjectName)

Example 85 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedStreamCachingStrategyTest method testStreamCachingStrategy.

public void testStreamCachingStrategy() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=myCamel,type=services,*");
    // number of services
    Set<ObjectName> names = mbeanServer.queryNames(on, null);
    ObjectName name = null;
    for (ObjectName service : names) {
        if (service.toString().contains("DefaultStreamCachingStrategy")) {
            name = service;
            break;
        }
    }
    assertNotNull("Cannot find DefaultStreamCachingStrategy", name);
    Boolean enabled = (Boolean) mbeanServer.getAttribute(name, "Enabled");
    assertEquals(Boolean.TRUE, enabled);
    String dir = (String) mbeanServer.getAttribute(name, "SpoolDirectory");
    assertEquals(normalizePath("target/cachedir/myCamel"), normalizePath(dir));
    Long threshold = (Long) mbeanServer.getAttribute(name, "SpoolThreshold");
    assertEquals(StreamCache.DEFAULT_SPOOL_THRESHOLD, threshold.longValue());
    Integer size = (Integer) mbeanServer.getAttribute(name, "BufferSize");
    assertEquals(IOHelper.DEFAULT_BUFFER_SIZE, size.intValue());
    Long counter = (Long) mbeanServer.getAttribute(name, "CacheMemoryCounter");
    assertEquals(0, counter.longValue());
    counter = (Long) mbeanServer.getAttribute(name, "CacheSpoolCounter");
    assertEquals(0, counter.longValue());
    Long cacheSize = (Long) mbeanServer.getAttribute(name, "CacheMemorySize");
    assertEquals(0, cacheSize.longValue());
    cacheSize = (Long) mbeanServer.getAttribute(name, "CacheSpoolSize");
    assertEquals(0, cacheSize.longValue());
    String chiper = (String) mbeanServer.getAttribute(name, "SpoolChiper");
    assertNull(chiper);
    Boolean remove = (Boolean) mbeanServer.getAttribute(name, "RemoveSpoolDirectoryWhenStopping");
    assertEquals(Boolean.TRUE, remove);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

ObjectName (javax.management.ObjectName)1515 MBeanServer (javax.management.MBeanServer)691 Test (org.junit.Test)258 MalformedObjectNameException (javax.management.MalformedObjectNameException)168 IOException (java.io.IOException)101 HashMap (java.util.HashMap)99 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)97 Attribute (javax.management.Attribute)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)94 ArrayList (java.util.ArrayList)91 MBeanServerConnection (javax.management.MBeanServerConnection)72 Map (java.util.Map)66 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)66 MBeanInfo (javax.management.MBeanInfo)64 TabularData (javax.management.openmbean.TabularData)55 JMXServiceURL (javax.management.remote.JMXServiceURL)55 MBeanRegistrationException (javax.management.MBeanRegistrationException)53 JMXConnector (javax.management.remote.JMXConnector)53 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)48 Notification (javax.management.Notification)47