1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.cache.memcached;
16  
17  import net.spy.memcached.MemcachedClientIF;
18  
19  import org.apache.commons.pool.ObjectPool;
20  
21  /**
22   * <a href="PooledMemcachedClientFactory.java.html"><b><i>View Source</i></b>
23   * </a>
24   *
25   * @author Michael C. Han
26   */
27  public class PooledMemcachedClientFactory implements MemcachedClientFactory {
28  
29      public MemcachedClientIF getMemcachedClient() throws Exception {
30          return (MemcachedClientIF)_memcachedClientPool.borrowObject();
31      }
32  
33      public void clear() throws Exception {
34          _memcachedClientPool.clear();
35      }
36  
37      public void close() throws Exception {
38          _memcachedClientPool.close();
39      }
40  
41      public void destroy() {
42          try {
43              close();
44          }
45          catch (Exception e) {
46          }
47      }
48  
49      public int getNumActive() {
50          return _memcachedClientPool.getNumActive();
51      }
52  
53      public int getNumIdle() {
54          return _memcachedClientPool.getNumIdle();
55      }
56  
57      public void invalidateMemcachedClient(MemcachedClientIF memcachedClient)
58          throws Exception {
59  
60          _memcachedClientPool.invalidateObject(memcachedClient);
61      }
62  
63      public void returnMemcachedObject(MemcachedClientIF memcachedClient)
64          throws Exception {
65  
66          _memcachedClientPool.returnObject(memcachedClient);
67      }
68  
69      public void setMemcachedClientPool(ObjectPool memcachedClientPool) {
70          _memcachedClientPool = memcachedClientPool;
71      }
72  
73      private ObjectPool _memcachedClientPool;
74  
75  }