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 java.util.Map; 020import javax.management.openmbean.CompositeData; 021import javax.management.openmbean.CompositeDataSupport; 022import javax.management.openmbean.CompositeType; 023import javax.management.openmbean.TabularData; 024import javax.management.openmbean.TabularDataSupport; 025 026import org.apache.camel.CamelContext; 027import org.apache.camel.api.management.ManagedResource; 028import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes; 029import org.apache.camel.api.management.mbean.ManagedRecipientListMBean; 030import org.apache.camel.model.RecipientListDefinition; 031import org.apache.camel.processor.RecipientList; 032import org.apache.camel.spi.EndpointUtilizationStatistics; 033import org.apache.camel.spi.ManagementStrategy; 034import org.apache.camel.util.ObjectHelper; 035import org.apache.camel.util.URISupport; 036 037/** 038 * @version 039 */ 040@ManagedResource(description = "Managed RecipientList") 041public class ManagedRecipientList extends ManagedProcessor implements ManagedRecipientListMBean { 042 private final RecipientList processor; 043 private String uri; 044 private boolean sanitize; 045 046 public ManagedRecipientList(CamelContext context, RecipientList processor, RecipientListDefinition definition) { 047 super(context, processor, definition); 048 this.processor = processor; 049 } 050 051 @Override 052 public void init(ManagementStrategy strategy) { 053 super.init(strategy); 054 sanitize = strategy.getManagementAgent().getMask() != null ? strategy.getManagementAgent().getMask() : false; 055 uri = getDefinition().getExpression().getExpression(); 056 if (sanitize) { 057 uri = URISupport.sanitizeUri(uri); 058 } 059 } 060 061 @Override 062 public synchronized void reset() { 063 super.reset(); 064 if (processor.getEndpointUtilizationStatistics() != null) { 065 processor.getEndpointUtilizationStatistics().clear(); 066 } 067 } 068 069 @Override 070 public Boolean getSupportExtendedInformation() { 071 return true; 072 } 073 074 @Override 075 public RecipientListDefinition getDefinition() { 076 return (RecipientListDefinition) super.getDefinition(); 077 } 078 079 @Override 080 public String getExpressionLanguage() { 081 return getDefinition().getExpression().getLanguage(); 082 } 083 084 @Override 085 public String getExpression() { 086 return uri; 087 } 088 089 @Override 090 public String getUriDelimiter() { 091 return processor.getDelimiter(); 092 } 093 094 @Override 095 public Integer getCacheSize() { 096 return processor.getCacheSize(); 097 } 098 099 @Override 100 public Boolean isParallelAggregate() { 101 return processor.isParallelAggregate(); 102 } 103 104 @Override 105 public Boolean isParallelProcessing() { 106 return processor.isParallelProcessing(); 107 } 108 109 @Override 110 public Boolean isStreaming() { 111 return processor.isStreaming(); 112 } 113 114 @Override 115 public Boolean isStopOnException() { 116 return processor.isStopOnException(); 117 } 118 119 @Override 120 public Boolean isShareUnitOfWork() { 121 return processor.isShareUnitOfWork(); 122 } 123 124 @Override 125 public Long getTimeout() { 126 return processor.getTimeout(); 127 } 128 129 @Override 130 public TabularData extendedInformation() { 131 try { 132 TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.endpointsUtilizationTabularType()); 133 134 EndpointUtilizationStatistics stats = processor.getEndpointUtilizationStatistics(); 135 if (stats != null) { 136 for (Map.Entry<String, Long> entry : stats.getStatistics().entrySet()) { 137 CompositeType ct = CamelOpenMBeanTypes.endpointsUtilizationCompositeType(); 138 String url = entry.getKey(); 139 if (sanitize) { 140 url = URISupport.sanitizeUri(url); 141 } 142 143 Long hits = entry.getValue(); 144 if (hits == null) { 145 hits = 0L; 146 } 147 148 CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "hits"}, new Object[]{url, hits}); 149 answer.put(data); 150 } 151 } 152 return answer; 153 } catch (Exception e) { 154 throw ObjectHelper.wrapRuntimeCamelException(e); 155 } 156 } 157 158}