You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ap...@apache.org on 2009/08/03 15:27:35 UTC

svn commit: r800367 - in /mina/sandbox/vysper/trunk/server/core/src: main/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImpl.java test/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImplTest.java test/resources/ehcache.xml

Author: apaliwal
Date: Mon Aug  3 13:27:34 2009
New Revision: 800367

URL: http://svn.apache.org/viewvc?rev=800367&view=rev
Log:
JIRA Issue: VYSPER-166
Submitted By: apaliwal at apache.org

Added support for configuring ehcache.xml file. Added the config file to resources

Added:
    mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml   (with props)
Modified:
    mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImpl.java
    mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImplTest.java

Modified: mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImpl.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImpl.java?rev=800367&r1=800366&r2=800367&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImpl.java (original)
+++ mina/sandbox/vysper/trunk/server/core/src/main/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImpl.java Mon Aug  3 13:27:34 2009
@@ -55,20 +55,30 @@
     // Cache instance to store presence information against JID
     private Cache jidPresenceCache = null;
 
+    // Default ehcache configuration file
+    private static final String DEFAULT_EHCACHE_CONFIG_FILE = "/ehcache.xml";
+
     /**
      * Defaulr Contructor
+     *
+     * @param configFile    ehcache configuration file
      */
-    public EhCachePresenceCacheImpl() {
-        createCache();
+    public EhCachePresenceCacheImpl(String configFile) {
+        createCache(configFile);
     }
 
     /**
      * Create the ehcache based on ehcache.xml file
      * Create two cache instances to store PresenceStanza against Entity and
      * JID
+     *
+     * @param configFile    ehcache configuration file
      */
-    protected void createCache() {
-        URL configFileURL = getClass().getResource("/ehcache.xml");
+    protected void createCache(String configFile) {
+        if(configFile == null) {
+            configFile = DEFAULT_EHCACHE_CONFIG_FILE;            
+        }
+        URL configFileURL = getClass().getResource(configFile);
         if(configFileURL == null) {
             throw new RuntimeException("ehcache configuration file ehcache.xml not found on classpath");
         }
@@ -82,7 +92,7 @@
      * @inheritDoc
      */
     @Override
-    public void put0(Entity entity, PresenceStanza presenceStanza)
+    protected void put0(Entity entity, PresenceStanza presenceStanza)
                                     throws PresenceCachingException {
         // Create EhCache elements to be stored
         Element cacheElement = new Element(entity, presenceStanza);
@@ -96,7 +106,7 @@
      * @inheritDoc
      */
     @Override
-    public PresenceStanza get0(Entity entity) throws PresenceCachingException {
+    protected PresenceStanza get0(Entity entity) throws PresenceCachingException {
         // Get the Element from cache
         Element cacheElement = presenceCache.get(entity);
 

Modified: mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImplTest.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImplTest.java?rev=800367&r1=800366&r2=800367&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImplTest.java (original)
+++ mina/sandbox/vysper/trunk/server/core/src/test/java/org/apache/vysper/xmpp/state/presence/EhCachePresenceCacheImplTest.java Mon Aug  3 13:27:34 2009
@@ -32,7 +32,7 @@
  */
 public class EhCachePresenceCacheImplTest extends LatestPresenceCacheTestCase {
 
-    LatestPresenceCache presenceCache  = new EhCachePresenceCacheImpl();
+    LatestPresenceCache presenceCache  = new EhCachePresenceCacheImpl(null);
 
     @Override
     protected void setUp() throws Exception {
@@ -98,12 +98,11 @@
 
     /**
      * Returns an Entity to be used as a key
-     * @return
+     * @return  Entity instance
      */
     protected Entity getEntity() {
         try {
-            Entity entity = EntityImpl.parse("tester@apache.org/test");
-            return entity;
+            return EntityImpl.parse("tester@apache.org/test");
         } catch (Exception e) {
             return null;
         }

Added: mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml?rev=800367&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml (added)
+++ mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml Mon Aug  3 13:27:34 2009
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:noNamespaceSchemaLocation="ehcache.xsd" >
+
+    <!--
+    CacheManager Configuration
+    ==========================
+    An ehcache.xml corresponds to a single CacheManager.
+
+    See instructions below or the ehcache schema (ehcache.xsd) on how to configure.
+
+    System property tokens can be specified in this file which are replaced when the configuration
+    is loaded. For example multicastGroupPort=${multicastGroupPort} can be replaced with the
+    System property either from an environment variable or a system property specified with a
+    command line switch such as -DmulticastGroupPort=4446.
+
+    DiskStore configuration
+    =======================
+
+    The diskStore element is optional. To turn off disk store path creation, comment out the diskStore
+    element below.
+
+    Configure it if you have overflowToDisk or diskPersistent enabled for any cache.
+
+    If it is not configured, and a cache is created which requires a disk store, a warning will be
+     issued and java.io.tmpdir will automatically be used.
+
+    diskStore has only one attribute - "path". It is the path to the directory where
+    .data and .index files will be created.
+
+    If the path is one of the following Java System Property it is replaced by its value in the
+    running VM. For backward compatibility these are not specified without being enclosed in the ${token}
+    replacement syntax.
+
+    The following properties are translated:
+    * user.home - User's home directory
+    * user.dir - User's current working directory
+    * java.io.tmpdir - Default temp file path
+    * ehcache.disk.store.dir - A system property you would normally specify on the command line
+      e.g. java -Dehcache.disk.store.dir=/u01/myapp/diskdir ...
+
+    Subdirectories can be specified below the property e.g. java.io.tmpdir/one
+
+    -->
+    <diskStore path="java.io.tmpdir"/>
+
+
+    <!--
+    Mandatory Default Cache configuration. These settings will be applied to caches
+    created programmtically using CacheManager.add(String cacheName).
+
+    The defaultCache has an implicit name "default" which is a reserved cache name.
+    -->
+    <defaultCache
+            maxElementsInMemory="10000"
+            eternal="false"
+            timeToIdleSeconds="120"
+            timeToLiveSeconds="120"
+            overflowToDisk="false"
+            diskSpoolBufferSizeMB="30"
+            maxElementsOnDisk="10000000"
+            diskPersistent="false"
+            diskExpiryThreadIntervalSeconds="120"
+            memoryStoreEvictionPolicy="LRU"
+            />
+
+    <!--
+    	Caches
+    -->
+
+    <!--
+    	Cache for Presence with Entity as key
+    -->
+    <cache name="PresenceCache"
+           maxElementsInMemory="10000"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LRU"/>
+
+	<!--
+    	Cache for Presence with JID as key
+    -->
+    <cache name="JIDCache"
+           maxElementsInMemory="10000"
+           eternal="true"
+           overflowToDisk="false"
+           memoryStoreEvictionPolicy="LRU"/>
+
+</ehcache>
\ No newline at end of file

Propchange: mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: mina/sandbox/vysper/trunk/server/core/src/test/resources/ehcache.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml