Permalink
Browse files

[SM-2109] Added EhCache store. Added StoreListener support to EhCache…

… store. Added unit test for EhCache store.

git-svn-id: https://svn.apache.org/repos/asf/servicemix/utils/trunk@1146175 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent e9ac5dd commit e7533e77bed51e4aba8c3ad1652d39b969304d14 @iocanel iocanel committed Jul 13, 2011
View
@@ -155,7 +155,11 @@
<artifactId>rjc</artifactId>
<version>0.6.4</version>
</dependency>
-
+ <dependency>
+ <groupId>net.sf.ehcache</groupId>
+ <artifactId>ehcache</artifactId>
+ <version>1.5.0</version>
+ </dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
@@ -0,0 +1,130 @@
+/*
+ * 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.servicemix.store.ehcache;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.config.CacheConfiguration;
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.DiskStoreConfiguration;
+
+/**
+ * @author: iocanel
+ */
+public class CacheManagerFactory {
+
+ private Boolean diskPersistent = Boolean.TRUE;
+ private Boolean eternal = Boolean.FALSE;
+ private int maxElementsInMemory=10000;
+ private Boolean overflowToDisk= Boolean.TRUE;
+ private long timeToIdleSeconds=300;
+ private long timeToLiveSeconds=300;
+ private String memoryStoreEvictionPolicy="LRU";
+
+ private String diskStorePath=".";
+
+
+ /**
+ * Builds the default {@ling CacheManager} instace
+ * @return
+ */
+ public CacheManager build() {
+ Configuration configuration = new Configuration();
+ CacheConfiguration defaultCacheConfiguration = new CacheConfiguration();
+ defaultCacheConfiguration.setMaxElementsInMemory(maxElementsInMemory);
+ defaultCacheConfiguration.setEternal(eternal);
+ defaultCacheConfiguration.setTimeToIdleSeconds(timeToIdleSeconds);
+ defaultCacheConfiguration.setTimeToLiveSeconds(timeToLiveSeconds);
+ defaultCacheConfiguration.setOverflowToDisk(overflowToDisk);
+ defaultCacheConfiguration.setDiskPersistent(diskPersistent);
+ defaultCacheConfiguration.setMemoryStoreEvictionPolicy(memoryStoreEvictionPolicy);
+
+ DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
+ diskStoreConfiguration.setPath(diskStorePath);
+ configuration.addDiskStore(diskStoreConfiguration);
+
+ configuration.addDefaultCache(defaultCacheConfiguration);
+
+
+ CacheManager cacheManager = new CacheManager(configuration);
+ return cacheManager;
+ }
+
+ public String getDiskStorePath() {
+ return diskStorePath;
+ }
+
+ public void setDiskStorePath(String diskStorePath) {
+ this.diskStorePath = diskStorePath;
+ }
+
+ public Boolean getDiskPersistent() {
+ return diskPersistent;
+ }
+
+ public void setDiskPersistent(Boolean diskPersistent) {
+ this.diskPersistent = diskPersistent;
+ }
+
+ public Boolean getEternal() {
+ return eternal;
+ }
+
+ public void setEternal(Boolean eternal) {
+ this.eternal = eternal;
+ }
+
+ public int getMaxElementsInMemory() {
+ return maxElementsInMemory;
+ }
+
+ public void setMaxElementsInMemory(int maxElementsInMemory) {
+ this.maxElementsInMemory = maxElementsInMemory;
+ }
+
+ public Boolean getOverflowToDisk() {
+ return overflowToDisk;
+ }
+
+ public void setOverflowToDisk(Boolean overflowToDisk) {
+ this.overflowToDisk = overflowToDisk;
+ }
+
+ public long getTimeToIdleSeconds() {
+ return timeToIdleSeconds;
+ }
+
+ public void setTimeToIdleSeconds(long timeToIdleSeconds) {
+ this.timeToIdleSeconds = timeToIdleSeconds;
+ }
+
+ public long getTimeToLiveSeconds() {
+ return timeToLiveSeconds;
+ }
+
+ public void setTimeToLiveSeconds(long timeToLiveSeconds) {
+ this.timeToLiveSeconds = timeToLiveSeconds;
+ }
+
+ public String getMemoryStoreEvictionPolicy() {
+ return memoryStoreEvictionPolicy;
+ }
+
+ public void setMemoryStoreEvictionPolicy(String memoryStoreEvictionPolicy) {
+ this.memoryStoreEvictionPolicy = memoryStoreEvictionPolicy;
+ }
+}
Oops, something went wrong.

0 comments on commit e7533e7

Please sign in to comment.