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