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
019/**
020 * A service pool is like a connection pool but can pool any kind of objects.
021 * <p/>
022 * Services that is capable of being pooled should implement the marker interface
023 * {@link org.apache.camel.ServicePoolAware}.
024 * <p/>
025 * Notice the capacity is <b>per key</b> which means that each key can contain at most
026 * (the capacity) services. The pool can contain an unbounded number of keys.
027 * <p/>
028 * By default the capacity is set to 100.
029 *
030 * @version 
031 */
032@Deprecated
033public interface ServicePool<Key, Service> {
034
035    /**
036     * Sets the capacity, which is capacity <b>per key</b>.
037     *
038     * @param capacity the capacity per key
039     */
040    void setCapacity(int capacity);
041
042    /**
043     * Gets the capacity per key.
044     *
045     * @return the capacity per key
046     */
047    int getCapacity();
048
049    /**
050     * Adds the given service to the pool and acquires it.
051     *
052     * @param key     the key
053     * @param service the service
054     * @return the acquired service, is newer <tt>null</tt>
055     * @throws IllegalStateException if the queue is full (capacity has been reached)
056     */
057    Service addAndAcquire(Key key, Service service);
058
059    /**
060     * Tries to acquire the service with the given key
061     *
062     * @param key the key
063     * @return the acquired service, or <tt>null</tt> if no free in pool
064     */
065    Service acquire(Key key);
066
067    /**
068     * Releases the service back to the pool
069     *
070     * @param key     the key
071     * @param service the service
072     */
073    void release(Key key, Service service);
074
075    /**
076     * Returns the current size of the pool
077     *
078     * @return the current size of the pool
079     */
080    int size();
081
082    /**
083     * Purges the pool.
084     */
085    void purge();
086
087}