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.spi; 018 019import java.util.List; 020import java.util.Map; 021 022import org.apache.camel.Endpoint; 023import org.apache.camel.StaticService; 024import org.apache.camel.model.transformer.TransformerDefinition; 025 026/** 027 * Registry to cache transformers in memory. 028 * <p/> 029 * The registry contains two caches: 030 * <ul> 031 * <li>static - which keeps all the transformers in the cache for the entire lifecycle</li> 032 * <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> 033 * </ul> 034 * The static cache stores all the transformers that are created as part of setting up and starting routes. 035 * The static cache has no upper limit. 036 * <p/> 037 * The dynamic cache stores the transformers that are created and used ad-hoc, such as from custom Java code that creates new transformers etc. 038 * The dynamic cache has an upper limit, that by default is 1000 entries. 039 * 040 * @param <K> transformer key 041 */ 042public interface TransformerRegistry<K> extends Map<K, Transformer>, StaticService { 043 044 /** 045 * Lookup a {@link Transformer} in the registry which supports the transformation for 046 * the data types represented by the key. 047 * @param key a key represents the from/to data types to transform 048 * @return {@link Transformer} if matched, otherwise null 049 */ 050 Transformer resolveTransformer(K key); 051 052 /** 053 * Number of transformers in the static registry. 054 */ 055 int staticSize(); 056 057 /** 058 * Number of transformers in the dynamic registry 059 */ 060 int dynamicSize(); 061 062 /** 063 * Maximum number of entries to store in the dynamic registry 064 */ 065 int getMaximumCacheSize(); 066 067 /** 068 * Purges the cache (removes transformers from the dynamic cache) 069 */ 070 void purge(); 071 072 /** 073 * Whether the given transformer is stored in the static cache 074 * 075 * @param scheme the scheme supported by this transformer 076 * @return <tt>true</tt> if in static cache, <tt>false</tt> if not 077 */ 078 boolean isStatic(String scheme); 079 080 /** 081 * Whether the given transformer is stored in the static cache 082 * 083 * @param from 'from' data type 084 * @param to 'to' data type 085 * @return <tt>true</tt> if in static cache, <tt>false</tt> if not 086 */ 087 boolean isStatic(DataType from, DataType to); 088 089 /** 090 * Whether the given transformer is stored in the dynamic cache 091 * 092 * @param scheme the scheme supported by this transformer 093 * @return <tt>true</tt> if in dynamic cache, <tt>false</tt> if not 094 */ 095 boolean isDynamic(String scheme); 096 097 /** 098 * Whether the given {@link Transformer} is stored in the dynamic cache 099 * 100 * @param from 'from' data type 101 * @param to 'to' data type 102 * @return <tt>true</tt> if in dynamic cache, <tt>false</tt> if not 103 */ 104 boolean isDynamic(DataType from, DataType to); 105 106 /** 107 * Cleanup the cache (purging stale entries) 108 */ 109 void cleanUp(); 110 111}