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.validator.ValidatorDefinition; 025 026/** 027 * Registry to cache validators in memory. 028 * <p/> 029 * The registry contains two caches: 030 * <ul> 031 * <li>static - which keeps all the validators in the cache for the entire lifecycle</li> 032 * <li>dynamic - which keeps the validators in a {@link org.apache.camel.util.LRUCache} and may evict validators which hasn't been requested recently</li> 033 * </ul> 034 * The static cache stores all the validators 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 validators that are created and used ad-hoc, such as from custom Java code that creates new validators etc. 038 * The dynamic cache has an upper limit, that by default is 1000 entries. 039 * 040 * @param <K> validator key 041 */ 042public interface ValidatorRegistry<K> extends Map<K, Validator>, StaticService { 043 044 /** 045 * Lookup a {@link Validator} in the registry which supports the validation for 046 * the data type represented by the key. 047 * @param key a key represents the data type 048 * @return {@link Validator} if matched, otherwise null 049 */ 050 Validator resolveValidator(K key); 051 052 /** 053 * Number of validators in the static registry. 054 */ 055 int staticSize(); 056 057 /** 058 * Number of validators 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 validators from the dynamic cache) 069 */ 070 void purge(); 071 072 /** 073 * Whether the given {@link Validator} is stored in the static cache 074 * 075 * @param type the data type 076 * @return <tt>true</tt> if in static cache, <tt>false</tt> if not 077 */ 078 boolean isStatic(DataType type); 079 080 /** 081 * Whether the given {@link Validator} is stored in the dynamic cache 082 * 083 * @param type the data type 084 * @return <tt>true</tt> if in dynamic cache, <tt>false</tt> if not 085 */ 086 boolean isDynamic(DataType type); 087 088 /** 089 * Cleanup the cache (purging stale entries) 090 */ 091 void cleanUp(); 092 093}