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 javax.management.openmbean.CompositeData; 020import javax.management.openmbean.CompositeDataSupport; 021import javax.management.openmbean.CompositeType; 022import javax.management.openmbean.TabularData; 023import javax.management.openmbean.TabularDataSupport; 024 025import org.apache.camel.CamelContext; 026import org.apache.camel.RuntimeCamelException; 027import org.apache.camel.api.management.ManagedResource; 028import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes; 029import org.apache.camel.api.management.mbean.ManagedSendProcessorMBean; 030import org.apache.camel.model.ProcessorDefinition; 031import org.apache.camel.processor.SendProcessor; 032import org.apache.camel.spi.ManagementStrategy; 033import org.apache.camel.util.URISupport; 034 035@ManagedResource(description = "Managed SendProcessor") 036public class ManagedSendProcessor extends ManagedProcessor implements ManagedSendProcessorMBean { 037 private final SendProcessor processor; 038 private String destination; 039 040 public ManagedSendProcessor(CamelContext context, SendProcessor processor, ProcessorDefinition<?> definition) { 041 super(context, processor, definition); 042 this.processor = processor; 043 } 044 045 @Override 046 public void init(ManagementStrategy strategy) { 047 super.init(strategy); 048 boolean sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; 049 if (sanitize) { 050 destination = URISupport.sanitizeUri(processor.getDestination().getEndpointUri()); 051 } else { 052 destination = processor.getDestination().getEndpointUri(); 053 } 054 } 055 056 @Override 057 public Boolean getSupportExtendedInformation() { 058 return true; 059 } 060 061 @Override 062 public void reset() { 063 super.reset(); 064 processor.reset(); 065 } 066 067 @Override 068 public SendProcessor getProcessor() { 069 return processor; 070 } 071 072 @Override 073 public String getDestination() { 074 return destination; 075 } 076 077 @Override 078 public String getVariableSend() { 079 return processor.getVariableSend(); 080 } 081 082 @Override 083 public String getVariableReceive() { 084 return processor.getVariableReceive(); 085 } 086 087 @Override 088 public String getMessageExchangePattern() { 089 if (processor.getPattern() != null) { 090 return processor.getPattern().name(); 091 } else { 092 return null; 093 } 094 } 095 096 @Override 097 public TabularData extendedInformation() { 098 try { 099 TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.endpointsUtilizationTabularType()); 100 101 // we only have 1 endpoint 102 CompositeType ct = CamelOpenMBeanTypes.endpointsUtilizationCompositeType(); 103 String url = getDestination(); 104 long hits = processor.getCounter(); 105 106 CompositeData data = new CompositeDataSupport(ct, new String[] { "url", "hits" }, new Object[] { url, hits }); 107 answer.put(data); 108 return answer; 109 } catch (Exception e) { 110 throw RuntimeCamelException.wrapRuntimeCamelException(e); 111 } 112 } 113}