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 java.util.Set; 020 021 import org.apache.camel.CamelContext; 022 import org.apache.camel.NoTypeConversionAvailableException; 023 import org.apache.camel.api.management.ManagedResource; 024 import org.apache.camel.api.management.mbean.ManagedBacklogDebuggerMBean; 025 import org.apache.camel.processor.interceptor.BacklogDebugger; 026 import org.apache.camel.spi.ManagementStrategy; 027 import org.apache.camel.util.ObjectHelper; 028 029 @ManagedResource(description = "Managed BacklogDebugger") 030 public class ManagedBacklogDebugger implements ManagedBacklogDebuggerMBean { 031 032 private final CamelContext camelContext; 033 private final BacklogDebugger backlogDebugger; 034 035 public ManagedBacklogDebugger(CamelContext camelContext, BacklogDebugger backlogDebugger) { 036 this.camelContext = camelContext; 037 this.backlogDebugger = backlogDebugger; 038 } 039 040 public void init(ManagementStrategy strategy) { 041 // do nothing 042 } 043 044 public CamelContext getContext() { 045 return camelContext; 046 } 047 048 public BacklogDebugger getBacklogDebugger() { 049 return backlogDebugger; 050 } 051 052 public String getLoggingLevel() { 053 return backlogDebugger.getLoggingLevel(); 054 } 055 056 public void setLoggingLevel(String level) { 057 backlogDebugger.setLoggingLevel(level); 058 } 059 060 public boolean isEnabled() { 061 return backlogDebugger.isEnabled(); 062 } 063 064 public void enableDebugger() { 065 backlogDebugger.enableDebugger(); 066 } 067 068 public void disableDebugger() { 069 backlogDebugger.disableDebugger(); 070 } 071 072 public void addBreakpoint(String nodeId) { 073 backlogDebugger.addBreakpoint(nodeId); 074 } 075 076 public void addConditionalBreakpoint(String nodeId, String language, String predicate) { 077 backlogDebugger.addConditionalBreakpoint(nodeId, language, predicate); 078 } 079 080 public void removeBreakpoint(String nodeId) { 081 backlogDebugger.removeBreakpoint(nodeId); 082 } 083 084 public void removeAllBreakpoints() { 085 backlogDebugger.removeAllBreakpoints(); 086 } 087 088 public Set<String> getBreakpoints() { 089 return backlogDebugger.getBreakpoints(); 090 } 091 092 public void resumeBreakpoint(String nodeId) { 093 backlogDebugger.resumeBreakpoint(nodeId); 094 } 095 096 public void setMessageBodyOnBreakpoint(String nodeId, Object body) { 097 backlogDebugger.setMessageBodyOnBreakpoint(nodeId, body); 098 } 099 100 public void setMessageBodyOnBreakpoint(String nodeId, Object body, String type) { 101 try { 102 Class<?> classType = camelContext.getClassResolver().resolveMandatoryClass(type); 103 backlogDebugger.setMessageBodyOnBreakpoint(nodeId, body, classType); 104 } catch (ClassNotFoundException e) { 105 throw ObjectHelper.wrapRuntimeCamelException(e); 106 } 107 } 108 109 public void removeMessageBodyOnBreakpoint(String nodeId) { 110 backlogDebugger.removeMessageBodyOnBreakpoint(nodeId); 111 } 112 113 public void setMessageHeaderOnBreakpoint(String nodeId, String headerName, Object value) { 114 try { 115 backlogDebugger.setMessageHeaderOnBreakpoint(nodeId, headerName, value); 116 } catch (NoTypeConversionAvailableException e) { 117 throw ObjectHelper.wrapRuntimeCamelException(e); 118 } 119 } 120 121 public void setMessageHeaderOnBreakpoint(String nodeId, String headerName, Object value, String type) { 122 try { 123 Class<?> classType = camelContext.getClassResolver().resolveMandatoryClass(type); 124 backlogDebugger.setMessageHeaderOnBreakpoint(nodeId, headerName, value, classType); 125 } catch (Exception e) { 126 throw ObjectHelper.wrapRuntimeCamelException(e); 127 } 128 } 129 130 public void removeMessageHeaderOnBreakpoint(String nodeId, String headerName) { 131 backlogDebugger.removeMessageHeaderOnBreakpoint(nodeId, headerName); 132 } 133 134 public void resumeAll() { 135 backlogDebugger.resumeAll(); 136 } 137 138 public void stepBreakpoint(String nodeId) { 139 backlogDebugger.stepBreakpoint(nodeId); 140 } 141 142 public boolean isSingleStepMode() { 143 return backlogDebugger.isSingleStepMode(); 144 } 145 146 public void step() { 147 backlogDebugger.step(); 148 } 149 150 public Set<String> getSuspendedBreakpointNodeIds() { 151 return backlogDebugger.getSuspendedBreakpointNodeIds(); 152 } 153 154 public void disableBreakpoint(String nodeId) { 155 backlogDebugger.disableBreakpoint(nodeId); 156 } 157 158 public void enableBreakpoint(String nodeId) { 159 backlogDebugger.enableBreakpoint(nodeId); 160 } 161 162 public int getBodyMaxChars() { 163 return backlogDebugger.getBodyMaxChars(); 164 } 165 166 public void setBodyMaxChars(int bodyMaxChars) { 167 backlogDebugger.setBodyMaxChars(bodyMaxChars); 168 } 169 170 public boolean isBodyIncludeStreams() { 171 return backlogDebugger.isBodyIncludeStreams(); 172 } 173 174 public void setBodyIncludeStreams(boolean bodyIncludeStreams) { 175 backlogDebugger.setBodyIncludeStreams(bodyIncludeStreams); 176 } 177 178 public boolean isBodyIncludeFiles() { 179 return backlogDebugger.isBodyIncludeFiles(); 180 } 181 182 public void setBodyIncludeFiles(boolean bodyIncludeFiles) { 183 backlogDebugger.setBodyIncludeFiles(bodyIncludeFiles); 184 } 185 186 public String dumpTracedMessagesAsXml(String nodeId) { 187 return backlogDebugger.dumpTracedMessagesAsXml(nodeId); 188 } 189 190 public long getDebugCounter() { 191 return backlogDebugger.getDebugCounter(); 192 } 193 194 public void resetDebugCounter() { 195 backlogDebugger.resetDebugCounter(); 196 } 197 198 }