1 /***
2 * @(#)JCSCacheServiceImpl.java
3 *
4 * JFoxSOAF, Service-Oriented Application Framework
5 *
6 * Copyright(c) JFoxSOAF Team
7 *
8 * Licensed under the GNU LGPL, Version 2.1 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.gnu.org/copyleft/lesser.html
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 *
20 * For more information, please visit:
21 * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
22 * http://www.huihoo.org/jfox/jfoxsoaf
23 */
24
25 package org.huihoo.jfox.soaf.services.cache;
26
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.apache.jcs.JCS;
30 import org.apache.jcs.access.exception.CacheException;
31 import org.huihoo.jfox.soaf.exception.CacheServiceException;
32
33 /***
34 * <p>
35 * Support for Apache Turbine's JCS
36 * </p>
37 *
38 * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
39 * @author <a href="mailto:m.bogaert@intrasoft.be">Mathias Bogaert </a>
40 * @version $Revision: 1.1 $ $Date: 2005/05/22 06:48:52 $
41 * @version Revision: 1.0
42 */
43
44 public class JCSCacheServiceImpl implements CacheService {
45
46 private static final Log log = LogFactory.getLog(JCSCacheServiceImpl.class);
47
48 private JCS cache;
49
50 /***
51 * Constructor with given param.
52 */
53 public JCSCacheServiceImpl(String regionName) throws CacheServiceException {
54 try {
55 cache = JCS.getInstance(regionName);
56 } catch (CacheException e) {
57 log.error("could not create JCS region", e);
58 throw new CacheServiceException(e);
59 }
60 }
61
62 /***
63 * @see org.huihoo.jfox.soaf.services.cache.CacheService#get(java.lang.Object)
64 */
65 public Object get(Object key) throws CacheServiceException {
66 return cache.get(key);
67 }
68
69 /***
70 * @see org.huihoo.jfox.soaf.services.cache.CacheService#put(java.lang.Object,
71 * java.lang.Object)
72 */
73 public void put(Object key, Object value) throws CacheServiceException {
74 try {
75 cache.put(key, value);
76 } catch (CacheException e) {
77 log.error("could not add to JCS region", e);
78 throw new CacheServiceException(e);
79 }
80 }
81
82 /***
83 * @see org.huihoo.jfox.soaf.services.cache.CacheService#remove(java.lang.Object)
84 */
85 public void remove(Object key) throws CacheServiceException {
86 try {
87 cache.remove(key);
88 } catch (CacheException e) {
89 log.error("could not remove from JCS region", e);
90 throw new CacheServiceException(e);
91 }
92 }
93
94 /***
95 * @see org.huihoo.jfox.soaf.services.cache.CacheService#clear()
96 */
97 public void clear() throws CacheServiceException {
98 try {
99 cache.remove();
100 } catch (CacheException e) {
101 log.error("could not remove from JCS region", e);
102 throw new CacheServiceException(e);
103 }
104 }
105 }