You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by Kevin Brown <et...@google.com> on 2008/08/27 21:15:40 UTC

Re: svn commit: r689568 - in /incubator/shindig/trunk: ./ java/common/ java/common/src/main/bundle/ java/common/src/main/bundle/org/ java/common/src/main/bundle/org/apache/ java/common/src/main/bundle/org/apache/shindig/ java/common/src/main/bundle/o

Would it make sense to have a separate artifact for this? I'm not familiar
enough with maven to understand how the stuff in main/bundle gets packaged.

On Wed, Aug 27, 2008 at 12:08 PM, <ie...@apache.org> wrote:

> Author: ieb
> Date: Wed Aug 27 12:08:36 2008
> New Revision: 689568
>
> URL: http://svn.apache.org/viewvc?rev=689568&view=rev
> Log:
> Adding implementation of the CacheProvider with EhCache and the unit tests
> for code coverage.
> This is not the default cache, but is covered by unit tests in both the
> Common project and the Gadgets project.
> The unit tests in the Gadget project only ensure that the
> BasicHttpCacheTest will also work for EhCache.
>
> To use this Cache implementation its necessary to add
> EhCacheGuiceCacheModule to the list of modules being loaded.
> Implementors may also want to modify both ehcacheConfig.xml and
> ehcache.properties to configure the cache appropriately
> for their environment.
>
> Added:
>    incubator/shindig/trunk/java/common/src/main/bundle/
>    incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf
>    incubator/shindig/trunk/java/common/src/main/bundle/ehcache.properties
>    incubator/shindig/trunk/java/common/src/main/bundle/org/
>    incubator/shindig/trunk/java/common/src/main/bundle/org/apache/
>    incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/
>
>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/
>
>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/
>
>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/ehcache/
>
>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml
>
>  incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/
>
>  incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
>
>  incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>
>  incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhConfiguredCache.java
>
>  incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/
>
>  incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>
>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpEhCacheTest.java
> Modified:
>    incubator/shindig/trunk/java/common/pom.xml
>
>  incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/DefaultCacheProvider.java
>
>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
>    incubator/shindig/trunk/pom.xml
>
> Modified: incubator/shindig/trunk/java/common/pom.xml
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/pom.xml?rev=689568&r1=689567&r2=689568&view=diff
>
> ==============================================================================
> --- incubator/shindig/trunk/java/common/pom.xml (original)
> +++ incubator/shindig/trunk/java/common/pom.xml Wed Aug 27 12:08:36 2008
> @@ -89,5 +89,9 @@
>       <groupId>org.json</groupId>
>       <artifactId>json</artifactId>
>     </dependency>
> +    <dependency>
> +      <groupId>net.sf.ehcache</groupId>
> +      <artifactId>ehcache</artifactId>
> +    </dependency>
>   </dependencies>
>  </project>
>
> Added: incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf?rev=689568&view=auto
>
> ==============================================================================
> --- incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf (added)
> +++ incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf Wed Aug
> 27 12:08:36 2008
> @@ -0,0 +1,14 @@
> +jcs.default=
> +jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
> +jcs.default.cacheattributes.MaxObjects=10000
>
> +jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
> +jcs.default.cacheattributes.UseMemoryShrinker=false
> +jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
> +jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
> +jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
> +jcs.default.elementattributes.IsEternal=false
> +jcs.default.elementattributes.MaxLifeSeconds=21600
> +jcs.default.elementattributes.IdleTime=1800
> +jcs.default.elementattributes.IsSpool=true
> +jcs.default.elementattributes.IsRemote=true
> +jcs.default.elementattributes.IsLateral=true
>
> Added:
> incubator/shindig/trunk/java/common/src/main/bundle/ehcache.properties
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/bundle/ehcache.properties?rev=689568&view=auto
>
> ==============================================================================
> --- incubator/shindig/trunk/java/common/src/main/bundle/ehcache.properties
> (added)
> +++ incubator/shindig/trunk/java/common/src/main/bundle/ehcache.properties
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,2 @@
> +cache.config=/org/apache/shindig/cache/ehcache/ehcacheConfig.xml
> +cache.jmx.stats=true
> \ No newline at end of file
>
> Added:
> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml?rev=689568&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml
> (added)
> +++
> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,22 @@
> +<?xml version="1.0" encoding="UTF-8"?>
> +<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +  xsi:noNamespaceSchemaLocation="ehcache.xsd">
> +
> +
> +
> +  <!--
> +    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="600" timeToLiveSeconds="600"
> +    overflowToDisk="false" diskPersistent="false"
> +    memoryStoreEvictionPolicy="LRU" />
> +
> +
> +
> +
> +
> +</ehcache>
> \ No newline at end of file
>
> Modified:
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/DefaultCacheProvider.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/DefaultCacheProvider.java?rev=689568&r1=689567&r2=689568&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/DefaultCacheProvider.java
> (original)
> +++
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/DefaultCacheProvider.java
> Wed Aug 27 12:08:36 2008
> @@ -29,7 +29,7 @@
>  @Singleton
>  public class DefaultCacheProvider implements CacheProvider {
>
> -  Map<String, Cache<?, ?>> cacheInstances = new HashMap<String, Cache<?,
> ?>>();
> +  private Map<String, Cache<?, ?>> cacheInstances = new HashMap<String,
> Cache<?, ?>>();
>
>   /*
>    * (non-Javadoc)
> @@ -47,7 +47,7 @@
>           c = new LruCache<K, V>(capacity);
>           cacheInstances.put(name, c);
>         }
> -        return c;
> +        return c;
>       }
>     }
>   }
>
> Added:
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java?rev=689568&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
> (added)
> +++
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProvider.java
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,123 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.common.cache.ehcache;
> +
> +import net.sf.ehcache.CacheManager;
> +import net.sf.ehcache.management.ManagementService;
> +
> +import org.apache.shindig.common.cache.Cache;
> +import org.apache.shindig.common.cache.CacheProvider;
> +
> +import com.google.inject.Inject;
> +import com.google.inject.name.Named;
> +
> +import javax.management.MBeanServer;
> +
> +import java.lang.management.ManagementFactory;
> +import java.net.URL;
> +import java.util.HashMap;
> +import java.util.Map;
> +
> +/**
> + *
> + */
> +public class EhCacheCacheProvider implements CacheProvider {
> +
> +  private CacheManager cacheManager;
> +  private Map<String, Cache<?, ?>> caches = new HashMap<String, Cache<?,
> ?>>();
> +
> +  public EhCacheCacheProvider() {
> +    create("/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml",
> "true");
> +  }
> +
> +  @Inject
> +  public EhCacheCacheProvider(@Named("cache.config")
> +  String configPath, @Named("cache.jmx.stats")
> +  String withCacheStatistics) {
> +    create(configPath, withCacheStatistics);
> +  }
> +
> +  public void create(String configPath, String withCacheStatistics) {
> +    URL url = getClass().getResource(configPath);
> +    cacheManager = new CacheManager(url);
> +
> +    /*
> +     * Add in a shutdown hook
> +     */
> +    Runtime.getRuntime().addShutdownHook(new Thread() {
> +      /*
> +       * (non-Javadoc)
> +       *
> +       * @see java.lang.Thread#run()
> +       */
> +      @Override
> +      public void run() {
> +        try {
> +          shutdown();
> +        } catch (Throwable t) {
> +
> +          // I really do want to swallow this, and make the shutdown clean
> for
> +          // others
> +        }
> +      }
> +    });
> +
> +    // register the cache manager with JMX
> +    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
> +    ManagementService.registerMBeans(cacheManager, mBeanServer, true,
> true, true, Boolean.valueOf(
> +        withCacheStatistics).booleanValue());
> +
> +  }
> +
> +  /**
> +   * perform a shutdown
> +   */
> +  public void shutdown() {
> +    cacheManager.shutdown();
> +  }
> +
> +  /*
> +   * (non-Javadoc)
> +   *
> +   * @see org.apache.shindig.common.cache.CacheProvider#createCache(int)
> +   */
> +  public <K, V> Cache<K, V> createCache(int capacity) {
> +    return createCache(capacity, null);
> +  }
> +
> +  /*
> +   * (non-Javadoc)
> +   *
> +   * @see org.apache.shindig.common.cache.CacheProvider#createCache(int,
> java.lang.String)
> +   */
> +  @SuppressWarnings("unchecked")
> +  public <K, V> Cache<K, V> createCache(int capacity, String name) {
> +    if (name == null) {
> +      return new EhConfiguredCache<K, V>(capacity, name, cacheManager);
> +    } else {
> +      Cache<K, V> c = (Cache<K, V>) caches.get(name);
> +      if (c == null) {
> +        c = new EhConfiguredCache<K, V>(capacity, name, cacheManager);
> +        caches.put(name, c);
> +      }
> +      return c;
> +    }
> +  }
> +
> +}
>
> Added:
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java?rev=689568&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
> (added)
> +++
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,68 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.common.cache.ehcache;
> +
> +import java.io.IOException;
> +import java.io.InputStream;
> +import java.util.Arrays;
> +import java.util.Properties;
> +
> +import org.apache.shindig.common.cache.CacheProvider;
> +import org.apache.shindig.common.util.ResourceLoader;
> +
> +import com.google.inject.AbstractModule;
> +import com.google.inject.CreationException;
> +import com.google.inject.Scopes;
> +import com.google.inject.name.Names;
> +import com.google.inject.spi.Message;
> +
> +/**
> + * Creates a module to supply a EhCache Provider
> + */
> +public class EhCacheGuiceCacheModule extends AbstractModule {
> +  private final Properties properties;
> +  private final static String DEFAULT_PROPERTIES = "ehcache.properties";
> +
> +  /** {@inheritDoc} */
> +  @Override
> +  protected void configure() {
> +    Names.bindProperties(this.binder(), properties);
> +
>  bind(CacheProvider.class).to(EhCacheCacheProvider.class).in(Scopes.SINGLETON);
> +  }
> +
> +  public EhCacheGuiceCacheModule(Properties properties) {
> +    this.properties = properties;
> +  }
> +
> +  /**
> +   * Creates module with standard properties.
> +   */
> +  public EhCacheGuiceCacheModule() {
> +    Properties properties = null;
> +    try {
> +      InputStream is = ResourceLoader.openResource(DEFAULT_PROPERTIES);
> +      properties = new Properties();
> +      properties.load(is);
> +    } catch (IOException e) {
> +      throw new CreationException(Arrays.asList(new Message("Unable to
> load properties: "
> +          + DEFAULT_PROPERTIES)));
> +    }
> +    this.properties = properties;
> +  }
> +}
>
> Added:
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhConfiguredCache.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhConfiguredCache.java?rev=689568&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhConfiguredCache.java
> (added)
> +++
> incubator/shindig/trunk/java/common/src/main/java/org/apache/shindig/common/cache/ehcache/EhConfiguredCache.java
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,84 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.common.cache.ehcache;
> +
> +import net.sf.ehcache.CacheManager;
> +import net.sf.ehcache.Element;
> +
> +import org.apache.shindig.common.cache.Cache;
> +
> +/**
> + *
> + */
> +public class EhConfiguredCache<K, V> implements Cache<K, V> {
> +
> +  private net.sf.ehcache.Cache cache;
> +
> +  public EhConfiguredCache(int capacity, String cacheName, CacheManager
> cacheManager) {
> +    if (cacheName == null) {
> +      cacheName = "default";
> +    }
> +    synchronized (cacheManager) {
> +      cache = cacheManager.getCache(cacheName);
> +      if (cache == null) {
> +        cacheManager.addCache(cacheName);
> +        cache = cacheManager.getCache(cacheName);
> +        if (cache == null) {
> +          throw new RuntimeException("Failed to create Cache with name " +
> cacheName);
> +        }
> +      }
> +    }
> +  }
> +
> +  /*
> +   * (non-Javadoc)
> +   *
> +   * @see
> org.apache.shindig.common.cache.Cache#addElement(java.lang.Object,
> java.lang.Object)
> +   */
> +  public void addElement(K key, V value) {
> +    cache.put(new Element(key, value));
> +  }
> +
> +  /*
> +   * (non-Javadoc)
> +   *
> +   * @see
> org.apache.shindig.common.cache.Cache#getElement(java.lang.Object)
> +   */
> +  @SuppressWarnings("unchecked")
> +  public V getElement(K key) {
> +    Element cacheElement = cache.get(key);
> +    if (cacheElement != null) {
> +      return (V) cacheElement.getObjectValue();
> +    }
> +    return null;
> +  }
> +
> +  /*
> +   * (non-Javadoc)
> +   *
> +   * @see
> org.apache.shindig.common.cache.Cache#removeElement(java.lang.Object)
> +   */
> +  @SuppressWarnings("unchecked")
> +  public V removeElement(K key) {
> +    Object value = getElement(key);
> +    cache.remove(key);
> +    return (V) value;
> +  }
> +
> +}
>
> Added:
> incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java?rev=689568&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
> (added)
> +++
> incubator/shindig/trunk/java/common/src/test/java/org/apache/shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,106 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + *   http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + */
> +package org.apache.shindig.common.cache.ehcache;
> +
> +import org.apache.shindig.common.cache.Cache;
> +import org.apache.shindig.common.cache.CacheProvider;
> +import org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider;
> +
> +import com.google.inject.Guice;
> +import com.google.inject.Injector;
> +
> +import org.junit.Test;
> +import org.junit.Assert;
> +
> +/**
> + *
> + */
> +public class EhCacheCacheProviderTest {
> +
> +  @Test
> +  public void getAnonCache() {
> +    CacheProvider defaultProvider = new EhCacheCacheProvider(
> +        "/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml",
> "true");
> +    Cache<String, String> cache = defaultProvider.createCache(100);
> +    Assert.assertNotNull(cache);
> +    Assert.assertNull(cache.getElement("test"));
> +    cache.addElement("test", "value1");
> +    Assert.assertEquals(cache.getElement("test"), "value1");
> +    cache.removeElement("test");
> +    Assert.assertNull(cache.getElement("test"));
> +
> +  }
> +
> +  @Test
> +  public void getNamedCache() {
> +    CacheProvider defaultProvider = new EhCacheCacheProvider(
> +        "/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml",
> "true");
> +    Cache<String, String> cache = defaultProvider.createCache(100,
> "testcache");
> +    Cache<String, String> cache2 = defaultProvider.createCache(100,
> "testcache");
> +    Assert.assertNotNull(cache);
> +    Assert.assertEquals(cache, cache2);
> +    Assert.assertNull(cache.getElement("test"));
> +    cache.addElement("test", "value1");
> +    Assert.assertEquals(cache.getElement("test"), "value1");
> +    cache.removeElement("test");
> +    Assert.assertNull(cache.getElement("test"));
> +  }
> +
> +  @Test
> +  public void getAnonCacheNoConfig() {
> +    CacheProvider defaultProvider = new EhCacheCacheProvider();
> +    Cache<String, String> cache = defaultProvider.createCache(100);
> +    Assert.assertNotNull(cache);
> +    Assert.assertNull(cache.getElement("test"));
> +    cache.addElement("test", "value1");
> +    Assert.assertEquals(cache.getElement("test"), "value1");
> +    cache.removeElement("test");
> +    Assert.assertNull(cache.getElement("test"));
> +
> +  }
> +
> +  @Test
> +  public void getNamedCacheNoConfig() {
> +    CacheProvider defaultProvider = new EhCacheCacheProvider();
> +    Cache<String, String> cache = defaultProvider.createCache(100,
> "testcache");
> +    Cache<String, String> cache2 = defaultProvider.createCache(100,
> "testcache");
> +    Assert.assertNotNull(cache);
> +    Assert.assertEquals(cache, cache2);
> +    Assert.assertNull(cache.getElement("test"));
> +    cache.addElement("test", "value1");
> +    Assert.assertEquals(cache.getElement("test"), "value1");
> +    cache.removeElement("test");
> +    Assert.assertNull(cache.getElement("test"));
> +  }
> +
> +  @Test
> +  public void testGuiceModule() {
> +    Injector i = Guice.createInjector(new EhCacheGuiceCacheModule());
> +    CacheProvider cacheProvider = i.getInstance(CacheProvider.class);
> +    Cache<String, String> cache = cacheProvider.createCache(100,
> "testcache");
> +    Cache<String, String> cache2 = cacheProvider.createCache(100,
> "testcache");
> +    Assert.assertNotNull(cache);
> +    Assert.assertEquals(cache, cache2);
> +    Assert.assertNull(cache.getElement("test"));
> +    cache.addElement("test", "value1");
> +    Assert.assertEquals(cache.getElement("test"), "value1");
> +    cache.removeElement("test");
> +    Assert.assertNull(cache.getElement("test"));
> +  }
> +}
>
> Modified:
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java?rev=689568&r1=689567&r2=689568&view=diff
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
> (original)
> +++
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpCacheTest.java
> Wed Aug 27 12:08:36 2008
> @@ -31,21 +31,28 @@
>  public class BasicHttpCacheTest extends TestCase {
>
>   private HttpCache cache;
> -  private CacheProvider cacheProvider;
>
>   @Override
>   public void setUp() throws Exception {
>     super.setUp();
> -    cacheProvider = new DefaultCacheProvider();
> -    cache = new BasicHttpCache(cacheProvider,10);
> +    cache = new BasicHttpCache(getCacheProvider(),10);
>   }
>
> +
>   @Override
>   protected void tearDown() throws Exception {
>     cache = null;
>     super.tearDown();
>   }
>
> +  /**
> +   * gets the cache provider to use for the set of tests
> +   * @return
> +   */
> +  protected CacheProvider getCacheProvider() {
> +    return new DefaultCacheProvider();
> +  }
> +
>   private static HttpRequest createRequest(String method) {
>     return new HttpRequest(Uri.parse("http://www.example.org
> ")).setMethod(method);
>   }
>
> Added:
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpEhCacheTest.java
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpEhCacheTest.java?rev=689568&view=auto
>
> ==============================================================================
> ---
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpEhCacheTest.java
> (added)
> +++
> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/shindig/gadgets/http/BasicHttpEhCacheTest.java
> Wed Aug 27 12:08:36 2008
> @@ -0,0 +1,32 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements. See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership. The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License. You may obtain a copy of the License at
> + *
> + *     http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied. See the License for the
> + * specific language governing permissions and limitations under the
> License.
> + */
> +package org.apache.shindig.gadgets.http;
> +
> +import org.apache.shindig.common.cache.CacheProvider;
> +import org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider;
> +
> +/**
> + * Performs the same set of tests for the EhCacheProvider, if there is a
> problem here, its the more
> + * likely to be the fault of the EhCacheProvider rather than the
> BasicHttpCache
> + */
> +public class BasicHttpEhCacheTest extends BasicHttpCacheTest {
> +  @Override
> +  protected CacheProvider getCacheProvider() {
> +    return new
> EhCacheCacheProvider("/org/apache/shindig/common/cache/ehcache/ehcacheConfig.xml","true");
> +  }
> +}
>
> Modified: incubator/shindig/trunk/pom.xml
> URL:
> http://svn.apache.org/viewvc/incubator/shindig/trunk/pom.xml?rev=689568&r1=689567&r2=689568&view=diff
>
> ==============================================================================
> --- incubator/shindig/trunk/pom.xml (original)
> +++ incubator/shindig/trunk/pom.xml Wed Aug 27 12:08:36 2008
> @@ -986,6 +986,11 @@
>         <artifactId>geronimo-stax-api_1.0_spec</artifactId>
>         <version>1.0.1</version>
>       </dependency>
> +      <dependency>
> +        <groupId>net.sf.ehcache</groupId>
> +        <artifactId>ehcache</artifactId>
> +        <version>1.4.1</version>
> +      </dependency>
>     </dependencies>
>   </dependencyManagement>
>  </project>
>
>
>

Re: svn commit: r689568 - in /incubator/shindig/trunk: ./ java/common/ java/common/src/main/bundle/ java/common/src/main/bundle/org/ java/common/src/main/bundle/org/apache/ java/common/src/main/bundle/org/apache/shindig/ java/common/src/main/bundle/o

Posted by Ian Boston <ie...@tfd.co.uk>.
Ok,
I can move it all into

shindig/java/container

and make it a separate jar that only binds to api's in the core.

"container"  a good name, but I cant think of anything else at the  
moment.
Any suggestions ? Apache Sling is using "launchpad" for the same sort  
of thing, but thats probably a bit 'grand' for this.

Ian

On 27 Aug 2008, at 20:39, Kevin Brown wrote:

> On Wed, Aug 27, 2008 at 12:23 PM, Ian Boston <ie...@tfd.co.uk> wrote:
>
>> Yes could do, although it didn't seem like it was big enough, 4 -  
>> 5 classes
>> + a few property files.
>>
>> However, if we say sample impls of the SPI and associated API's  
>> are outside
>> the core of shindig (common, gadgets, social-api) then we can put  
>> all the
>> sample code there, perhaps in a single artifact.
>>
>> The only downside is that the artifact is maintained on a separate
>> timeframe it binds the API's down a bit.... but sometimes thats  
>> not a bad
>> thing.
>
>
> That's actually something I was going for -- having implementations  
> that
> conform to the APIs keeps us honest when making decisions about API  
> changes.
>
> Once we do a release, interface stability is critical.


Re: svn commit: r689568 - in /incubator/shindig/trunk: ./ java/common/ java/common/src/main/bundle/ java/common/src/main/bundle/org/ java/common/src/main/bundle/org/apache/ java/common/src/main/bundle/org/apache/shindig/ java/common/src/main/bundle/o

Posted by Kevin Brown <et...@google.com>.
On Wed, Aug 27, 2008 at 12:23 PM, Ian Boston <ie...@tfd.co.uk> wrote:

> Yes could do, although it didn't seem like it was big enough, 4 - 5 classes
> + a few property files.
>
> However, if we say sample impls of the SPI and associated API's are outside
> the core of shindig (common, gadgets, social-api) then we can put all the
> sample code there, perhaps in a single artifact.
>
> The only downside is that the artifact is maintained on a separate
> timeframe it binds the API's down a bit.... but sometimes thats not a bad
> thing.


That's actually something I was going for -- having implementations that
conform to the APIs keeps us honest when making decisions about API changes.

Once we do a release, interface stability is critical.


>
>
>
> Maven build:
> main/bundle goes into target/classes and then into the jar so its on the
> classpath.
> As long as it all comes up in the same classloader, then there are normally
> no problems.
>
>
> Ian
>
>
> On 27 Aug 2008, at 20:15, Kevin Brown wrote:
>
>  a separate artifact for this? I'm not familiar
>> enough with maven to understand how the stuff in main/bundle gets
>> packaged.
>>
>
>

Re: svn commit: r689568 - in /incubator/shindig/trunk: ./ java/common/ java/common/src/main/bundle/ java/common/src/main/bundle/org/ java/common/src/main/bundle/org/apache/ java/common/src/main/bundle/org/apache/shindig/ java/common/src/main/bundle/o

Posted by Ian Boston <ie...@tfd.co.uk>.
Yes could do, although it didn't seem like it was big enough, 4 - 5  
classes + a few property files.

However, if we say sample impls of the SPI and associated API's are  
outside the core of shindig (common, gadgets, social-api) then we can  
put all the sample code there, perhaps in a single artifact.

The only downside is that the artifact is maintained on a separate  
timeframe it binds the API's down a bit.... but sometimes thats not a  
bad thing.


Maven build:
main/bundle goes into target/classes and then into the jar so its on  
the classpath.
As long as it all comes up in the same classloader, then there are  
normally no problems.


Ian

On 27 Aug 2008, at 20:15, Kevin Brown wrote:

> a separate artifact for this? I'm not familiar
> enough with maven to understand how the stuff in main/bundle gets  
> packaged.


Re: svn commit: r689568 - in /incubator/shindig/trunk: ./ java/common/ java/common/src/main/bundle/ java/common/src/main/bundle/org/ java/common/src/main/bundle/org/apache/ java/common/src/main/bundle/org/apache/shindig/ java/common/src/main/bundle/o

Posted by Ian Boston <ie...@tfd.co.uk>.
Should be fixed in revision r689606
Ian

On 27 Aug 2008, at 21:28, Ian Boston wrote:

> oops,sorry broke the build with this on one of the unit tests  
> because the bindle *isnt* being included.
> Will fix in a moment, very sorry.
>
> Ian
>
> On 27 Aug 2008, at 20:15, Kevin Brown wrote:
>
>> Would it make sense to have a separate artifact for this? I'm not  
>> familiar
>> enough with maven to understand how the stuff in main/bundle gets  
>> packaged.
>>
>> On Wed, Aug 27, 2008 at 12:08 PM, <ie...@apache.org> wrote:
>>
>>> Author: ieb
>>> Date: Wed Aug 27 12:08:36 2008
>>> New Revision: 689568
>>>
>>> URL: http://svn.apache.org/viewvc?rev=689568&view=rev
>>> Log:
>>> Adding implementation of the CacheProvider with EhCache and the  
>>> unit tests
>>> for code coverage.
>>> This is not the default cache, but is covered by unit tests in  
>>> both the
>>> Common project and the Gadgets project.
>>> The unit tests in the Gadget project only ensure that the
>>> BasicHttpCacheTest will also work for EhCache.
>>>
>>> To use this Cache implementation its necessary to add
>>> EhCacheGuiceCacheModule to the list of modules being loaded.
>>> Implementors may also want to modify both ehcacheConfig.xml and
>>> ehcache.properties to configure the cache appropriately
>>> for their environment.
>>>
>>> Added:
>>>    incubator/shindig/trunk/java/common/src/main/bundle/
>>>    incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf
>>>    incubator/shindig/trunk/java/common/src/main/bundle/ 
>>> ehcache.properties
>>>    incubator/shindig/trunk/java/common/src/main/bundle/org/
>>>    incubator/shindig/trunk/java/common/src/main/bundle/org/apache/
>>>    incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/
>>>
>>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/
>>>
>>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/cache/
>>>
>>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/cache/ehcache/
>>>
>>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/cache/ehcache/ehcacheConfig.xml
>>>
>>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/
>>>
>>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>>>
>>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>>>
>>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhConfiguredCache.java
>>>
>>>  incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>>> shindig/common/cache/ehcache/
>>>
>>>  incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>>>
>>>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>>> Modified:
>>>    incubator/shindig/trunk/java/common/pom.xml
>>>
>>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/DefaultCacheProvider.java
>>>
>>>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpCacheTest.java
>>>    incubator/shindig/trunk/pom.xml
>>>
>>> Modified: incubator/shindig/trunk/java/common/pom.xml
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> pom.xml?rev=689568&r1=689567&r2=689568&view=diff
>>>
>>> ==================================================================== 
>>> ==========
>>> --- incubator/shindig/trunk/java/common/pom.xml (original)
>>> +++ incubator/shindig/trunk/java/common/pom.xml Wed Aug 27  
>>> 12:08:36 2008
>>> @@ -89,5 +89,9 @@
>>>       <groupId>org.json</groupId>
>>>       <artifactId>json</artifactId>
>>>     </dependency>
>>> +    <dependency>
>>> +      <groupId>net.sf.ehcache</groupId>
>>> +      <artifactId>ehcache</artifactId>
>>> +    </dependency>
>>>   </dependencies>
>>>  </project>
>>>
>>> Added: incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/bundle/cache.ccf?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> --- incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf  
>>> (added)
>>> +++ incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf  
>>> Wed Aug
>>> 27 12:08:36 2008
>>> @@ -0,0 +1,14 @@
>>> +jcs.default=
>>> +jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAtt 
>>> ributes
>>> +jcs.default.cacheattributes.MaxObjects=10000
>>>
>>> +jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.m 
>>> emory.lru.LRUMemoryCache
>>> +jcs.default.cacheattributes.UseMemoryShrinker=false
>>> +jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
>>> +jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
>>> +jcs.default.elementattributes=org.apache.jcs.engine.ElementAttribut 
>>> es
>>> +jcs.default.elementattributes.IsEternal=false
>>> +jcs.default.elementattributes.MaxLifeSeconds=21600
>>> +jcs.default.elementattributes.IdleTime=1800
>>> +jcs.default.elementattributes.IsSpool=true
>>> +jcs.default.elementattributes.IsRemote=true
>>> +jcs.default.elementattributes.IsLateral=true
>>>
>>> Added:
>>> incubator/shindig/trunk/java/common/src/main/bundle/ 
>>> ehcache.properties
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/bundle/ehcache.properties?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> --- incubator/shindig/trunk/java/common/src/main/bundle/ 
>>> ehcache.properties
>>> (added)
>>> +++ incubator/shindig/trunk/java/common/src/main/bundle/ 
>>> ehcache.properties
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,2 @@
>>> +cache.config=/org/apache/shindig/cache/ehcache/ehcacheConfig.xml
>>> +cache.jmx.stats=true
>>> \ No newline at end of file
>>>
>>> Added:
>>> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/cache/ehcache/ehcacheConfig.xml
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/bundle/org/apache/shindig/common/cache/ehcache/ 
>>> ehcacheConfig.xml?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/cache/ehcache/ehcacheConfig.xml
>>> (added)
>>> +++
>>> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>>> shindig/common/cache/ehcache/ehcacheConfig.xml
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,22 @@
>>> +<?xml version="1.0" encoding="UTF-8"?>
>>> +<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> +  xsi:noNamespaceSchemaLocation="ehcache.xsd">
>>> +
>>> +
>>> +
>>> +  <!--
>>> +    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="600" timeToLiveSeconds="600"
>>> +    overflowToDisk="false" diskPersistent="false"
>>> +    memoryStoreEvictionPolicy="LRU" />
>>> +
>>> +
>>> +
>>> +
>>> +
>>> +</ehcache>
>>> \ No newline at end of file
>>>
>>> Modified:
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/DefaultCacheProvider.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/java/org/apache/shindig/common/cache/ 
>>> DefaultCacheProvider.java?rev=689568&r1=689567&r2=689568&view=diff
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/DefaultCacheProvider.java
>>> (original)
>>> +++
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/DefaultCacheProvider.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -29,7 +29,7 @@
>>>  @Singleton
>>>  public class DefaultCacheProvider implements CacheProvider {
>>>
>>> -  Map<String, Cache<?, ?>> cacheInstances = new HashMap<String,  
>>> Cache<?,
>>> ?>>();
>>> +  private Map<String, Cache<?, ?>> cacheInstances = new  
>>> HashMap<String,
>>> Cache<?, ?>>();
>>>
>>>   /*
>>>    * (non-Javadoc)
>>> @@ -47,7 +47,7 @@
>>>           c = new LruCache<K, V>(capacity);
>>>           cacheInstances.put(name, c);
>>>         }
>>> -        return c;
>>> +        return c;
>>>       }
>>>     }
>>>   }
>>>
>>> Added:
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/java/org/apache/shindig/common/cache/ehcache/ 
>>> EhCacheCacheProvider.java?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>>> (added)
>>> +++
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,123 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>> + * or more contributor license agreements.  See the NOTICE file
>>> + * distributed with this work for additional information
>>> + * regarding copyright ownership.  The ASF licenses this file
>>> + * to you under the Apache License, Version 2.0 (the
>>> + * "License"); you may not use this file except in compliance
>>> + * with the License.  You may obtain a copy of the License at
>>> + *
>>> + *   http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing,
>>> + * software distributed under the License is distributed on an
>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> + * KIND, either express or implied.  See the License for the
>>> + * specific language governing permissions and limitations
>>> + * under the License.
>>> + */
>>> +package org.apache.shindig.common.cache.ehcache;
>>> +
>>> +import net.sf.ehcache.CacheManager;
>>> +import net.sf.ehcache.management.ManagementService;
>>> +
>>> +import org.apache.shindig.common.cache.Cache;
>>> +import org.apache.shindig.common.cache.CacheProvider;
>>> +
>>> +import com.google.inject.Inject;
>>> +import com.google.inject.name.Named;
>>> +
>>> +import javax.management.MBeanServer;
>>> +
>>> +import java.lang.management.ManagementFactory;
>>> +import java.net.URL;
>>> +import java.util.HashMap;
>>> +import java.util.Map;
>>> +
>>> +/**
>>> + *
>>> + */
>>> +public class EhCacheCacheProvider implements CacheProvider {
>>> +
>>> +  private CacheManager cacheManager;
>>> +  private Map<String, Cache<?, ?>> caches = new HashMap<String,  
>>> Cache<?,
>>> ?>>();
>>> +
>>> +  public EhCacheCacheProvider() {
>>> +    create("/org/apache/shindig/common/cache/ehcache/ 
>>> ehcacheConfig.xml",
>>> "true");
>>> +  }
>>> +
>>> +  @Inject
>>> +  public EhCacheCacheProvider(@Named("cache.config")
>>> +  String configPath, @Named("cache.jmx.stats")
>>> +  String withCacheStatistics) {
>>> +    create(configPath, withCacheStatistics);
>>> +  }
>>> +
>>> +  public void create(String configPath, String  
>>> withCacheStatistics) {
>>> +    URL url = getClass().getResource(configPath);
>>> +    cacheManager = new CacheManager(url);
>>> +
>>> +    /*
>>> +     * Add in a shutdown hook
>>> +     */
>>> +    Runtime.getRuntime().addShutdownHook(new Thread() {
>>> +      /*
>>> +       * (non-Javadoc)
>>> +       *
>>> +       * @see java.lang.Thread#run()
>>> +       */
>>> +      @Override
>>> +      public void run() {
>>> +        try {
>>> +          shutdown();
>>> +        } catch (Throwable t) {
>>> +
>>> +          // I really do want to swallow this, and make the  
>>> shutdown clean
>>> for
>>> +          // others
>>> +        }
>>> +      }
>>> +    });
>>> +
>>> +    // register the cache manager with JMX
>>> +    MBeanServer mBeanServer =  
>>> ManagementFactory.getPlatformMBeanServer();
>>> +    ManagementService.registerMBeans(cacheManager, mBeanServer,  
>>> true,
>>> true, true, Boolean.valueOf(
>>> +        withCacheStatistics).booleanValue());
>>> +
>>> +  }
>>> +
>>> +  /**
>>> +   * perform a shutdown
>>> +   */
>>> +  public void shutdown() {
>>> +    cacheManager.shutdown();
>>> +  }
>>> +
>>> +  /*
>>> +   * (non-Javadoc)
>>> +   *
>>> +   * @see  
>>> org.apache.shindig.common.cache.CacheProvider#createCache(int)
>>> +   */
>>> +  public <K, V> Cache<K, V> createCache(int capacity) {
>>> +    return createCache(capacity, null);
>>> +  }
>>> +
>>> +  /*
>>> +   * (non-Javadoc)
>>> +   *
>>> +   * @see  
>>> org.apache.shindig.common.cache.CacheProvider#createCache(int,
>>> java.lang.String)
>>> +   */
>>> +  @SuppressWarnings("unchecked")
>>> +  public <K, V> Cache<K, V> createCache(int capacity, String  
>>> name) {
>>> +    if (name == null) {
>>> +      return new EhConfiguredCache<K, V>(capacity, name,  
>>> cacheManager);
>>> +    } else {
>>> +      Cache<K, V> c = (Cache<K, V>) caches.get(name);
>>> +      if (c == null) {
>>> +        c = new EhConfiguredCache<K, V>(capacity, name,  
>>> cacheManager);
>>> +        caches.put(name, c);
>>> +      }
>>> +      return c;
>>> +    }
>>> +  }
>>> +
>>> +}
>>>
>>> Added:
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/java/org/apache/shindig/common/cache/ehcache/ 
>>> EhCacheGuiceCacheModule.java?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>>> (added)
>>> +++
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,68 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>> + * or more contributor license agreements.  See the NOTICE file
>>> + * distributed with this work for additional information
>>> + * regarding copyright ownership.  The ASF licenses this file
>>> + * to you under the Apache License, Version 2.0 (the
>>> + * "License"); you may not use this file except in compliance
>>> + * with the License.  You may obtain a copy of the License at
>>> + *
>>> + *   http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing,
>>> + * software distributed under the License is distributed on an
>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> + * KIND, either express or implied.  See the License for the
>>> + * specific language governing permissions and limitations
>>> + * under the License.
>>> + */
>>> +package org.apache.shindig.common.cache.ehcache;
>>> +
>>> +import java.io.IOException;
>>> +import java.io.InputStream;
>>> +import java.util.Arrays;
>>> +import java.util.Properties;
>>> +
>>> +import org.apache.shindig.common.cache.CacheProvider;
>>> +import org.apache.shindig.common.util.ResourceLoader;
>>> +
>>> +import com.google.inject.AbstractModule;
>>> +import com.google.inject.CreationException;
>>> +import com.google.inject.Scopes;
>>> +import com.google.inject.name.Names;
>>> +import com.google.inject.spi.Message;
>>> +
>>> +/**
>>> + * Creates a module to supply a EhCache Provider
>>> + */
>>> +public class EhCacheGuiceCacheModule extends AbstractModule {
>>> +  private final Properties properties;
>>> +  private final static String DEFAULT_PROPERTIES =  
>>> "ehcache.properties";
>>> +
>>> +  /** {@inheritDoc} */
>>> +  @Override
>>> +  protected void configure() {
>>> +    Names.bindProperties(this.binder(), properties);
>>> +
>>>  bind(CacheProvider.class).to(EhCacheCacheProvider.class).in 
>>> (Scopes.SINGLETON);
>>> +  }
>>> +
>>> +  public EhCacheGuiceCacheModule(Properties properties) {
>>> +    this.properties = properties;
>>> +  }
>>> +
>>> +  /**
>>> +   * Creates module with standard properties.
>>> +   */
>>> +  public EhCacheGuiceCacheModule() {
>>> +    Properties properties = null;
>>> +    try {
>>> +      InputStream is = ResourceLoader.openResource 
>>> (DEFAULT_PROPERTIES);
>>> +      properties = new Properties();
>>> +      properties.load(is);
>>> +    } catch (IOException e) {
>>> +      throw new CreationException(Arrays.asList(new Message 
>>> ("Unable to
>>> load properties: "
>>> +          + DEFAULT_PROPERTIES)));
>>> +    }
>>> +    this.properties = properties;
>>> +  }
>>> +}
>>>
>>> Added:
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhConfiguredCache.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/main/java/org/apache/shindig/common/cache/ehcache/ 
>>> EhConfiguredCache.java?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhConfiguredCache.java
>>> (added)
>>> +++
>>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhConfiguredCache.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,84 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>> + * or more contributor license agreements.  See the NOTICE file
>>> + * distributed with this work for additional information
>>> + * regarding copyright ownership.  The ASF licenses this file
>>> + * to you under the Apache License, Version 2.0 (the
>>> + * "License"); you may not use this file except in compliance
>>> + * with the License.  You may obtain a copy of the License at
>>> + *
>>> + *   http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing,
>>> + * software distributed under the License is distributed on an
>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> + * KIND, either express or implied.  See the License for the
>>> + * specific language governing permissions and limitations
>>> + * under the License.
>>> + */
>>> +package org.apache.shindig.common.cache.ehcache;
>>> +
>>> +import net.sf.ehcache.CacheManager;
>>> +import net.sf.ehcache.Element;
>>> +
>>> +import org.apache.shindig.common.cache.Cache;
>>> +
>>> +/**
>>> + *
>>> + */
>>> +public class EhConfiguredCache<K, V> implements Cache<K, V> {
>>> +
>>> +  private net.sf.ehcache.Cache cache;
>>> +
>>> +  public EhConfiguredCache(int capacity, String cacheName,  
>>> CacheManager
>>> cacheManager) {
>>> +    if (cacheName == null) {
>>> +      cacheName = "default";
>>> +    }
>>> +    synchronized (cacheManager) {
>>> +      cache = cacheManager.getCache(cacheName);
>>> +      if (cache == null) {
>>> +        cacheManager.addCache(cacheName);
>>> +        cache = cacheManager.getCache(cacheName);
>>> +        if (cache == null) {
>>> +          throw new RuntimeException("Failed to create Cache  
>>> with name " +
>>> cacheName);
>>> +        }
>>> +      }
>>> +    }
>>> +  }
>>> +
>>> +  /*
>>> +   * (non-Javadoc)
>>> +   *
>>> +   * @see
>>> org.apache.shindig.common.cache.Cache#addElement(java.lang.Object,
>>> java.lang.Object)
>>> +   */
>>> +  public void addElement(K key, V value) {
>>> +    cache.put(new Element(key, value));
>>> +  }
>>> +
>>> +  /*
>>> +   * (non-Javadoc)
>>> +   *
>>> +   * @see
>>> org.apache.shindig.common.cache.Cache#getElement(java.lang.Object)
>>> +   */
>>> +  @SuppressWarnings("unchecked")
>>> +  public V getElement(K key) {
>>> +    Element cacheElement = cache.get(key);
>>> +    if (cacheElement != null) {
>>> +      return (V) cacheElement.getObjectValue();
>>> +    }
>>> +    return null;
>>> +  }
>>> +
>>> +  /*
>>> +   * (non-Javadoc)
>>> +   *
>>> +   * @see
>>> org.apache.shindig.common.cache.Cache#removeElement 
>>> (java.lang.Object)
>>> +   */
>>> +  @SuppressWarnings("unchecked")
>>> +  public V removeElement(K key) {
>>> +    Object value = getElement(key);
>>> +    cache.remove(key);
>>> +    return (V) value;
>>> +  }
>>> +
>>> +}
>>>
>>> Added:
>>> incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>>> src/test/java/org/apache/shindig/common/cache/ehcache/ 
>>> EhCacheCacheProviderTest.java?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>>> (added)
>>> +++
>>> incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,106 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>> + * or more contributor license agreements.  See the NOTICE file
>>> + * distributed with this work for additional information
>>> + * regarding copyright ownership.  The ASF licenses this file
>>> + * to you under the Apache License, Version 2.0 (the
>>> + * "License"); you may not use this file except in compliance
>>> + * with the License.  You may obtain a copy of the License at
>>> + *
>>> + *   http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing,
>>> + * software distributed under the License is distributed on an
>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> + * KIND, either express or implied.  See the License for the
>>> + * specific language governing permissions and limitations
>>> + * under the License.
>>> + */
>>> +package org.apache.shindig.common.cache.ehcache;
>>> +
>>> +import org.apache.shindig.common.cache.Cache;
>>> +import org.apache.shindig.common.cache.CacheProvider;
>>> +import  
>>> org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider;
>>> +
>>> +import com.google.inject.Guice;
>>> +import com.google.inject.Injector;
>>> +
>>> +import org.junit.Test;
>>> +import org.junit.Assert;
>>> +
>>> +/**
>>> + *
>>> + */
>>> +public class EhCacheCacheProviderTest {
>>> +
>>> +  @Test
>>> +  public void getAnonCache() {
>>> +    CacheProvider defaultProvider = new EhCacheCacheProvider(
>>> +        "/org/apache/shindig/common/cache/ehcache/ 
>>> ehcacheConfig.xml",
>>> "true");
>>> +    Cache<String, String> cache = defaultProvider.createCache(100);
>>> +    Assert.assertNotNull(cache);
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +    cache.addElement("test", "value1");
>>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>>> +    cache.removeElement("test");
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +
>>> +  }
>>> +
>>> +  @Test
>>> +  public void getNamedCache() {
>>> +    CacheProvider defaultProvider = new EhCacheCacheProvider(
>>> +        "/org/apache/shindig/common/cache/ehcache/ 
>>> ehcacheConfig.xml",
>>> "true");
>>> +    Cache<String, String> cache = defaultProvider.createCache(100,
>>> "testcache");
>>> +    Cache<String, String> cache2 = defaultProvider.createCache(100,
>>> "testcache");
>>> +    Assert.assertNotNull(cache);
>>> +    Assert.assertEquals(cache, cache2);
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +    cache.addElement("test", "value1");
>>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>>> +    cache.removeElement("test");
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +  }
>>> +
>>> +  @Test
>>> +  public void getAnonCacheNoConfig() {
>>> +    CacheProvider defaultProvider = new EhCacheCacheProvider();
>>> +    Cache<String, String> cache = defaultProvider.createCache(100);
>>> +    Assert.assertNotNull(cache);
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +    cache.addElement("test", "value1");
>>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>>> +    cache.removeElement("test");
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +
>>> +  }
>>> +
>>> +  @Test
>>> +  public void getNamedCacheNoConfig() {
>>> +    CacheProvider defaultProvider = new EhCacheCacheProvider();
>>> +    Cache<String, String> cache = defaultProvider.createCache(100,
>>> "testcache");
>>> +    Cache<String, String> cache2 = defaultProvider.createCache(100,
>>> "testcache");
>>> +    Assert.assertNotNull(cache);
>>> +    Assert.assertEquals(cache, cache2);
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +    cache.addElement("test", "value1");
>>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>>> +    cache.removeElement("test");
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +  }
>>> +
>>> +  @Test
>>> +  public void testGuiceModule() {
>>> +    Injector i = Guice.createInjector(new EhCacheGuiceCacheModule 
>>> ());
>>> +    CacheProvider cacheProvider = i.getInstance 
>>> (CacheProvider.class);
>>> +    Cache<String, String> cache = cacheProvider.createCache(100,
>>> "testcache");
>>> +    Cache<String, String> cache2 = cacheProvider.createCache(100,
>>> "testcache");
>>> +    Assert.assertNotNull(cache);
>>> +    Assert.assertEquals(cache, cache2);
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +    cache.addElement("test", "value1");
>>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>>> +    cache.removeElement("test");
>>> +    Assert.assertNull(cache.getElement("test"));
>>> +  }
>>> +}
>>>
>>> Modified:
>>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpCacheTest.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/ 
>>> src/test/java/org/apache/shindig/gadgets/http/ 
>>> BasicHttpCacheTest.java?rev=689568&r1=689567&r2=689568&view=diff
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpCacheTest.java
>>> (original)
>>> +++
>>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpCacheTest.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -31,21 +31,28 @@
>>>  public class BasicHttpCacheTest extends TestCase {
>>>
>>>   private HttpCache cache;
>>> -  private CacheProvider cacheProvider;
>>>
>>>   @Override
>>>   public void setUp() throws Exception {
>>>     super.setUp();
>>> -    cacheProvider = new DefaultCacheProvider();
>>> -    cache = new BasicHttpCache(cacheProvider,10);
>>> +    cache = new BasicHttpCache(getCacheProvider(),10);
>>>   }
>>>
>>> +
>>>   @Override
>>>   protected void tearDown() throws Exception {
>>>     cache = null;
>>>     super.tearDown();
>>>   }
>>>
>>> +  /**
>>> +   * gets the cache provider to use for the set of tests
>>> +   * @return
>>> +   */
>>> +  protected CacheProvider getCacheProvider() {
>>> +    return new DefaultCacheProvider();
>>> +  }
>>> +
>>>   private static HttpRequest createRequest(String method) {
>>>     return new HttpRequest(Uri.parse("http://www.example.org
>>> ")).setMethod(method);
>>>   }
>>>
>>> Added:
>>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/ 
>>> src/test/java/org/apache/shindig/gadgets/http/ 
>>> BasicHttpEhCacheTest.java?rev=689568&view=auto
>>>
>>> ==================================================================== 
>>> ==========
>>> ---
>>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>>> (added)
>>> +++
>>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>>> Wed Aug 27 12:08:36 2008
>>> @@ -0,0 +1,32 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>> + * or more contributor license agreements. See the NOTICE file
>>> + * distributed with this work for additional information
>>> + * regarding copyright ownership. The ASF licenses this file
>>> + * to you under the Apache License, Version 2.0 (the
>>> + * "License"); you may not use this file except in compliance
>>> + * with the License. You may obtain a copy of the License at
>>> + *
>>> + *     http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing,
>>> + * software distributed under the License is distributed on an
>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> + * KIND, either express or implied. See the License for the
>>> + * specific language governing permissions and limitations under  
>>> the
>>> License.
>>> + */
>>> +package org.apache.shindig.gadgets.http;
>>> +
>>> +import org.apache.shindig.common.cache.CacheProvider;
>>> +import  
>>> org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider;
>>> +
>>> +/**
>>> + * Performs the same set of tests for the EhCacheProvider, if  
>>> there is a
>>> problem here, its the more
>>> + * likely to be the fault of the EhCacheProvider rather than the
>>> BasicHttpCache
>>> + */
>>> +public class BasicHttpEhCacheTest extends BasicHttpCacheTest {
>>> +  @Override
>>> +  protected CacheProvider getCacheProvider() {
>>> +    return new
>>> EhCacheCacheProvider("/org/apache/shindig/common/cache/ehcache/ 
>>> ehcacheConfig.xml","true");
>>> +  }
>>> +}
>>>
>>> Modified: incubator/shindig/trunk/pom.xml
>>> URL:
>>> http://svn.apache.org/viewvc/incubator/shindig/trunk/pom.xml? 
>>> rev=689568&r1=689567&r2=689568&view=diff
>>>
>>> ==================================================================== 
>>> ==========
>>> --- incubator/shindig/trunk/pom.xml (original)
>>> +++ incubator/shindig/trunk/pom.xml Wed Aug 27 12:08:36 2008
>>> @@ -986,6 +986,11 @@
>>>         <artifactId>geronimo-stax-api_1.0_spec</artifactId>
>>>         <version>1.0.1</version>
>>>       </dependency>
>>> +      <dependency>
>>> +        <groupId>net.sf.ehcache</groupId>
>>> +        <artifactId>ehcache</artifactId>
>>> +        <version>1.4.1</version>
>>> +      </dependency>
>>>     </dependencies>
>>>   </dependencyManagement>
>>>  </project>
>>>
>>>
>>>
>


Re: svn commit: r689568 - in /incubator/shindig/trunk: ./ java/common/ java/common/src/main/bundle/ java/common/src/main/bundle/org/ java/common/src/main/bundle/org/apache/ java/common/src/main/bundle/org/apache/shindig/ java/common/src/main/bundle/o

Posted by Ian Boston <ie...@tfd.co.uk>.
oops,sorry broke the build with this on one of the unit tests because  
the bindle *isnt* being included.
Will fix in a moment, very sorry.

Ian

On 27 Aug 2008, at 20:15, Kevin Brown wrote:

> Would it make sense to have a separate artifact for this? I'm not  
> familiar
> enough with maven to understand how the stuff in main/bundle gets  
> packaged.
>
> On Wed, Aug 27, 2008 at 12:08 PM, <ie...@apache.org> wrote:
>
>> Author: ieb
>> Date: Wed Aug 27 12:08:36 2008
>> New Revision: 689568
>>
>> URL: http://svn.apache.org/viewvc?rev=689568&view=rev
>> Log:
>> Adding implementation of the CacheProvider with EhCache and the  
>> unit tests
>> for code coverage.
>> This is not the default cache, but is covered by unit tests in  
>> both the
>> Common project and the Gadgets project.
>> The unit tests in the Gadget project only ensure that the
>> BasicHttpCacheTest will also work for EhCache.
>>
>> To use this Cache implementation its necessary to add
>> EhCacheGuiceCacheModule to the list of modules being loaded.
>> Implementors may also want to modify both ehcacheConfig.xml and
>> ehcache.properties to configure the cache appropriately
>> for their environment.
>>
>> Added:
>>    incubator/shindig/trunk/java/common/src/main/bundle/
>>    incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf
>>    incubator/shindig/trunk/java/common/src/main/bundle/ 
>> ehcache.properties
>>    incubator/shindig/trunk/java/common/src/main/bundle/org/
>>    incubator/shindig/trunk/java/common/src/main/bundle/org/apache/
>>    incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/
>>
>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/
>>
>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/cache/
>>
>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/cache/ehcache/
>>
>>  incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/cache/ehcache/ehcacheConfig.xml
>>
>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/
>>
>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>>
>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>>
>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhConfiguredCache.java
>>
>>  incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>> shindig/common/cache/ehcache/
>>
>>  incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>>
>>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>> Modified:
>>    incubator/shindig/trunk/java/common/pom.xml
>>
>>  incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/DefaultCacheProvider.java
>>
>>  incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpCacheTest.java
>>    incubator/shindig/trunk/pom.xml
>>
>> Modified: incubator/shindig/trunk/java/common/pom.xml
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> pom.xml?rev=689568&r1=689567&r2=689568&view=diff
>>
>> ===================================================================== 
>> =========
>> --- incubator/shindig/trunk/java/common/pom.xml (original)
>> +++ incubator/shindig/trunk/java/common/pom.xml Wed Aug 27  
>> 12:08:36 2008
>> @@ -89,5 +89,9 @@
>>       <groupId>org.json</groupId>
>>       <artifactId>json</artifactId>
>>     </dependency>
>> +    <dependency>
>> +      <groupId>net.sf.ehcache</groupId>
>> +      <artifactId>ehcache</artifactId>
>> +    </dependency>
>>   </dependencies>
>>  </project>
>>
>> Added: incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/bundle/cache.ccf?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> --- incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf  
>> (added)
>> +++ incubator/shindig/trunk/java/common/src/main/bundle/cache.ccf  
>> Wed Aug
>> 27 12:08:36 2008
>> @@ -0,0 +1,14 @@
>> +jcs.default=
>> +jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttr 
>> ibutes
>> +jcs.default.cacheattributes.MaxObjects=10000
>>
>> +jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.me 
>> mory.lru.LRUMemoryCache
>> +jcs.default.cacheattributes.UseMemoryShrinker=false
>> +jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
>> +jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
>> +jcs.default.elementattributes=org.apache.jcs.engine.ElementAttribute 
>> s
>> +jcs.default.elementattributes.IsEternal=false
>> +jcs.default.elementattributes.MaxLifeSeconds=21600
>> +jcs.default.elementattributes.IdleTime=1800
>> +jcs.default.elementattributes.IsSpool=true
>> +jcs.default.elementattributes.IsRemote=true
>> +jcs.default.elementattributes.IsLateral=true
>>
>> Added:
>> incubator/shindig/trunk/java/common/src/main/bundle/ 
>> ehcache.properties
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/bundle/ehcache.properties?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> --- incubator/shindig/trunk/java/common/src/main/bundle/ 
>> ehcache.properties
>> (added)
>> +++ incubator/shindig/trunk/java/common/src/main/bundle/ 
>> ehcache.properties
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,2 @@
>> +cache.config=/org/apache/shindig/cache/ehcache/ehcacheConfig.xml
>> +cache.jmx.stats=true
>> \ No newline at end of file
>>
>> Added:
>> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/cache/ehcache/ehcacheConfig.xml
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/bundle/org/apache/shindig/common/cache/ehcache/ 
>> ehcacheConfig.xml?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/cache/ehcache/ehcacheConfig.xml
>> (added)
>> +++
>> incubator/shindig/trunk/java/common/src/main/bundle/org/apache/ 
>> shindig/common/cache/ehcache/ehcacheConfig.xml
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,22 @@
>> +<?xml version="1.0" encoding="UTF-8"?>
>> +<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> +  xsi:noNamespaceSchemaLocation="ehcache.xsd">
>> +
>> +
>> +
>> +  <!--
>> +    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="600" timeToLiveSeconds="600"
>> +    overflowToDisk="false" diskPersistent="false"
>> +    memoryStoreEvictionPolicy="LRU" />
>> +
>> +
>> +
>> +
>> +
>> +</ehcache>
>> \ No newline at end of file
>>
>> Modified:
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/DefaultCacheProvider.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/java/org/apache/shindig/common/cache/ 
>> DefaultCacheProvider.java?rev=689568&r1=689567&r2=689568&view=diff
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/DefaultCacheProvider.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/DefaultCacheProvider.java
>> Wed Aug 27 12:08:36 2008
>> @@ -29,7 +29,7 @@
>>  @Singleton
>>  public class DefaultCacheProvider implements CacheProvider {
>>
>> -  Map<String, Cache<?, ?>> cacheInstances = new HashMap<String,  
>> Cache<?,
>> ?>>();
>> +  private Map<String, Cache<?, ?>> cacheInstances = new  
>> HashMap<String,
>> Cache<?, ?>>();
>>
>>   /*
>>    * (non-Javadoc)
>> @@ -47,7 +47,7 @@
>>           c = new LruCache<K, V>(capacity);
>>           cacheInstances.put(name, c);
>>         }
>> -        return c;
>> +        return c;
>>       }
>>     }
>>   }
>>
>> Added:
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/java/org/apache/shindig/common/cache/ehcache/ 
>> EhCacheCacheProvider.java?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>> (added)
>> +++
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProvider.java
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,123 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License.  You may obtain a copy of the License at
>> + *
>> + *   http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> + */
>> +package org.apache.shindig.common.cache.ehcache;
>> +
>> +import net.sf.ehcache.CacheManager;
>> +import net.sf.ehcache.management.ManagementService;
>> +
>> +import org.apache.shindig.common.cache.Cache;
>> +import org.apache.shindig.common.cache.CacheProvider;
>> +
>> +import com.google.inject.Inject;
>> +import com.google.inject.name.Named;
>> +
>> +import javax.management.MBeanServer;
>> +
>> +import java.lang.management.ManagementFactory;
>> +import java.net.URL;
>> +import java.util.HashMap;
>> +import java.util.Map;
>> +
>> +/**
>> + *
>> + */
>> +public class EhCacheCacheProvider implements CacheProvider {
>> +
>> +  private CacheManager cacheManager;
>> +  private Map<String, Cache<?, ?>> caches = new HashMap<String,  
>> Cache<?,
>> ?>>();
>> +
>> +  public EhCacheCacheProvider() {
>> +    create("/org/apache/shindig/common/cache/ehcache/ 
>> ehcacheConfig.xml",
>> "true");
>> +  }
>> +
>> +  @Inject
>> +  public EhCacheCacheProvider(@Named("cache.config")
>> +  String configPath, @Named("cache.jmx.stats")
>> +  String withCacheStatistics) {
>> +    create(configPath, withCacheStatistics);
>> +  }
>> +
>> +  public void create(String configPath, String  
>> withCacheStatistics) {
>> +    URL url = getClass().getResource(configPath);
>> +    cacheManager = new CacheManager(url);
>> +
>> +    /*
>> +     * Add in a shutdown hook
>> +     */
>> +    Runtime.getRuntime().addShutdownHook(new Thread() {
>> +      /*
>> +       * (non-Javadoc)
>> +       *
>> +       * @see java.lang.Thread#run()
>> +       */
>> +      @Override
>> +      public void run() {
>> +        try {
>> +          shutdown();
>> +        } catch (Throwable t) {
>> +
>> +          // I really do want to swallow this, and make the  
>> shutdown clean
>> for
>> +          // others
>> +        }
>> +      }
>> +    });
>> +
>> +    // register the cache manager with JMX
>> +    MBeanServer mBeanServer =  
>> ManagementFactory.getPlatformMBeanServer();
>> +    ManagementService.registerMBeans(cacheManager, mBeanServer,  
>> true,
>> true, true, Boolean.valueOf(
>> +        withCacheStatistics).booleanValue());
>> +
>> +  }
>> +
>> +  /**
>> +   * perform a shutdown
>> +   */
>> +  public void shutdown() {
>> +    cacheManager.shutdown();
>> +  }
>> +
>> +  /*
>> +   * (non-Javadoc)
>> +   *
>> +   * @see  
>> org.apache.shindig.common.cache.CacheProvider#createCache(int)
>> +   */
>> +  public <K, V> Cache<K, V> createCache(int capacity) {
>> +    return createCache(capacity, null);
>> +  }
>> +
>> +  /*
>> +   * (non-Javadoc)
>> +   *
>> +   * @see  
>> org.apache.shindig.common.cache.CacheProvider#createCache(int,
>> java.lang.String)
>> +   */
>> +  @SuppressWarnings("unchecked")
>> +  public <K, V> Cache<K, V> createCache(int capacity, String name) {
>> +    if (name == null) {
>> +      return new EhConfiguredCache<K, V>(capacity, name,  
>> cacheManager);
>> +    } else {
>> +      Cache<K, V> c = (Cache<K, V>) caches.get(name);
>> +      if (c == null) {
>> +        c = new EhConfiguredCache<K, V>(capacity, name,  
>> cacheManager);
>> +        caches.put(name, c);
>> +      }
>> +      return c;
>> +    }
>> +  }
>> +
>> +}
>>
>> Added:
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/java/org/apache/shindig/common/cache/ehcache/ 
>> EhCacheGuiceCacheModule.java?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>> (added)
>> +++
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheGuiceCacheModule.java
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,68 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License.  You may obtain a copy of the License at
>> + *
>> + *   http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> + */
>> +package org.apache.shindig.common.cache.ehcache;
>> +
>> +import java.io.IOException;
>> +import java.io.InputStream;
>> +import java.util.Arrays;
>> +import java.util.Properties;
>> +
>> +import org.apache.shindig.common.cache.CacheProvider;
>> +import org.apache.shindig.common.util.ResourceLoader;
>> +
>> +import com.google.inject.AbstractModule;
>> +import com.google.inject.CreationException;
>> +import com.google.inject.Scopes;
>> +import com.google.inject.name.Names;
>> +import com.google.inject.spi.Message;
>> +
>> +/**
>> + * Creates a module to supply a EhCache Provider
>> + */
>> +public class EhCacheGuiceCacheModule extends AbstractModule {
>> +  private final Properties properties;
>> +  private final static String DEFAULT_PROPERTIES =  
>> "ehcache.properties";
>> +
>> +  /** {@inheritDoc} */
>> +  @Override
>> +  protected void configure() {
>> +    Names.bindProperties(this.binder(), properties);
>> +
>>  bind(CacheProvider.class).to(EhCacheCacheProvider.class).in 
>> (Scopes.SINGLETON);
>> +  }
>> +
>> +  public EhCacheGuiceCacheModule(Properties properties) {
>> +    this.properties = properties;
>> +  }
>> +
>> +  /**
>> +   * Creates module with standard properties.
>> +   */
>> +  public EhCacheGuiceCacheModule() {
>> +    Properties properties = null;
>> +    try {
>> +      InputStream is = ResourceLoader.openResource 
>> (DEFAULT_PROPERTIES);
>> +      properties = new Properties();
>> +      properties.load(is);
>> +    } catch (IOException e) {
>> +      throw new CreationException(Arrays.asList(new Message 
>> ("Unable to
>> load properties: "
>> +          + DEFAULT_PROPERTIES)));
>> +    }
>> +    this.properties = properties;
>> +  }
>> +}
>>
>> Added:
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhConfiguredCache.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/main/java/org/apache/shindig/common/cache/ehcache/ 
>> EhConfiguredCache.java?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhConfiguredCache.java
>> (added)
>> +++
>> incubator/shindig/trunk/java/common/src/main/java/org/apache/ 
>> shindig/common/cache/ehcache/EhConfiguredCache.java
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,84 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License.  You may obtain a copy of the License at
>> + *
>> + *   http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> + */
>> +package org.apache.shindig.common.cache.ehcache;
>> +
>> +import net.sf.ehcache.CacheManager;
>> +import net.sf.ehcache.Element;
>> +
>> +import org.apache.shindig.common.cache.Cache;
>> +
>> +/**
>> + *
>> + */
>> +public class EhConfiguredCache<K, V> implements Cache<K, V> {
>> +
>> +  private net.sf.ehcache.Cache cache;
>> +
>> +  public EhConfiguredCache(int capacity, String cacheName,  
>> CacheManager
>> cacheManager) {
>> +    if (cacheName == null) {
>> +      cacheName = "default";
>> +    }
>> +    synchronized (cacheManager) {
>> +      cache = cacheManager.getCache(cacheName);
>> +      if (cache == null) {
>> +        cacheManager.addCache(cacheName);
>> +        cache = cacheManager.getCache(cacheName);
>> +        if (cache == null) {
>> +          throw new RuntimeException("Failed to create Cache with  
>> name " +
>> cacheName);
>> +        }
>> +      }
>> +    }
>> +  }
>> +
>> +  /*
>> +   * (non-Javadoc)
>> +   *
>> +   * @see
>> org.apache.shindig.common.cache.Cache#addElement(java.lang.Object,
>> java.lang.Object)
>> +   */
>> +  public void addElement(K key, V value) {
>> +    cache.put(new Element(key, value));
>> +  }
>> +
>> +  /*
>> +   * (non-Javadoc)
>> +   *
>> +   * @see
>> org.apache.shindig.common.cache.Cache#getElement(java.lang.Object)
>> +   */
>> +  @SuppressWarnings("unchecked")
>> +  public V getElement(K key) {
>> +    Element cacheElement = cache.get(key);
>> +    if (cacheElement != null) {
>> +      return (V) cacheElement.getObjectValue();
>> +    }
>> +    return null;
>> +  }
>> +
>> +  /*
>> +   * (non-Javadoc)
>> +   *
>> +   * @see
>> org.apache.shindig.common.cache.Cache#removeElement(java.lang.Object)
>> +   */
>> +  @SuppressWarnings("unchecked")
>> +  public V removeElement(K key) {
>> +    Object value = getElement(key);
>> +    cache.remove(key);
>> +    return (V) value;
>> +  }
>> +
>> +}
>>
>> Added:
>> incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/common/ 
>> src/test/java/org/apache/shindig/common/cache/ehcache/ 
>> EhCacheCacheProviderTest.java?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>> (added)
>> +++
>> incubator/shindig/trunk/java/common/src/test/java/org/apache/ 
>> shindig/common/cache/ehcache/EhCacheCacheProviderTest.java
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,106 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License.  You may obtain a copy of the License at
>> + *
>> + *   http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> + */
>> +package org.apache.shindig.common.cache.ehcache;
>> +
>> +import org.apache.shindig.common.cache.Cache;
>> +import org.apache.shindig.common.cache.CacheProvider;
>> +import org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider;
>> +
>> +import com.google.inject.Guice;
>> +import com.google.inject.Injector;
>> +
>> +import org.junit.Test;
>> +import org.junit.Assert;
>> +
>> +/**
>> + *
>> + */
>> +public class EhCacheCacheProviderTest {
>> +
>> +  @Test
>> +  public void getAnonCache() {
>> +    CacheProvider defaultProvider = new EhCacheCacheProvider(
>> +        "/org/apache/shindig/common/cache/ehcache/ 
>> ehcacheConfig.xml",
>> "true");
>> +    Cache<String, String> cache = defaultProvider.createCache(100);
>> +    Assert.assertNotNull(cache);
>> +    Assert.assertNull(cache.getElement("test"));
>> +    cache.addElement("test", "value1");
>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>> +    cache.removeElement("test");
>> +    Assert.assertNull(cache.getElement("test"));
>> +
>> +  }
>> +
>> +  @Test
>> +  public void getNamedCache() {
>> +    CacheProvider defaultProvider = new EhCacheCacheProvider(
>> +        "/org/apache/shindig/common/cache/ehcache/ 
>> ehcacheConfig.xml",
>> "true");
>> +    Cache<String, String> cache = defaultProvider.createCache(100,
>> "testcache");
>> +    Cache<String, String> cache2 = defaultProvider.createCache(100,
>> "testcache");
>> +    Assert.assertNotNull(cache);
>> +    Assert.assertEquals(cache, cache2);
>> +    Assert.assertNull(cache.getElement("test"));
>> +    cache.addElement("test", "value1");
>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>> +    cache.removeElement("test");
>> +    Assert.assertNull(cache.getElement("test"));
>> +  }
>> +
>> +  @Test
>> +  public void getAnonCacheNoConfig() {
>> +    CacheProvider defaultProvider = new EhCacheCacheProvider();
>> +    Cache<String, String> cache = defaultProvider.createCache(100);
>> +    Assert.assertNotNull(cache);
>> +    Assert.assertNull(cache.getElement("test"));
>> +    cache.addElement("test", "value1");
>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>> +    cache.removeElement("test");
>> +    Assert.assertNull(cache.getElement("test"));
>> +
>> +  }
>> +
>> +  @Test
>> +  public void getNamedCacheNoConfig() {
>> +    CacheProvider defaultProvider = new EhCacheCacheProvider();
>> +    Cache<String, String> cache = defaultProvider.createCache(100,
>> "testcache");
>> +    Cache<String, String> cache2 = defaultProvider.createCache(100,
>> "testcache");
>> +    Assert.assertNotNull(cache);
>> +    Assert.assertEquals(cache, cache2);
>> +    Assert.assertNull(cache.getElement("test"));
>> +    cache.addElement("test", "value1");
>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>> +    cache.removeElement("test");
>> +    Assert.assertNull(cache.getElement("test"));
>> +  }
>> +
>> +  @Test
>> +  public void testGuiceModule() {
>> +    Injector i = Guice.createInjector(new EhCacheGuiceCacheModule 
>> ());
>> +    CacheProvider cacheProvider = i.getInstance 
>> (CacheProvider.class);
>> +    Cache<String, String> cache = cacheProvider.createCache(100,
>> "testcache");
>> +    Cache<String, String> cache2 = cacheProvider.createCache(100,
>> "testcache");
>> +    Assert.assertNotNull(cache);
>> +    Assert.assertEquals(cache, cache2);
>> +    Assert.assertNull(cache.getElement("test"));
>> +    cache.addElement("test", "value1");
>> +    Assert.assertEquals(cache.getElement("test"), "value1");
>> +    cache.removeElement("test");
>> +    Assert.assertNull(cache.getElement("test"));
>> +  }
>> +}
>>
>> Modified:
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpCacheTest.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/ 
>> src/test/java/org/apache/shindig/gadgets/http/ 
>> BasicHttpCacheTest.java?rev=689568&r1=689567&r2=689568&view=diff
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpCacheTest.java
>> (original)
>> +++
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpCacheTest.java
>> Wed Aug 27 12:08:36 2008
>> @@ -31,21 +31,28 @@
>>  public class BasicHttpCacheTest extends TestCase {
>>
>>   private HttpCache cache;
>> -  private CacheProvider cacheProvider;
>>
>>   @Override
>>   public void setUp() throws Exception {
>>     super.setUp();
>> -    cacheProvider = new DefaultCacheProvider();
>> -    cache = new BasicHttpCache(cacheProvider,10);
>> +    cache = new BasicHttpCache(getCacheProvider(),10);
>>   }
>>
>> +
>>   @Override
>>   protected void tearDown() throws Exception {
>>     cache = null;
>>     super.tearDown();
>>   }
>>
>> +  /**
>> +   * gets the cache provider to use for the set of tests
>> +   * @return
>> +   */
>> +  protected CacheProvider getCacheProvider() {
>> +    return new DefaultCacheProvider();
>> +  }
>> +
>>   private static HttpRequest createRequest(String method) {
>>     return new HttpRequest(Uri.parse("http://www.example.org
>> ")).setMethod(method);
>>   }
>>
>> Added:
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/java/gadgets/ 
>> src/test/java/org/apache/shindig/gadgets/http/ 
>> BasicHttpEhCacheTest.java?rev=689568&view=auto
>>
>> ===================================================================== 
>> =========
>> ---
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>> (added)
>> +++
>> incubator/shindig/trunk/java/gadgets/src/test/java/org/apache/ 
>> shindig/gadgets/http/BasicHttpEhCacheTest.java
>> Wed Aug 27 12:08:36 2008
>> @@ -0,0 +1,32 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements. See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership. The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License. You may obtain a copy of the License at
>> + *
>> + *     http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied. See the License for the
>> + * specific language governing permissions and limitations under the
>> License.
>> + */
>> +package org.apache.shindig.gadgets.http;
>> +
>> +import org.apache.shindig.common.cache.CacheProvider;
>> +import org.apache.shindig.common.cache.ehcache.EhCacheCacheProvider;
>> +
>> +/**
>> + * Performs the same set of tests for the EhCacheProvider, if  
>> there is a
>> problem here, its the more
>> + * likely to be the fault of the EhCacheProvider rather than the
>> BasicHttpCache
>> + */
>> +public class BasicHttpEhCacheTest extends BasicHttpCacheTest {
>> +  @Override
>> +  protected CacheProvider getCacheProvider() {
>> +    return new
>> EhCacheCacheProvider("/org/apache/shindig/common/cache/ehcache/ 
>> ehcacheConfig.xml","true");
>> +  }
>> +}
>>
>> Modified: incubator/shindig/trunk/pom.xml
>> URL:
>> http://svn.apache.org/viewvc/incubator/shindig/trunk/pom.xml? 
>> rev=689568&r1=689567&r2=689568&view=diff
>>
>> ===================================================================== 
>> =========
>> --- incubator/shindig/trunk/pom.xml (original)
>> +++ incubator/shindig/trunk/pom.xml Wed Aug 27 12:08:36 2008
>> @@ -986,6 +986,11 @@
>>         <artifactId>geronimo-stax-api_1.0_spec</artifactId>
>>         <version>1.0.1</version>
>>       </dependency>
>> +      <dependency>
>> +        <groupId>net.sf.ehcache</groupId>
>> +        <artifactId>ehcache</artifactId>
>> +        <version>1.4.1</version>
>> +      </dependency>
>>     </dependencies>
>>   </dependencyManagement>
>>  </project>
>>
>>
>>