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     */
017    package org.apache.camel.management.mbean;
018    
019    import org.apache.camel.CamelContext;
020    import org.apache.camel.LoggingLevel;
021    import org.apache.camel.processor.interceptor.Tracer;
022    import org.apache.camel.spi.ManagementStrategy;
023    import org.apache.camel.util.ObjectHelper;
024    import org.springframework.jmx.export.annotation.ManagedAttribute;
025    import org.springframework.jmx.export.annotation.ManagedResource;
026    
027    /**
028     * @version $Revision: 884845 $
029     */
030    @ManagedResource(description = "Managed Tracer")
031    public class ManagedTracer {
032    
033        private CamelContext camelContext;
034        private Tracer tracer;
035    
036        public ManagedTracer(CamelContext camelContext, Tracer tracer) {
037            this.camelContext = camelContext;
038            this.tracer = tracer;
039        }
040    
041        public void init(ManagementStrategy strategy) {
042            // do nothing
043        }
044    
045        public CamelContext getCamelContext() {
046            return camelContext;
047        }
048    
049        public Tracer getTracer() {
050            return tracer;
051        }
052    
053        @ManagedAttribute(description = "Tracer enabled")
054        public boolean getEnabled() {
055            return tracer.isEnabled();
056        }
057    
058        @ManagedAttribute(description = "Tracer enabled")
059        public void setEnabled(boolean enabled) {
060            tracer.setEnabled(enabled);
061        }
062    
063        @ManagedAttribute(description = "Additional destination Uri")
064        public String getDestinationUri() {
065            return tracer.getDestinationUri();
066        }
067    
068        @ManagedAttribute(description = "Additional destination Uri")
069        public void setDestinationUri(String uri) {
070            if (ObjectHelper.isEmpty(uri)) {
071                tracer.setDestinationUri(null);
072            } else {
073                tracer.setDestinationUri(uri);
074            }
075        }
076    
077        @ManagedAttribute(description = "Logging Name")
078        public String getLogName() {
079            return tracer.getLogName();
080        }
081    
082        @ManagedAttribute(description = "Using Jpa")
083        public boolean getUseJpa() {
084            return tracer.isUseJpa();
085        }
086    
087        @ManagedAttribute(description = "Logging Name")
088        public void setLogName(String logName) {
089            tracer.setLogName(logName);
090        }
091    
092        @ManagedAttribute(description = "Logging Level")
093        public String getLogLevel() {
094            return tracer.getLogLevel().name();
095        }
096    
097        @ManagedAttribute(description = "Logging Level")
098        public void setLogLevel(String logLevel) {
099            tracer.setLogLevel(LoggingLevel.valueOf(logLevel));
100        }
101    
102        @ManagedAttribute(description = "Log Stacktrace")
103        public boolean getLogStackTrace() {
104            return tracer.isLogStackTrace();
105        }
106    
107        @ManagedAttribute(description = "Log Stacktrace")
108        public void setLogStackTrace(boolean logStackTrace) {
109            tracer.setLogStackTrace(logStackTrace);
110        }
111    
112        @ManagedAttribute(description = "Trace Interceptors")
113        public boolean getTraceInterceptors() {
114            return tracer.isTraceInterceptors();
115        }
116    
117        @ManagedAttribute(description = "Trace Interceptors")
118        public void setTraceInterceptors(boolean traceInterceptors) {
119            tracer.setTraceInterceptors(traceInterceptors);
120        }
121    
122        @ManagedAttribute(description = "Trace Exceptions")
123        public boolean getTraceExceptions() {
124            return tracer.isTraceExceptions();
125        }
126    
127        @ManagedAttribute(description = "Trace Exceptions")
128        public void setTraceExceptions(boolean traceExceptions) {
129            tracer.setTraceExceptions(traceExceptions);
130        }
131    
132        @ManagedAttribute(description = "Trace Out Exchanges")
133        public boolean getTraceOutExchanges() {
134            return tracer.isTraceOutExchanges();
135        }
136    
137        @ManagedAttribute(description = "Trace Out Exchanges")
138        public void setTraceOutExchanges(boolean traceOutExchanges) {
139            tracer.setTraceOutExchanges(traceOutExchanges);
140        }
141    
142        @ManagedAttribute(description = "Formatter show body")
143        public boolean getFormatterShowBody() {
144            if (tracer.getDefaultTraceFormatter() == null) {
145                return false;
146            }
147            return tracer.getDefaultTraceFormatter().isShowBody();
148        }
149    
150        @ManagedAttribute(description = "Formatter show body")
151        public void setFormatterShowBody(boolean showBody) {
152            if (tracer.getDefaultTraceFormatter() == null) {
153                return;
154            }
155            tracer.getDefaultTraceFormatter().setShowBody(showBody);
156        }
157    
158        @ManagedAttribute(description = "Formatter show body type")
159        public boolean getFormatterShowBodyType() {
160            if (tracer.getDefaultTraceFormatter() == null) {
161                return false;
162            }
163            return tracer.getDefaultTraceFormatter().isShowBodyType();
164        }
165    
166        @ManagedAttribute(description = "Formatter show body type")
167        public void setFormatterShowBodyType(boolean showBodyType) {
168            if (tracer.getDefaultTraceFormatter() == null) {
169                return;
170            }
171            tracer.getDefaultTraceFormatter().setShowBodyType(showBodyType);
172        }
173    
174        @ManagedAttribute(description = "Formatter show out body")
175        public boolean getFormatterShowOutBody() {
176            if (tracer.getDefaultTraceFormatter() == null) {
177                return false;
178            }
179            return tracer.getDefaultTraceFormatter().isShowOutBody();
180        }
181    
182        @ManagedAttribute(description = "Formatter show out body")
183        public void setFormatterShowOutBody(boolean showOutBody) {
184            if (tracer.getDefaultTraceFormatter() == null) {
185                return;
186            }
187            tracer.getDefaultTraceFormatter().setShowOutBody(showOutBody);
188        }
189    
190        @ManagedAttribute(description = "Formatter show out body type")
191        public boolean getFormatterShowOutBodyType() {
192            if (tracer.getDefaultTraceFormatter() == null) {
193                return false;
194            }
195            return tracer.getDefaultTraceFormatter().isShowOutBodyType();
196        }
197    
198        @ManagedAttribute(description = "Formatter show out body type")
199        public void setFormatterShowOutBodyType(boolean showOutBodyType) {
200            if (tracer.getDefaultTraceFormatter() == null) {
201                return;
202            }
203            tracer.getDefaultTraceFormatter().setShowOutBodyType(showOutBodyType);
204        }
205    
206        @ManagedAttribute(description = "Formatter show breadcrumb")
207        public boolean getFormatterShowBreadCrumb() {
208            if (tracer.getDefaultTraceFormatter() == null) {
209                return false;
210            }
211            return tracer.getDefaultTraceFormatter().isShowBreadCrumb();
212        }
213    
214        @ManagedAttribute(description = "Formatter show breadcrumb")
215        public void setFormatterShowBreadCrumb(boolean showBreadCrumb) {
216            if (tracer.getDefaultTraceFormatter() == null) {
217                return;
218            }
219            tracer.getDefaultTraceFormatter().setShowBreadCrumb(showBreadCrumb);
220        }
221    
222        @ManagedAttribute(description = "Formatter show exchange id")
223        public boolean getFormatterShowExchangeId() {
224            if (tracer.getDefaultTraceFormatter() == null) {
225                return false;
226            }
227            return tracer.getDefaultTraceFormatter().isShowExchangeId();
228        }
229    
230        @ManagedAttribute(description = "Formatter show exchange id")
231        public void setFormatterShowExchangeId(boolean showExchangeId) {
232            if (tracer.getDefaultTraceFormatter() == null) {
233                return;
234            }
235            tracer.getDefaultTraceFormatter().setShowExchangeId(showExchangeId);
236        }
237    
238        @ManagedAttribute(description = "Formatter show headers")
239        public boolean getFormatterShowHeaders() {
240            if (tracer.getDefaultTraceFormatter() == null) {
241                return false;
242            }
243            return tracer.getDefaultTraceFormatter().isShowHeaders();
244        }
245    
246        @ManagedAttribute(description = "Formatter show headers")
247        public void setFormatterShowHeaders(boolean showHeaders) {
248            if (tracer.getDefaultTraceFormatter() == null) {
249                return;
250            }
251            tracer.getDefaultTraceFormatter().setShowHeaders(showHeaders);
252        }
253    
254        @ManagedAttribute(description = "Formatter show out headers")
255        public boolean getFormatterShowOutHeaders() {
256            if (tracer.getDefaultTraceFormatter() == null) {
257                return false;
258            }
259            return tracer.getDefaultTraceFormatter().isShowOutHeaders();
260        }
261    
262        @ManagedAttribute(description = "Formatter show out headers")
263        public void setFormatterShowOutHeaders(boolean showOutHeaders) {
264            if (tracer.getDefaultTraceFormatter() == null) {
265                return;
266            }
267            tracer.getDefaultTraceFormatter().setShowOutHeaders(showOutHeaders);
268        }
269    
270        @ManagedAttribute(description = "Formatter show properties")
271        public boolean getFormatterShowProperties() {
272            if (tracer.getDefaultTraceFormatter() == null) {
273                return false;
274            }
275            return tracer.getDefaultTraceFormatter().isShowProperties();
276        }
277    
278        @ManagedAttribute(description = "Formatter show properties")
279        public void setFormatterShowProperties(boolean showProperties) {
280            if (tracer.getDefaultTraceFormatter() == null) {
281                return;
282            }
283            tracer.getDefaultTraceFormatter().setShowProperties(showProperties);
284        }
285    
286        @ManagedAttribute(description = "Formatter show node")
287        public boolean getFormatterShowNode() {
288            if (tracer.getDefaultTraceFormatter() == null) {
289                return false;
290            }
291            return tracer.getDefaultTraceFormatter().isShowNode();
292        }
293    
294        @ManagedAttribute(description = "Formatter show node")
295        public void setFormatterShowNode(boolean showNode) {
296            if (tracer.getDefaultTraceFormatter() == null) {
297                return;
298            }
299            tracer.getDefaultTraceFormatter().setShowNode(showNode);
300        }
301    
302        @ManagedAttribute(description = "Formatter show exchange pattern")
303        public boolean getFormatterShowExchangePattern() {
304            if (tracer.getDefaultTraceFormatter() == null) {
305                return false;
306            }
307            return tracer.getDefaultTraceFormatter().isShowExchangePattern();
308        }
309    
310        @ManagedAttribute(description = "Formatter show exchange pattern")
311        public void setFormatterShowExchangePattern(boolean showExchangePattern) {
312            if (tracer.getDefaultTraceFormatter() == null) {
313                return;
314            }
315            tracer.getDefaultTraceFormatter().setShowExchangePattern(showExchangePattern);
316        }
317    
318        @ManagedAttribute(description = "Formatter show exception")
319        public boolean getFormatterShowException() {
320            if (tracer.getDefaultTraceFormatter() == null) {
321                return false;
322            }
323            return tracer.getDefaultTraceFormatter().isShowException();
324        }
325    
326        @ManagedAttribute(description = "Formatter show exception")
327        public void setFormatterShowException(boolean showException) {
328            if (tracer.getDefaultTraceFormatter() == null) {
329                return;
330            }
331            tracer.getDefaultTraceFormatter().setShowException(showException);
332        }
333    
334        @ManagedAttribute(description = "Formatter show route id")
335        public boolean getFormatterShowRouteId() {
336            if (tracer.getDefaultTraceFormatter() == null) {
337                return false;
338            }
339            return tracer.getDefaultTraceFormatter().isShowRouteId();
340        }
341    
342        @ManagedAttribute(description = "Formatter show route id")
343        public void setFormatterShowRouteId(boolean showRouteId) {
344            if (tracer.getDefaultTraceFormatter() == null) {
345                return;
346            }
347            tracer.getDefaultTraceFormatter().setShowRouteId(showRouteId);
348        }
349    
350        @ManagedAttribute(description = "Formatter breadcrumb length")
351        public int getFormatterBreadCrumbLength() {
352            if (tracer.getDefaultTraceFormatter() == null) {
353                return 0;
354            }
355            return tracer.getDefaultTraceFormatter().getBreadCrumbLength();
356        }
357    
358        @ManagedAttribute(description = "Formatter breadcrumb length")
359        public void setFormatterBreadCrumbLength(int breadCrumbLength) {
360            if (tracer.getDefaultTraceFormatter() == null) {
361                return;
362            }
363            tracer.getDefaultTraceFormatter().setBreadCrumbLength(breadCrumbLength);
364        }
365    
366        @ManagedAttribute(description = "Formatter show short exchange id")
367        public boolean getFormatterShowShortExchangeId() {
368            if (tracer.getDefaultTraceFormatter() == null) {
369                return false;
370            }
371            return tracer.getDefaultTraceFormatter().isShowShortExchangeId();
372        }
373    
374        @ManagedAttribute(description = "Formatter show short exchange id")
375        public void setFormatterShowShortExchangeId(boolean showShortExchangeId) {
376            if (tracer.getDefaultTraceFormatter() == null) {
377                return;
378            }
379            tracer.getDefaultTraceFormatter().setShowShortExchangeId(showShortExchangeId);
380        }
381    
382        @ManagedAttribute(description = "Formatter node length")
383        public int getFormatterNodeLength() {
384            if (tracer.getDefaultTraceFormatter() == null) {
385                return 0;
386            }
387            return tracer.getDefaultTraceFormatter().getNodeLength();
388        }
389    
390        @ManagedAttribute(description = "Formatter node length")
391        public void setFormatterNodeLength(int nodeLength) {
392            if (tracer.getDefaultTraceFormatter() == null) {
393                return;
394            }
395            tracer.getDefaultTraceFormatter().setNodeLength(nodeLength);
396        }
397    
398        @ManagedAttribute(description = "Formatter max chars")
399        public int getFormatterMaxChars() {
400            if (tracer.getDefaultTraceFormatter() == null) {
401                return 0;
402            }
403            return tracer.getDefaultTraceFormatter().getMaxChars();
404        }
405    
406        @ManagedAttribute(description = "Formatter max chars")
407        public void setFormatterMaxChars(int maxChars) {
408            if (tracer.getDefaultTraceFormatter() == null) {
409                return;
410            }
411            tracer.getDefaultTraceFormatter().setMaxChars(maxChars);
412        }
413    
414    }