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