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 String destination; 038 039 public ManagedSendProcessor(CamelContext context, SendProcessor processor, ProcessorDefinition<?> definition) { 040 super(context, processor, definition); 041 } 042 043 @Override 044 public void init(ManagementStrategy strategy) { 045 super.init(strategy); 046 boolean sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : true; 047 if (sanitize) { 048 destination = URISupport.sanitizeUri(getProcessor().getDestination().getEndpointUri()); 049 } else { 050 destination = getProcessor().getDestination().getEndpointUri(); 051 } 052 } 053 054 @Override 055 public Boolean getSupportExtendedInformation() { 056 return true; 057 } 058 059 @Override 060 public void reset() { 061 super.reset(); 062 getProcessor().reset(); 063 } 064 065 @Override 066 public SendProcessor getProcessor() { 067 return (SendProcessor) super.getProcessor(); 068 } 069 070 @Override 071 public String getDestination() { 072 return destination; 073 } 074 075 @Override 076 public String getVariableSend() { 077 return getProcessor().getVariableSend(); 078 } 079 080 @Override 081 public String getVariableReceive() { 082 return getProcessor().getVariableReceive(); 083 } 084 085 @Override 086 public String getMessageExchangePattern() { 087 if (getProcessor().getPattern() != null) { 088 return getProcessor().getPattern().name(); 089 } else { 090 return null; 091 } 092 } 093 094 @Override 095 public TabularData extendedInformation() { 096 try { 097 TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.endpointsUtilizationTabularType()); 098 099 // we only have 1 endpoint 100 CompositeType ct = CamelOpenMBeanTypes.endpointsUtilizationCompositeType(); 101 String url = getDestination(); 102 long hits = getProcessor().getCounter(); 103 104 CompositeData data = new CompositeDataSupport(ct, new String[] { "url", "hits" }, new Object[] { url, hits }); 105 answer.put(data); 106 return answer; 107 } catch (Exception e) { 108 throw RuntimeCamelException.wrapRuntimeCamelException(e); 109 } 110 } 111}