camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] camel git commit: CAMEL-10530 Introduce TransformerRegistry
Date Tue, 20 Dec 2016 12:36:49 GMT
CAMEL-10530 Introduce TransformerRegistry


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/892f9be4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/892f9be4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/892f9be4

Branch: refs/heads/master
Commit: 892f9be42bb92be425aa30dddc23e50290fa6fe9
Parents: 29ccf72
Author: Tomohisa Igarashi <tm.igarashi@gmail.com>
Authored: Tue Dec 13 16:38:20 2016 +0900
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Dec 20 13:36:39 2016 +0100

----------------------------------------------------------------------
 .../management/mbean/CamelOpenMBeanTypes.java   |  12 ++
 .../mbean/ManagedTransformerRegistryMBean.java  |  47 ++++
 .../apache/camel/impl/DefaultCamelContext.java  |   5 +-
 .../camel/impl/DefaultTransformerRegistry.java  | 213 +++++++++++++++++++
 .../DefaultManagementLifecycleStrategy.java     |   4 +
 .../mbean/ManagedTransformerRegistry.java       | 102 +++++++++
 .../apache/camel/spi/TransformerRegistry.java   |  83 ++++++++
 .../ManagedTransformerRegistryTest.java         |  89 ++++++++
 8 files changed, 554 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
index 25edc09..da73e90 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/CamelOpenMBeanTypes.java
@@ -216,4 +216,16 @@ public final class CamelOpenMBeanTypes {
                 new OpenType[]{SimpleType.STRING, SimpleType.LONG});
     }
 
+    public static TabularType listTransformersTabularType() throws OpenDataException {
+        CompositeType ct = listTransformersCompositeType();
+        return new TabularType("listTransformers", "Lists all the transformers in the registry",
ct, new String[]{"string"});
+        
+    }
+
+    public static CompositeType listTransformersCompositeType() throws OpenDataException
{
+        return new CompositeType("transformers", "Transformers",
+                                 new String[]{"string", "static", "dynamic"},
+                                 new String[]{"string", "Static", "Dynamic"},
+                                 new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTransformerRegistryMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTransformerRegistryMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTransformerRegistryMBean.java
new file mode 100644
index 0000000..de6441e
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTransformerRegistryMBean.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.api.management.mbean;
+
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedOperation;
+
+public interface ManagedTransformerRegistryMBean extends ManagedServiceMBean {
+
+    @ManagedAttribute(description = "Source")
+    String getSource();
+
+    @ManagedAttribute(description = "Number of dynamic transformers cached")
+    Integer getDynamicSize();
+
+    @ManagedAttribute(description = "Number of static transformers cached")
+    Integer getStaticSize();
+
+    @ManagedAttribute(description = "Number of total transformers cached")
+    Integer getSize();
+
+    @ManagedAttribute(description = "Maximum cache size (capacity)")
+    Integer getMaximumCacheSize();
+
+    @ManagedOperation(description = "Purges the cache")
+    void purge();
+
+    @ManagedOperation(description = "Lists all the transformers in the registry")
+    TabularData listTransformers();
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index a9b30a4..5372b90 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -156,6 +156,7 @@ import org.apache.camel.spi.ServicePool;
 import org.apache.camel.spi.ShutdownStrategy;
 import org.apache.camel.spi.StreamCachingStrategy;
 import org.apache.camel.spi.Transformer;
+import org.apache.camel.spi.TransformerRegistry;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.spi.UnitOfWorkFactory;
 import org.apache.camel.spi.UuidGenerator;
@@ -283,7 +284,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
     private Date startDate;
     private ModelJAXBContextFactory modelJAXBContextFactory;
     private List<TransformerDefinition> transformers = new ArrayList<TransformerDefinition>();
-    private Map<TransformerKey, Transformer> transformerRegistry = new HashMap<TransformerKey,
Transformer>();
+    private TransformerRegistry<TransformerKey> transformerRegistry;
     private ReloadStrategy reloadStrategy;
 
     /**
@@ -297,6 +298,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
 
         // create endpoint registry at first since end users may access endpoints before
CamelContext is started
         this.endpoints = new DefaultEndpointRegistry(this);
+        this.transformerRegistry = new DefaultTransformerRegistry(this);
 
         // add the defer service startup listener
         this.startupListeners.add(deferStartupListener);
@@ -3124,6 +3126,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
             log.info("Using ReloadStrategy: {}", reloadStrategy);
             addService(reloadStrategy, true, true);
         }
+        addService(transformerRegistry, true, true);
 
         if (runtimeEndpointRegistry != null) {
             if (runtimeEndpointRegistry instanceof EventNotifier) {

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
b/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
new file mode 100644
index 0000000..f371267
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultTransformerRegistry.java
@@ -0,0 +1,213 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.transformer.TransformerKey;
+import org.apache.camel.spi.EndpointRegistry;
+import org.apache.camel.spi.Transformer;
+import org.apache.camel.spi.TransformerRegistry;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.LRUCache;
+import org.apache.camel.util.ServiceHelper;
+
+/**
+ * Default implementation of {@link org.apache.camel.spi.TransformerRegistry}
+ */
+public class DefaultTransformerRegistry extends LRUCache<TransformerKey, Transformer>
implements TransformerRegistry<TransformerKey> {
+    private static final long serialVersionUID = 1L;
+    private ConcurrentMap<TransformerKey, Transformer> staticMap;
+    private final CamelContext context;
+
+    public DefaultTransformerRegistry(CamelContext context) {
+        // do not stop on eviction, as the endpoint may still be in use
+        super(CamelContextHelper.getMaximumEndpointCacheSize(context), CamelContextHelper.getMaximumEndpointCacheSize(context),
false);
+        // static map to hold endpoints we do not want to be evicted
+        this.staticMap = new ConcurrentHashMap<TransformerKey, Transformer>();
+        this.context = context;
+    }
+
+    public DefaultTransformerRegistry(CamelContext context, Map<TransformerKey, Transformer>
transformers) {
+        this(context);
+        putAll(transformers);
+    }
+
+    @Override
+    public void start() throws Exception {
+        resetStatistics();
+    }
+
+    @Override
+    public Transformer get(Object o) {
+        // try static map first
+        Transformer answer = staticMap.get(o);
+        if (answer == null) {
+            answer = super.get(o);
+        } else {
+            hits.incrementAndGet();
+        }
+        return answer;
+    }
+
+    @Override
+    public Transformer put(TransformerKey key, Transformer transformer) {
+        // at first we must see if the key already exists and then replace it back, so it
stays the same spot
+        Transformer answer = staticMap.remove(key);
+        if (answer != null) {
+            // replace existing
+            staticMap.put(key, transformer);
+            return answer;
+        }
+
+        answer = super.remove(key);
+        if (answer != null) {
+            // replace existing
+            super.put(key, transformer);
+            return answer;
+        }
+
+        // we want endpoints to be static if they are part of setting up or starting routes
+        if (context.isSetupRoutes() || context.isStartingRoutes()) {
+            answer = staticMap.put(key, transformer);
+        } else {
+            answer = super.put(key, transformer);
+        }
+
+        return answer;
+    }
+
+    @Override
+    public void putAll(Map<? extends TransformerKey, ? extends Transformer> map) {
+        // need to use put instead of putAll to ensure the entries gets added to either static
or dynamic map
+        for (Map.Entry<? extends TransformerKey, ? extends Transformer> entry : map.entrySet())
{
+            put(entry.getKey(), entry.getValue());
+        }
+    }
+
+    @Override
+    public boolean containsKey(Object o) {
+        return staticMap.containsKey(o) || super.containsKey(o);
+    }
+
+    @Override
+    public boolean containsValue(Object o) {
+        return staticMap.containsValue(o) || super.containsValue(o);
+    }
+
+    @Override
+    public int size() {
+        return staticMap.size() + super.size();
+    }
+
+    public int staticSize() {
+        return staticMap.size();
+    }
+
+    @Override
+    public int dynamicSize() {
+        return super.size();
+    }
+
+    @Override
+    public boolean isEmpty() {
+        return staticMap.isEmpty() && super.isEmpty();
+    }
+
+    @Override
+    public Transformer remove(Object o) {
+        Transformer answer = staticMap.remove(o);
+        if (answer == null) {
+            answer = super.remove(o);
+        }
+        return answer;
+    }
+
+    @Override
+    public void clear() {
+        staticMap.clear();
+        super.clear();
+    }
+
+    @Override
+    public Set<TransformerKey> keySet() {
+        Set<TransformerKey> answer = new LinkedHashSet<TransformerKey>();
+        answer.addAll(staticMap.keySet());
+        answer.addAll(super.keySet());
+        return answer;
+    }
+
+    @Override
+    public Collection<Transformer> values() {
+        Collection<Transformer> answer = new ArrayList<Transformer>();
+        answer.addAll(staticMap.values());
+        answer.addAll(super.values());
+        return answer;
+    }
+
+    @Override
+    public Set<Entry<TransformerKey, Transformer>> entrySet() {
+        Set<Entry<TransformerKey, Transformer>> answer = new LinkedHashSet<Entry<TransformerKey,
Transformer>>();
+        answer.addAll(staticMap.entrySet());
+        answer.addAll(super.entrySet());
+        return answer;
+    }
+
+    @Override
+    public int getMaximumCacheSize() {
+        return super.getMaxCacheSize();
+    }
+
+    /**
+     * Purges the cache
+     */
+    @Override
+    public void purge() {
+        // only purge the dynamic part
+        super.clear();
+    }
+
+    @Override
+    public boolean isStatic(String key) {
+        return staticMap.containsKey(new EndpointKey(key));
+    }
+
+    @Override
+    public boolean isDynamic(String key) {
+        return super.containsKey(new EndpointKey(key));
+    }
+
+    @Override
+    public void stop() throws Exception {
+        ServiceHelper.stopServices(staticMap.values());
+        ServiceHelper.stopServices(values());
+        purge();
+    }
+
+    @Override
+    public String toString() {
+        return "TransformerRegistry for " + context.getName() + ", capacity: " + getMaxCacheSize();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 34c8d5e..6a2b58d 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -49,6 +49,7 @@ import org.apache.camel.api.management.PerformanceCounter;
 import org.apache.camel.impl.ConsumerCache;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.impl.DefaultEndpointRegistry;
+import org.apache.camel.impl.DefaultTransformerRegistry;
 import org.apache.camel.impl.EventDrivenConsumerRoute;
 import org.apache.camel.impl.ProducerCache;
 import org.apache.camel.impl.ThrottlingInflightRoutePolicy;
@@ -68,6 +69,7 @@ import org.apache.camel.management.mbean.ManagedService;
 import org.apache.camel.management.mbean.ManagedStreamCachingStrategy;
 import org.apache.camel.management.mbean.ManagedThrottlingInflightRoutePolicy;
 import org.apache.camel.management.mbean.ManagedTracer;
+import org.apache.camel.management.mbean.ManagedTransformerRegistry;
 import org.apache.camel.management.mbean.ManagedTypeConverterRegistry;
 import org.apache.camel.model.AOPDefinition;
 import org.apache.camel.model.InterceptDefinition;
@@ -487,6 +489,8 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport
implement
             answer = new ManagedStreamCachingStrategy(context, (StreamCachingStrategy) service);
         } else if (service instanceof EventNotifier) {
             answer = getManagementObjectStrategy().getManagedObjectForEventNotifier(context,
(EventNotifier) service);
+        } else if (service instanceof DefaultTransformerRegistry) {
+            answer = new ManagedTransformerRegistry(context, (DefaultTransformerRegistry)service);
         } else if (service != null) {
             // fallback as generic service
             answer = getManagementObjectStrategy().getManagedObjectForService(context, service);

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTransformerRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTransformerRegistry.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTransformerRegistry.java
new file mode 100644
index 0000000..e1373b7
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTransformerRegistry.java
@@ -0,0 +1,102 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management.mbean;
+
+import java.util.Collection;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes;
+import org.apache.camel.api.management.mbean.ManagedTransformerRegistryMBean;
+import org.apache.camel.spi.EndpointRegistry;
+import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spi.Transformer;
+import org.apache.camel.spi.TransformerRegistry;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
+
+/**
+ * @version 
+ */
+@ManagedResource(description = "Managed TransformerRegistry")
+public class ManagedTransformerRegistry extends ManagedService implements ManagedTransformerRegistryMBean
{
+    private final TransformerRegistry transformerRegistry;
+
+    public ManagedTransformerRegistry(CamelContext context, TransformerRegistry endpointRegistry)
{
+        super(context, endpointRegistry);
+        this.transformerRegistry = endpointRegistry;
+    }
+
+    public void init(ManagementStrategy strategy) {
+        super.init(strategy);
+    }
+
+    public TransformerRegistry getTransformerRegistry() {
+        return transformerRegistry;
+    }
+
+    public String getSource() {
+        return transformerRegistry.toString();
+    }
+
+    public Integer getDynamicSize() {
+        return transformerRegistry.dynamicSize();
+    }
+
+    public Integer getStaticSize() {
+        return transformerRegistry.staticSize();
+    }
+
+    public Integer getSize() {
+        return transformerRegistry.size();
+    }
+
+    public Integer getMaximumCacheSize() {
+        return transformerRegistry.getMaximumCacheSize();
+    }
+
+    public void purge() {
+        transformerRegistry.purge();
+    }
+
+    @SuppressWarnings("unchecked")
+    public TabularData listTransformers() {
+        try {
+            TabularData answer = new TabularDataSupport(CamelOpenMBeanTypes.listTransformersTabularType());
+            Collection<Transformer> transformers = transformerRegistry.values();
+            for (Transformer transformer : transformers) {
+                CompositeType ct = CamelOpenMBeanTypes.listTransformersCompositeType();
+                String transformerString = transformer.toString();
+                boolean fromStatic = transformerRegistry.isStatic(transformerString);
+                boolean fromDynamic = transformerRegistry.isDynamic(transformerString);
+
+                CompositeData data = new CompositeDataSupport(ct, new String[]{"string",
"static", "dynamic"}, new Object[]{transformerString, fromStatic, fromDynamic});
+                answer.put(data);
+            }
+            return answer;
+        } catch (Exception e) {
+            throw ObjectHelper.wrapRuntimeCamelException(e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/main/java/org/apache/camel/spi/TransformerRegistry.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/TransformerRegistry.java b/camel-core/src/main/java/org/apache/camel/spi/TransformerRegistry.java
new file mode 100644
index 0000000..2ec1be6
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/TransformerRegistry.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.StaticService;
+
+/**
+ * Registry to cache transformers in memory.
+ * <p/>
+ * The registry contains two caches:
+ * <ul>
+ *     <li>static - which keeps all the transformers in the cache for the entire lifecycle</li>
+ *     <li>dynamic - which keeps the transformers in a {@link org.apache.camel.util.LRUCache}
and may evict transformers which hasn't been requested recently</li>
+ * </ul>
+ * The static cache stores all the transformers that are created as part of setting up and
starting routes.
+ * The static cache has no upper limit.
+ * <p/>
+ * The dynamic cache stores the transformers that are created and used ad-hoc, such as from
custom Java code that creates new transformers etc.
+ * The dynamic cache has an upper limit, that by default is 1000 entries.
+ *
+ * @param <K> transformer key
+ */
+public interface TransformerRegistry<K> extends Map<K, Transformer>, StaticService
{
+
+    /**
+     * Number of transformers in the static registry.
+     */
+    int staticSize();
+
+    /**
+     * Number of transformers in the dynamic registry
+     */
+    int dynamicSize();
+
+    /**
+     * Maximum number of entries to store in the dynamic registry
+     */
+    int getMaximumCacheSize();
+
+    /**
+     * Purges the cache (removes transformers from the dynamic cache)
+     */
+    void purge();
+
+    /**
+     * Whether the given transformer is stored in the static cache
+     *
+     * @param key  the transformer key
+     * @return <tt>true</tt> if in static cache, <tt>false</tt> if
not
+     */
+    boolean isStatic(String key);
+
+    /**
+     * Whether the given transformer is stored in the dynamic cache
+     *
+     * @param key  the transformer key
+     * @return <tt>true</tt> if in dynamic cache, <tt>false</tt>
if not
+     */
+    boolean isDynamic(String key);
+
+    /**
+     * Cleanup the cache (purging stale entries)
+     */
+    void cleanUp();
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/892f9be4/camel-core/src/test/java/org/apache/camel/management/ManagedTransformerRegistryTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedTransformerRegistryTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedTransformerRegistryTest.java
new file mode 100644
index 0000000..2960cb1
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedTransformerRegistryTest.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.TabularData;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class ManagedTransformerRegistryTest extends ManagementTestSupport {
+
+    public void testManageTransformerRegistry() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        // get the stats for the route
+        MBeanServer mbeanServer = getMBeanServer();
+        Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=services,*"),
null);
+        List<ObjectName> list = new ArrayList<ObjectName>(set);
+        ObjectName on = null;
+        for (ObjectName name : list) {
+            if (name.getCanonicalName().contains("DefaultTransformerRegistry")) {
+                on = name;
+                break;
+            }
+        }
+
+        assertNotNull("Should have found TransformerRegistry", on);
+
+        Integer max = (Integer) mbeanServer.getAttribute(on, "MaximumCacheSize");
+        assertEquals(1000, max.intValue());
+
+        Integer current = (Integer) mbeanServer.getAttribute(on, "Size");
+        assertEquals(0, current.intValue());
+
+        current = (Integer) mbeanServer.getAttribute(on, "StaticSize");
+        assertEquals(0, current.intValue());
+
+        current = (Integer) mbeanServer.getAttribute(on, "DynamicSize");
+        assertEquals(0, current.intValue());
+
+        String source = (String) mbeanServer.getAttribute(on, "Source");
+        assertTrue(source.startsWith("TransformerRegistry"));
+        assertTrue(source.endsWith("capacity: 1000"));
+
+        TabularData data = (TabularData) mbeanServer.invoke(on, "listTransformers", null,
null);
+        assertEquals(0, data.size());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("mock:result");
+            }
+        };
+    }
+
+}
\ No newline at end of file


Mime
View raw message