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);
}
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();
}
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;
}
Aggregations