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