Search in sources :

Example 1 with ManagedCamelContext

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

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

the class DefaultManagementLifecycleStrategy method onContextStart.

public void onContextStart(CamelContext context) throws VetoCamelContextStartException {
    Object mc = getManagementObjectStrategy().getManagedObjectForCamelContext(context);
    String name = context.getName();
    String managementName = context.getManagementNameStrategy().getName();
    try {
        boolean done = false;
        while (!done) {
            ObjectName on = getManagementStrategy().getManagementNamingStrategy().getObjectNameForCamelContext(managementName, name);
            boolean exists = getManagementStrategy().isManaged(mc, on);
            if (!exists) {
                done = true;
            } else {
                // okay there exists already a CamelContext with this name, we can try to fix it by finding a free name
                boolean fixed = false;
                // if we use the default name strategy we can find a free name to use
                String newName = findFreeName(mc, context.getManagementNameStrategy(), name);
                if (newName != null) {
                    // use this as the fixed name
                    fixed = true;
                    done = true;
                    managementName = newName;
                }
                // we could not fix it so veto starting camel
                if (!fixed) {
                    throw new VetoCamelContextStartException("CamelContext (" + context.getName() + ") with ObjectName[" + on + "] is already registered." + " Make sure to use unique names on CamelContext when using multiple CamelContexts in the same MBeanServer.", context);
                } else {
                    LOG.warn("This CamelContext(" + context.getName() + ") will be registered using the name: " + managementName + " due to clash with an existing name already registered in MBeanServer.");
                }
            }
        }
    } catch (VetoCamelContextStartException e) {
        // rethrow veto
        throw e;
    } catch (Exception e) {
        // Camel to continue to run
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    // set the name we are going to use
    if (context instanceof DefaultCamelContext) {
        ((DefaultCamelContext) context).setManagementName(managementName);
    }
    try {
        manageObject(mc);
    } catch (Exception e) {
        // Camel to continue to run
        throw ObjectHelper.wrapRuntimeCamelException(e);
    }
    // yes we made it and are initialized
    initialized = true;
    if (mc instanceof ManagedCamelContext) {
        camelContextMBean = (ManagedCamelContext) mc;
    }
    // register any pre registered now that we are initialized
    enlistPreRegisteredServices();
}
Also used : ManagedCamelContext(org.apache.camel.management.mbean.ManagedCamelContext) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) MalformedObjectNameException(javax.management.MalformedObjectNameException) JMException(javax.management.JMException) VetoCamelContextStartException(org.apache.camel.VetoCamelContextStartException) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ObjectName(javax.management.ObjectName)

Example 3 with ManagedCamelContext

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

the class DefaultManagementObjectStrategy method getManagedObjectForCamelContext.

public Object getManagedObjectForCamelContext(CamelContext context) {
    ManagedCamelContext mc = new ManagedCamelContext((ModelCamelContext) context);
    mc.init(context.getManagementStrategy());
    return mc;
}
Also used : ManagedCamelContext(org.apache.camel.management.mbean.ManagedCamelContext)

Aggregations

ManagedCamelContext (org.apache.camel.management.mbean.ManagedCamelContext)3 ObjectName (javax.management.ObjectName)2 JMException (javax.management.JMException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 Endpoint (org.apache.camel.Endpoint)1 VetoCamelContextStartException (org.apache.camel.VetoCamelContextStartException)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ManagedBacklogDebugger (org.apache.camel.management.mbean.ManagedBacklogDebugger)1 ManagedBacklogTracer (org.apache.camel.management.mbean.ManagedBacklogTracer)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 ManagedRoute (org.apache.camel.management.mbean.ManagedRoute)1 ManagedService (org.apache.camel.management.mbean.ManagedService)1 ManagedThreadPool (org.apache.camel.management.mbean.ManagedThreadPool)1