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.Map;
020
021import org.apache.camel.Endpoint;
022import org.apache.camel.StaticService;
023
024/**
025 * Registry to cache endpoints in memory.
026 * <p/>
027 * The registry contains two caches:
028 * <ul>
029 *     <li>static - which keeps all the endpoints in the cache for the entire lifecycle</li>
030 *     <li>dynamic - which keeps the endpoints in a {@link org.apache.camel.util.LRUCache} and may evict endpoints which hasn't been requested recently</li>
031 * </ul>
032 * The static cache stores all the endpoints that are created as part of setting up and starting routes.
033 * The static cache has no upper limit.
034 * <p/>
035 * The dynamic cache stores the endpoints that are created and used ad-hoc, such as from custom Java code that creates new endpoints etc.
036 * The dynamic cache has an upper limit, that by default is 1000 entries.
037 *
038 * @param <K> endpoint key
039 */
040public interface EndpointRegistry<K> extends Map<K, Endpoint>, StaticService {
041
042    /**
043     * Number of endpoints in the static registry.
044     */
045    int staticSize();
046
047    /**
048     * Number of endpoints in the dynamic registry
049     */
050    int dynamicSize();
051
052    /**
053     * Maximum number of entries to store in the dynamic registry
054     */
055    int getMaximumCacheSize();
056
057    /**
058     * Purges the cache (removes endpoints from the dynamic cache)
059     */
060    void purge();
061
062    /**
063     * Whether the given endpoint is stored in the static cache
064     *
065     * @param key  the endpoint key
066     * @return <tt>true</tt> if in static cache, <tt>false</tt> if not
067     */
068    boolean isStatic(String key);
069
070    /**
071     * Whether the given endpoint is stored in the dynamic cache
072     *
073     * @param key  the endpoint key
074     * @return <tt>true</tt> if in dynamic cache, <tt>false</tt> if not
075     */
076    boolean isDynamic(String key);
077
078    /**
079     * Cleanup the cache (purging stale entries)
080     */
081    void cleanUp();
082
083}