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