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 */ 017 package 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 * 025 * @version $Revision: 779038 $ 026 */ 027 public interface ServicePool<Key, Service> extends org.apache.camel.Service { 028 029 /** 030 * Adds the given service to the pool and acquires it. 031 * 032 * @param key the key 033 * @param service the service 034 * @return the acquired service, is newer <tt>null</tt> 035 */ 036 Service addAndAcquire(Key key, Service service); 037 038 /** 039 * Tries to acquire the servie with the given key 040 * 041 * @param key the key 042 * @return the acquired service, or <tt>null</tt> if no free in pool 043 */ 044 Service acquire(Key key); 045 046 /** 047 * Releases the service back to the pool 048 * 049 * @param key the key 050 * @param service the service 051 */ 052 void release(Key key, Service service); 053 054 }