Search in sources :

Example 1 with ManagedRoute

use of org.apache.camel.management.mbean.ManagedRoute in project camel by apache.

the class DefaultManagementObjectStrategy method getManagedObjectForRoute.

public Object getManagedObjectForRoute(CamelContext context, Route route) {
    ManagedRoute mr;
    if (route.supportsSuspension()) {
        mr = new ManagedSuspendableRoute((ModelCamelContext) context, route);
    } else {
        mr = new ManagedRoute((ModelCamelContext) context, route);
    }
    mr.init(context.getManagementStrategy());
    return mr;
}
Also used : ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) ManagedSuspendableRoute(org.apache.camel.management.mbean.ManagedSuspendableRoute) ModelCamelContext(org.apache.camel.model.ModelCamelContext)

Example 2 with ManagedRoute

use of org.apache.camel.management.mbean.ManagedRoute 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 3 with ManagedRoute

use of org.apache.camel.management.mbean.ManagedRoute in project camel by apache.

the class DefaultManagementLifecycleStrategy method onRoutesAdd.

public void onRoutesAdd(Collection<Route> routes) {
    for (Route route : routes) {
        // enabled, then enlist the route as a known route
        if (getCamelContext().getStatus().isStarting() || getManagementStrategy().getManagementAgent().getRegisterAlways() || getManagementStrategy().getManagementAgent().getRegisterNewRoutes()) {
            // register as known route id
            knowRouteIds.add(route.getId());
        }
        if (!shouldRegister(route, route)) {
            // avoid registering if not needed, skip to next route
            continue;
        }
        Object mr = getManagementObjectStrategy().getManagedObjectForRoute(camelContext, route);
        // skip already managed routes, for example if the route has been restarted
        if (getManagementStrategy().isManaged(mr, null)) {
            LOG.trace("The route is already managed: {}", route);
            continue;
        }
        // and set me as the counter
        if (route instanceof EventDrivenConsumerRoute) {
            EventDrivenConsumerRoute edcr = (EventDrivenConsumerRoute) route;
            Processor processor = edcr.getProcessor();
            if (processor instanceof CamelInternalProcessor && mr instanceof ManagedRoute) {
                CamelInternalProcessor internal = (CamelInternalProcessor) processor;
                ManagedRoute routeMBean = (ManagedRoute) mr;
                CamelInternalProcessor.InstrumentationAdvice task = internal.getAdvice(CamelInternalProcessor.InstrumentationAdvice.class);
                if (task != null) {
                    // we need to wrap the counter with the camel context so we get stats updated on the context as well
                    if (camelContextMBean != null) {
                        CompositePerformanceCounter wrapper = new CompositePerformanceCounter(routeMBean, camelContextMBean);
                        task.setCounter(wrapper);
                    } else {
                        task.setCounter(routeMBean);
                    }
                }
            }
        }
        try {
            manageObject(mr);
        } catch (JMException e) {
            LOG.warn("Could not register Route MBean", e);
        } catch (Exception e) {
            LOG.warn("Could not create Route MBean", e);
        }
    }
}
Also used : CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) CamelInternalProcessor(org.apache.camel.processor.CamelInternalProcessor) Processor(org.apache.camel.Processor) ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) JMException(javax.management.JMException) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) ManagedRoute(org.apache.camel.management.mbean.ManagedRoute) Route(org.apache.camel.Route) EventDrivenConsumerRoute(org.apache.camel.impl.EventDrivenConsumerRoute) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException)

Aggregations

ManagedRoute (org.apache.camel.management.mbean.ManagedRoute)3 JMException (javax.management.JMException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 Endpoint (org.apache.camel.Endpoint)1 Processor (org.apache.camel.Processor)1 Route (org.apache.camel.Route)1 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)1 EventDrivenConsumerRoute (org.apache.camel.impl.EventDrivenConsumerRoute)1 ManagedBacklogDebugger (org.apache.camel.management.mbean.ManagedBacklogDebugger)1 ManagedBacklogTracer (org.apache.camel.management.mbean.ManagedBacklogTracer)1 ManagedCamelContext (org.apache.camel.management.mbean.ManagedCamelContext)1 ManagedComponent (org.apache.camel.management.mbean.ManagedComponent)1 ManagedConsumer (org.apache.camel.management.mbean.ManagedConsumer)1 ManagedDataFormat (org.apache.camel.management.mbean.ManagedDataFormat)1 ManagedEndpoint (org.apache.camel.management.mbean.ManagedEndpoint)1 ManagedErrorHandler (org.apache.camel.management.mbean.ManagedErrorHandler)1 ManagedEventNotifier (org.apache.camel.management.mbean.ManagedEventNotifier)1 ManagedProcessor (org.apache.camel.management.mbean.ManagedProcessor)1 ManagedProducer (org.apache.camel.management.mbean.ManagedProducer)1