001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.management.mbean;
018
019import java.io.ByteArrayInputStream;
020import java.util.ArrayList;
021import java.util.Collection;
022import java.util.Comparator;
023import java.util.List;
024import java.util.Map;
025import java.util.Set;
026import java.util.concurrent.TimeUnit;
027
028import javax.management.MBeanServer;
029import javax.management.ObjectName;
030
031import org.w3c.dom.Document;
032
033import org.apache.camel.CamelContext;
034import org.apache.camel.Endpoint;
035import org.apache.camel.Exchange;
036import org.apache.camel.ManagementStatisticsLevel;
037import org.apache.camel.Producer;
038import org.apache.camel.ProducerTemplate;
039import org.apache.camel.Route;
040import org.apache.camel.TimerListener;
041import org.apache.camel.api.management.ManagedResource;
042import org.apache.camel.api.management.mbean.ManagedCamelContextMBean;
043import org.apache.camel.api.management.mbean.ManagedProcessorMBean;
044import org.apache.camel.api.management.mbean.ManagedRouteMBean;
045import org.apache.camel.api.management.mbean.ManagedStepMBean;
046import org.apache.camel.model.Model;
047import org.apache.camel.model.RouteDefinition;
048import org.apache.camel.model.RouteTemplateDefinition;
049import org.apache.camel.model.RouteTemplatesDefinition;
050import org.apache.camel.model.RoutesDefinition;
051import org.apache.camel.model.rest.RestDefinition;
052import org.apache.camel.model.rest.RestsDefinition;
053import org.apache.camel.spi.ManagementStrategy;
054import org.apache.camel.spi.UnitOfWork;
055import org.apache.camel.support.PluginHelper;
056
057@ManagedResource(description = "Managed CamelContext")
058public class ManagedCamelContext extends ManagedPerformanceCounter implements TimerListener, ManagedCamelContextMBean {
059
060    private final CamelContext context;
061    private final LoadTriplet load = new LoadTriplet();
062    private final LoadThroughput thp = new LoadThroughput();
063    private final String jmxDomain;
064
065    public ManagedCamelContext(CamelContext context) {
066        this.context = context;
067        this.jmxDomain = context.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();
068    }
069
070    @Override
071    public void init(ManagementStrategy strategy) {
072        super.init(strategy);
073        boolean enabled = context.getManagementStrategy().getManagementAgent() != null
074                && context.getManagementStrategy().getManagementAgent().getStatisticsLevel() != ManagementStatisticsLevel.Off;
075        setStatisticsEnabled(enabled);
076    }
077
078    @Override
079    public void completedExchange(Exchange exchange, long time) {
080        // the camel-context mbean is triggered for every route mbean
081        // so we must only trigger on the root level, otherwise the context mbean
082        // total counter will be incorrect. For example if an exchange is routed via 3 routes
083        // we should only count this as 1 instead of 3.
084        UnitOfWork uow = exchange.getUnitOfWork();
085        if (uow != null) {
086            int level = uow.routeStackLevel();
087            if (level <= 1) {
088                super.completedExchange(exchange, time);
089            }
090        } else {
091            super.completedExchange(exchange, time);
092        }
093    }
094
095    @Override
096    public void failedExchange(Exchange exchange) {
097        // the camel-context mbean is triggered for every route mbean
098        // so we must only trigger on the root level, otherwise the context mbean
099        // total counter will be incorrect. For example if an exchange is routed via 3 routes
100        // we should only count this as 1 instead of 3.
101        UnitOfWork uow = exchange.getUnitOfWork();
102        if (uow != null) {
103            int level = uow.routeStackLevel();
104            if (level <= 1) {
105                super.failedExchange(exchange);
106            }
107        } else {
108            super.failedExchange(exchange);
109        }
110    }
111
112    @Override
113    public void processExchange(Exchange exchange, String type) {
114        // the camel-context mbean is triggered for every route mbean
115        // so we must only trigger on the root level, otherwise the context mbean
116        // total counter will be incorrect. For example if an exchange is routed via 3 routes
117        // we should only count this as 1 instead of 3.
118        UnitOfWork uow = exchange.getUnitOfWork();
119        if (uow != null) {
120            int level = uow.routeStackLevel();
121            if (level <= 1) {
122                super.processExchange(exchange, type);
123            }
124        } else {
125            super.processExchange(exchange, type);
126        }
127    }
128
129    public CamelContext getContext() {
130        return context;
131    }
132
133    @Override
134    public String getCamelId() {
135        return context.getName();
136    }
137
138    @Override
139    public String getCamelDescription() {
140        return context.getDescription();
141    }
142
143    @Override
144    public String getManagementName() {
145        return context.getManagementName();
146    }
147
148    @Override
149    public String getCamelVersion() {
150        return context.getVersion();
151    }
152
153    @Override
154    public String getState() {
155        return context.getStatus().name();
156    }
157
158    @Override
159    public String getUptime() {
160        return context.getUptime();
161    }
162
163    @Override
164    public long getUptimeMillis() {
165        return context.getUptimeMillis();
166    }
167
168    @Override
169    public String getManagementStatisticsLevel() {
170        if (context.getManagementStrategy().getManagementAgent() != null) {
171            return context.getManagementStrategy().getManagementAgent().getStatisticsLevel().name();
172        } else {
173            return null;
174        }
175    }
176
177    @Override
178    public String getClassResolver() {
179        return context.getClassResolver().getClass().getName();
180    }
181
182    @Override
183    public String getPackageScanClassResolver() {
184        return PluginHelper.getPackageScanClassResolver(context).getClass().getName();
185    }
186
187    @Override
188    public String getApplicationContextClassName() {
189        if (context.getApplicationContextClassLoader() != null) {
190            return context.getApplicationContextClassLoader().getClass().getName();
191        } else {
192            return null;
193        }
194    }
195
196    @Override
197    public String getHeadersMapFactoryClassName() {
198        return context.getCamelContextExtension().getHeadersMapFactory().getClass().getName();
199    }
200
201    @Override
202    public Map<String, String> getGlobalOptions() {
203        if (context.getGlobalOptions().isEmpty()) {
204            return null;
205        }
206        return context.getGlobalOptions();
207    }
208
209    @Override
210    public String getGlobalOption(String key) throws Exception {
211        return context.getGlobalOption(key);
212    }
213
214    @Override
215    public void setGlobalOption(String key, String value) throws Exception {
216        context.getGlobalOptions().put(key, value);
217    }
218
219    @Override
220    public Boolean getTracing() {
221        return context.isTracing();
222    }
223
224    @Override
225    public void setTracing(Boolean tracing) {
226        context.setTracing(tracing);
227    }
228
229    public Integer getInflightExchanges() {
230        return (int) super.getExchangesInflight();
231    }
232
233    @Override
234    public Integer getTotalRoutes() {
235        return context.getRoutesSize();
236    }
237
238    @Override
239    public Integer getStartedRoutes() {
240        int started = 0;
241        for (Route route : context.getRoutes()) {
242            if (context.getRouteController().getRouteStatus(route.getId()).isStarted()) {
243                started++;
244            }
245        }
246        return started;
247    }
248
249    @Override
250    public void setTimeout(long timeout) {
251        context.getShutdownStrategy().setTimeout(timeout);
252    }
253
254    @Override
255    public long getTimeout() {
256        return context.getShutdownStrategy().getTimeout();
257    }
258
259    @Override
260    public void setTimeUnit(TimeUnit timeUnit) {
261        context.getShutdownStrategy().setTimeUnit(timeUnit);
262    }
263
264    @Override
265    public TimeUnit getTimeUnit() {
266        return context.getShutdownStrategy().getTimeUnit();
267    }
268
269    @Override
270    public void setShutdownNowOnTimeout(boolean shutdownNowOnTimeout) {
271        context.getShutdownStrategy().setShutdownNowOnTimeout(shutdownNowOnTimeout);
272    }
273
274    @Override
275    public boolean isShutdownNowOnTimeout() {
276        return context.getShutdownStrategy().isShutdownNowOnTimeout();
277    }
278
279    @Override
280    public String getLoad01() {
281        double load1 = load.getLoad1();
282        if (Double.isNaN(load1)) {
283            // empty string if load statistics is disabled
284            return "";
285        } else {
286            return String.format("%.2f", load1);
287        }
288    }
289
290    @Override
291    public String getLoad05() {
292        double load5 = load.getLoad5();
293        if (Double.isNaN(load5)) {
294            // empty string if load statistics is disabled
295            return "";
296        } else {
297            return String.format("%.2f", load5);
298        }
299    }
300
301    @Override
302    public String getLoad15() {
303        double load15 = load.getLoad15();
304        if (Double.isNaN(load15)) {
305            // empty string if load statistics is disabled
306            return "";
307        } else {
308            return String.format("%.2f", load15);
309        }
310    }
311
312    @Override
313    public String getThroughput() {
314        double d = thp.getThroughput();
315        if (Double.isNaN(d)) {
316            // empty string if load statistics is disabled
317            return "";
318        } else {
319            return String.format("%.2f", d);
320        }
321    }
322
323    @Override
324    public boolean isUseBreadcrumb() {
325        return context.isUseBreadcrumb();
326    }
327
328    @Override
329    public boolean isAllowUseOriginalMessage() {
330        return context.isAllowUseOriginalMessage();
331    }
332
333    @Override
334    public boolean isMessageHistory() {
335        return context.isMessageHistory() != null ? context.isMessageHistory() : false;
336    }
337
338    @Override
339    public boolean isLogMask() {
340        return context.isLogMask() != null ? context.isLogMask() : false;
341    }
342
343    @Override
344    public boolean isUseMDCLogging() {
345        return context.isUseMDCLogging();
346    }
347
348    @Override
349    public boolean isUseDataType() {
350        return context.isUseDataType();
351    }
352
353    @Override
354    public void onTimer() {
355        load.update(getInflightExchanges());
356        thp.update(getExchangesTotal());
357    }
358
359    @Override
360    public void start() throws Exception {
361        if (context.isSuspended()) {
362            context.resume();
363        } else {
364            context.start();
365        }
366    }
367
368    @Override
369    public void stop() throws Exception {
370        context.stop();
371    }
372
373    @Override
374    public void restart() throws Exception {
375        context.stop();
376        context.start();
377    }
378
379    @Override
380    public void suspend() throws Exception {
381        context.suspend();
382    }
383
384    @Override
385    public void resume() throws Exception {
386        if (context.isSuspended()) {
387            context.resume();
388        } else {
389            throw new IllegalStateException("CamelContext is not suspended");
390        }
391    }
392
393    @Override
394    public void startAllRoutes() throws Exception {
395        context.getRouteController().startAllRoutes();
396    }
397
398    @Override
399    public boolean canSendToEndpoint(String endpointUri) {
400        try {
401            Endpoint endpoint = context.getEndpoint(endpointUri);
402            if (endpoint != null) {
403                try (Producer producer = endpoint.createProducer()) {
404                    return producer != null;
405                }
406            }
407        } catch (Exception e) {
408            // ignore
409        }
410
411        return false;
412    }
413
414    @Override
415    public void sendBody(String endpointUri, Object body) throws Exception {
416        try (ProducerTemplate template = context.createProducerTemplate()) {
417            template.sendBody(endpointUri, body);
418        }
419    }
420
421    @Override
422    public void sendStringBody(String endpointUri, String body) throws Exception {
423        sendBody(endpointUri, body);
424    }
425
426    @Override
427    public void sendBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws Exception {
428        try (ProducerTemplate template = context.createProducerTemplate()) {
429            template.sendBodyAndHeaders(endpointUri, body, headers);
430        }
431    }
432
433    @Override
434    public Object requestBody(String endpointUri, Object body) throws Exception {
435        try (ProducerTemplate template = context.createProducerTemplate()) {
436            return template.requestBody(endpointUri, body);
437        }
438    }
439
440    @Override
441    public Object requestStringBody(String endpointUri, String body) throws Exception {
442        return requestBody(endpointUri, body);
443    }
444
445    @Override
446    public Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws Exception {
447        try (ProducerTemplate template = context.createProducerTemplate()) {
448            return template.requestBodyAndHeaders(endpointUri, body, headers);
449        }
450
451    }
452
453    @Override
454    public String dumpRestsAsXml() throws Exception {
455        return dumpRestsAsXml(false);
456    }
457
458    @Override
459    public String dumpRestsAsXml(boolean resolvePlaceholders) throws Exception {
460        List<RestDefinition> rests = context.getCamelContextExtension().getContextPlugin(Model.class).getRestDefinitions();
461        if (rests.isEmpty()) {
462            return null;
463        }
464
465        RestsDefinition def = new RestsDefinition();
466        def.setRests(rests);
467
468        return PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, def, resolvePlaceholders, false);
469    }
470
471    @Override
472    public String dumpRoutesAsXml() throws Exception {
473        return dumpRoutesAsXml(false, false);
474    }
475
476    @Override
477    public String dumpRoutesAsXml(boolean resolvePlaceholders) throws Exception {
478        return dumpRoutesAsXml(resolvePlaceholders, false);
479    }
480
481    @Override
482    public String dumpRoutesAsXml(boolean resolvePlaceholders, boolean resolveDelegateEndpoints) throws Exception {
483        List<RouteDefinition> routes = context.getCamelContextExtension().getContextPlugin(Model.class).getRouteDefinitions();
484        if (routes.isEmpty()) {
485            return null;
486        }
487
488        // use routes definition to dump the routes
489        RoutesDefinition def = new RoutesDefinition();
490        def.setRoutes(routes);
491
492        return PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, def, resolvePlaceholders,
493                resolveDelegateEndpoints);
494    }
495
496    @Override
497    public String dumpRouteTemplatesAsXml() throws Exception {
498        List<RouteTemplateDefinition> templates
499                = context.getCamelContextExtension().getContextPlugin(Model.class).getRouteTemplateDefinitions();
500        if (templates.isEmpty()) {
501            return null;
502        }
503
504        // use a route templates definition to dump the templates
505        RouteTemplatesDefinition def = new RouteTemplatesDefinition();
506        def.setRouteTemplates(templates);
507
508        return PluginHelper.getModelToXMLDumper(context).dumpModelAsXml(context, def);
509    }
510
511    @Override
512    public String dumpRoutesStatsAsXml(boolean fullStats, boolean includeProcessors) throws Exception {
513        StringBuilder sb = new StringBuilder();
514        sb.append("<camelContextStat").append(String.format(" id=\"%s\" state=\"%s\"", getCamelId(), getState()));
515        // use substring as we only want the attributes
516        String stat = dumpStatsAsXml(fullStats);
517        sb.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");
518        sb.append(" ").append(stat, 7, stat.length() - 2).append(">\n");
519
520        MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
521        if (server != null) {
522            // gather all the routes for this CamelContext, which requires JMX
523            String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
524            ObjectName query = ObjectName
525                    .getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
526            Set<ObjectName> routes = server.queryNames(query, null);
527
528            List<ManagedProcessorMBean> processors = new ArrayList<>();
529            if (includeProcessors) {
530                // gather all the processors for this CamelContext, which requires JMX
531                query = ObjectName.getInstance(
532                        jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=processors,*");
533                Set<ObjectName> names = server.queryNames(query, null);
534                for (ObjectName on : names) {
535                    ManagedProcessorMBean processor = context.getManagementStrategy().getManagementAgent().newProxyClient(on,
536                            ManagedProcessorMBean.class);
537                    processors.add(processor);
538                }
539            }
540            processors.sort(new OrderProcessorMBeans());
541
542            // loop the routes, and append the processor stats if needed
543            sb.append("  <routeStats>\n");
544            for (ObjectName on : routes) {
545                ManagedRouteMBean route
546                        = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
547                sb.append("    <routeStat")
548                        .append(String.format(" id=\"%s\" state=\"%s\"", route.getRouteId(), route.getState()));
549                if (route.getSourceLocation() != null) {
550                    sb.append(String.format(" sourceLocation=\"%s\"", route.getSourceLocation()));
551                }
552
553                // use substring as we only want the attributes
554                stat = route.dumpStatsAsXml(fullStats);
555                sb.append(" exchangesInflight=\"").append(route.getExchangesInflight()).append("\"");
556                sb.append(" ").append(stat, 7, stat.length() - 2).append(">\n");
557
558                // add processor details if needed
559                if (includeProcessors) {
560                    sb.append("      <processorStats>\n");
561                    for (ManagedProcessorMBean processor : processors) {
562                        int line = processor.getSourceLineNumber() != null ? processor.getSourceLineNumber() : -1;
563                        // the processor must belong to this route
564                        if (route.getRouteId().equals(processor.getRouteId())) {
565                            sb.append("        <processorStat")
566                                    .append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\" sourceLineNumber=\"%s\"",
567                                            processor.getProcessorId(), processor.getIndex(), processor.getState(), line));
568                            // use substring as we only want the attributes
569                            stat = processor.dumpStatsAsXml(fullStats);
570                            sb.append(" exchangesInflight=\"").append(processor.getExchangesInflight()).append("\"");
571                            sb.append(" ").append(stat, 7, stat.length()).append("\n");
572                        }
573                    }
574                    sb.append("      </processorStats>\n");
575                }
576                sb.append("    </routeStat>\n");
577            }
578            sb.append("  </routeStats>\n");
579        }
580
581        sb.append("</camelContextStat>");
582        return sb.toString();
583    }
584
585    @Override
586    public String dumpStepStatsAsXml(boolean fullStats) throws Exception {
587        StringBuilder sb = new StringBuilder();
588        sb.append("<camelContextStat").append(String.format(" id=\"%s\" state=\"%s\"", getCamelId(), getState()));
589        // use substring as we only want the attributes
590        String stat = dumpStatsAsXml(fullStats);
591        sb.append(" exchangesInflight=\"").append(getInflightExchanges()).append("\"");
592        sb.append(" ").append(stat, 7, stat.length() - 2).append(">\n");
593
594        MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
595        if (server != null) {
596            // gather all the routes for this CamelContext, which requires JMX
597            String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
598            ObjectName query = ObjectName
599                    .getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
600            Set<ObjectName> routes = server.queryNames(query, null);
601
602            List<ManagedProcessorMBean> steps = new ArrayList<>();
603            // gather all the steps for this CamelContext, which requires JMX
604            query = ObjectName
605                    .getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=steps,*");
606            Set<ObjectName> names = server.queryNames(query, null);
607            for (ObjectName on : names) {
608                ManagedStepMBean step
609                        = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedStepMBean.class);
610                steps.add(step);
611            }
612            steps.sort(new OrderProcessorMBeans());
613
614            // loop the routes, and append the processor stats if needed
615            sb.append("  <routeStats>\n");
616            for (ObjectName on : routes) {
617                ManagedRouteMBean route
618                        = context.getManagementStrategy().getManagementAgent().newProxyClient(on, ManagedRouteMBean.class);
619                sb.append("    <routeStat")
620                        .append(String.format(" id=\"%s\" state=\"%s\"", route.getRouteId(), route.getState()));
621                if (route.getSourceLocation() != null) {
622                    sb.append(String.format(" sourceLocation=\"%s\"", route.getSourceLocation()));
623                }
624
625                // use substring as we only want the attributes
626                stat = route.dumpStatsAsXml(fullStats);
627                sb.append(" exchangesInflight=\"").append(route.getExchangesInflight()).append("\"");
628                sb.append(" ").append(stat, 7, stat.length() - 2).append(">\n");
629
630                // add steps details if needed
631                sb.append("      <stepStats>\n");
632                for (ManagedProcessorMBean step : steps) {
633                    // the step must belong to this route
634                    if (route.getRouteId().equals(step.getRouteId())) {
635                        int line = step.getSourceLineNumber() != null ? step.getSourceLineNumber() : -1;
636                        sb.append("        <stepStat")
637                                .append(String.format(" id=\"%s\" index=\"%s\" state=\"%s\" sourceLineNumber=\"%s\"",
638                                        step.getProcessorId(), step.getIndex(), step.getState(), line));
639                        // use substring as we only want the attributes
640                        stat = step.dumpStatsAsXml(fullStats);
641                        sb.append(" exchangesInflight=\"").append(step.getExchangesInflight()).append("\"");
642                        sb.append(" ").append(stat, 7, stat.length()).append("\n");
643                    }
644                    sb.append("      </stepStats>\n");
645                }
646                sb.append("    </stepStat>\n");
647            }
648            sb.append("  </routeStats>\n");
649        }
650
651        sb.append("</camelContextStat>");
652        return sb.toString();
653    }
654
655    @Override
656    public String dumpRoutesCoverageAsXml() throws Exception {
657        StringBuilder sb = new StringBuilder();
658        sb.append("<camelContextRouteCoverage")
659                .append(String.format(" id=\"%s\" exchangesTotal=\"%s\" totalProcessingTime=\"%s\"", getCamelId(),
660                        getExchangesTotal(), getTotalProcessingTime()))
661                .append(">\n");
662
663        String xml = dumpRoutesAsXml();
664        if (xml != null) {
665            // use the coverage xml parser to dump the routes and enrich with coverage stats
666            Document dom = RouteCoverageXmlParser.parseXml(context, new ByteArrayInputStream(xml.getBytes()));
667            // convert dom back to xml
668            String converted = context.getTypeConverter().convertTo(String.class, dom);
669            sb.append(converted);
670        }
671
672        sb.append("\n</camelContextRouteCoverage>");
673        return sb.toString();
674    }
675
676    @Override
677    public boolean createEndpoint(String uri) throws Exception {
678        if (context.hasEndpoint(uri) != null) {
679            // endpoint already exists
680            return false;
681        }
682
683        Endpoint endpoint = context.getEndpoint(uri);
684        if (endpoint != null) {
685            // ensure endpoint is registered, as the management strategy could have been configured to not always
686            // register new endpoints in JMX, so we need to check if its registered, and if not register it manually
687            ObjectName on
688                    = context.getManagementStrategy().getManagementObjectNameStrategy().getObjectNameForEndpoint(endpoint);
689            if (on != null && !context.getManagementStrategy().getManagementAgent().isRegistered(on)) {
690                // register endpoint as mbean
691                Object me = context.getManagementStrategy().getManagementObjectStrategy().getManagedObjectForEndpoint(context,
692                        endpoint);
693                context.getManagementStrategy().getManagementAgent().register(me, on);
694            }
695            return true;
696        } else {
697            return false;
698        }
699    }
700
701    @Override
702    public int removeEndpoints(String pattern) throws Exception {
703        // endpoints is always removed from JMX if removed from context
704        Collection<Endpoint> removed = context.removeEndpoints(pattern);
705        return removed.size();
706    }
707
708    @Override
709    public void reset(boolean includeRoutes) throws Exception {
710        reset();
711        load.reset();
712        thp.reset();
713
714        // and now reset all routes for this route
715        if (includeRoutes) {
716            MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
717            if (server != null) {
718                String prefix = getContext().getManagementStrategy().getManagementAgent().getIncludeHostName() ? "*/" : "";
719                ObjectName query = ObjectName
720                        .getInstance(jmxDomain + ":context=" + prefix + getContext().getManagementName() + ",type=routes,*");
721                Set<ObjectName> names = server.queryNames(query, null);
722                for (ObjectName name : names) {
723                    server.invoke(name, "reset", new Object[] { true }, new String[] { "boolean" });
724                }
725            }
726        }
727    }
728
729    @Override
730    public Set<String> componentNames() throws Exception {
731        return context.getComponentNames();
732    }
733
734    @Override
735    public Set<String> languageNames() throws Exception {
736        return context.getLanguageNames();
737    }
738
739    @Override
740    public Set<String> dataFormatNames() throws Exception {
741        return context.getDataFormatNames();
742    }
743
744    /**
745     * Used for sorting the processor mbeans accordingly to their index.
746     */
747    private static final class OrderProcessorMBeans implements Comparator<ManagedProcessorMBean> {
748
749        @Override
750        public int compare(ManagedProcessorMBean o1, ManagedProcessorMBean o2) {
751            return o1.getIndex().compareTo(o2.getIndex());
752        }
753    }
754
755    /**
756     * Used for sorting the routes mbeans accordingly to their ids.
757     */
758    private static final class RouteMBeans implements Comparator<ManagedRouteMBean> {
759
760        @Override
761        public int compare(ManagedRouteMBean o1, ManagedRouteMBean o2) {
762            return o1.getRouteId().compareToIgnoreCase(o2.getRouteId());
763        }
764    }
765
766}