treecachepool.java

来自「羽量级数据持久层开发框架」· Java 代码 · 共 74 行

JAVA
74
字号
package org.speedframework.cache;

import org.jboss.cache.TreeCache;
import org.speedframework.exception.SpeedFrameworkException;

/**
 * JBoss Cache Pool
 * 
 * @author lizf
 * 
 */
public class TreeCachePool implements CachePool {

	/**
	 * 
	 */
	private static final String SPEED_CACHE = "CACHE";

	private static TreeCache cache = null;

	public TreeCachePool() {
		try {
			if (cache == null) {
				cache = new TreeCache();
				cache.setClusterProperties("treecache.xml");
				cache.createService();
				cache.startService();
			}
		} catch (Exception e) {
			// TODO 自动生成 catch 块
			throw new SpeedFrameworkException(e);
		}

	}

	public synchronized void put(Object name, Object value)
			throws SpeedFrameworkException {
		try {
			cache.put(SPEED_CACHE, name, value);
		} catch (org.jboss.cache.CacheException e) {
			throw new SpeedFrameworkException(e);
		}
	}

	public synchronized Object get(Object name) throws SpeedFrameworkException {
		Object value = null;
		try {
			value = cache.get(SPEED_CACHE, name);
		} catch (org.jboss.cache.CacheException e) {
			// throw new CacheException(e);
			throw new SpeedFrameworkException(e);
		}
		return value;

	}

	public String getStats() {
		// return ( (TreeCache) cachePool.get(key))
		return null;
	}

	public void dispose() {
		cache.destroy();
	}

	public synchronized void remove(Object name) throws SpeedFrameworkException {
		try {
			cache.remove(SPEED_CACHE, name);
		} catch (org.jboss.cache.CacheException e) {
			throw new SpeedFrameworkException(e);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?