KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > entity > TreeCacheProviderHook


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.entity;
23
24 import java.util.Properties JavaDoc;
25
26 import org.hibernate.cache.Cache;
27 import org.hibernate.cache.CacheException;
28 import org.hibernate.cache.CacheProvider;
29
30 /**
31  * Support for a standalone JBossCache (TreeCache) instance. The JBossCache is configured
32  * via a local config resource.
33  *
34  * @author Gavin King
35  */

36 public class TreeCacheProviderHook implements CacheProvider
37 {
38    private TransactionalCacheFactory cacheFactory;
39
40    /**
41     * Construct and configure the Cache representation of a named cache region.
42     *
43     * @param regionName the name of the cache region
44     * @param properties configuration settings
45     * @return The Cache representation of the named cache region.
46     * @throws org.hibernate.cache.CacheException
47     * Indicates an error building the cache region.
48     */

49    public Cache buildCache(String JavaDoc regionName, Properties JavaDoc properties) throws CacheException
50    {
51 // return new TreeCache(cache, regionName, TxUtil.getTransactionManager());
52
return cacheFactory.buildCache(regionName, properties);
53    }
54
55    public boolean isMinimalPutsEnabledByDefault()
56    {
57       return false;
58    }
59
60    public long nextTimestamp()
61    {
62       return System.currentTimeMillis() / 100;
63    }
64
65    /**
66     * Prepare the underlying JBossCache TreeCache instance.
67     *
68     * @param properties All current config settings.
69     * @throws org.hibernate.cache.CacheException
70     * Indicates a problem preparing cache for use.
71     */

72    public void start(Properties JavaDoc properties)
73    {
74       cacheFactory = TransactionalCacheFactory.getFactory(properties);
75 // try
76
// {
77
// ObjectName mbeanObjectName = new ObjectName((String) properties.get("hibernate.treecache.mbean.object_name"));
78
// TreeCacheMBean mbean = (TreeCacheMBean) MBeanProxyExt.create(TreeCacheMBean.class, mbeanObjectName, MBeanServerLocator.locateJBoss());
79
// cache = mbean.getInstance();
80
// }
81
// catch (Exception e)
82
// {
83
// throw new CacheException(e);
84
// }
85
}
86
87    public void stop()
88    {
89    }
90
91 }
92
Popular Tags