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