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.Collection; 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.Endpoint; 028import org.apache.camel.api.management.ManagedResource; 029import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes; 030import org.apache.camel.api.management.mbean.ManagedEndpointRegistryMBean; 031import org.apache.camel.spi.EndpointRegistry; 032import org.apache.camel.util.ObjectHelper; 033 034/** 035 * @version 036 */ 037@ManagedResource(description = "Managed EndpointRegistry") 038public class ManagedEndpointRegistry extends ManagedService implements ManagedEndpointRegistryMBean { 039 private final EndpointRegistry endpointRegistry; 040 041 public ManagedEndpointRegistry(CamelContext context, EndpointRegistry endpointRegistry) { 042 super(context, endpointRegistry); 043 this.endpointRegistry = endpointRegistry; 044 } 045 046 public EndpointRegistry getEndpointRegistry() { 047 return endpointRegistry; 048 } 049 050 public String getSource() { 051 return endpointRegistry.toString(); 052 } 053 054 public Integer getDynamicSize() { 055 return endpointRegistry.dynamicSize(); 056 } 057 058 public Integer getStaticSize() { 059 return endpointRegistry.staticSize(); 060 } 061 062 public Integer getSize() { 063 return endpointRegistry.size(); 064 } 065 066 public Integer getMaximumCacheSize() { 067 return endpointRegistry.getMaximumCacheSize(); 068 } 069 070 public void purge() { 071 endpointRegistry.purge(); 072 } 073 074 @SuppressWarnings("unchecked") 075 public TabularData listEndpoints() { 076 try { 077 TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listEndpointsTabularType()); 078 Collection<Endpoint> endpoints = endpointRegistry.values(); 079 for (Endpoint endpoint : endpoints) { 080 CompositeType ct = CamelOpenMBeanTypes.listEndpointsCompositeType(); 081 String url = endpoint.getEndpointUri(); 082 083 boolean fromStatic = endpointRegistry.isStatic(url); 084 boolean fromDynamic = endpointRegistry.isDynamic(url); 085 086 CompositeData data = new CompositeDataSupport(ct, new String[]{"url", "static", "dynamic"}, new Object[]{url, fromStatic, fromDynamic}); 087 answer.put(data); 088 } 089 return answer; 090 } catch (Exception e) { 091 throw ObjectHelper.wrapRuntimeCamelException(e); 092 } 093 } 094 095}