You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/08/30 21:12:13 UTC
svn commit: r990902 - in /directory/apacheds/trunk/core-api/src/main:
java/org/apache/directory/server/core/CacheService.java resources/
resources/directory-cacheservice.xml
Author: kayyagari
Date: Mon Aug 30 19:12:12 2010
New Revision: 990902
URL: http://svn.apache.org/viewvc?rev=990902&view=rev
Log:
o adding a cache service based on ehcache
Added:
directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CacheService.java
directory/apacheds/trunk/core-api/src/main/resources/
directory/apacheds/trunk/core-api/src/main/resources/directory-cacheservice.xml
Added: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CacheService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CacheService.java?rev=990902&view=auto
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CacheService.java (added)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/CacheService.java Mon Aug 30 19:12:12 2010
@@ -0,0 +1,99 @@
+/*
+ * 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.directory.server.core;
+
+
+import java.io.File;
+
+import net.sf.ehcache.Cache;
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Status;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * A ehcache based cache service to be used for various caching requirement in the server.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CacheService
+{
+
+ private static final String DIRECTORY_CACHESERVICE_XML = "directory-cacheservice.xml";
+
+ private static final Logger LOG = LoggerFactory.getLogger( CacheService.class );
+
+ /** the ehcache cache manager */
+ private CacheManager cacheManager;
+
+
+ protected CacheService()
+ {
+ }
+
+
+ public void initialize( DirectoryService dirService )
+ {
+ if ( ( cacheManager != null ) && ( cacheManager.getStatus() == Status.STATUS_ALIVE ) )
+ {
+ LOG.warn( "cache service was already initialized and is alive" );
+ return;
+ }
+
+ File configFile = new File( dirService.getWorkingDirectory(), DIRECTORY_CACHESERVICE_XML );
+
+ if ( !configFile.exists() )
+ {
+ LOG.info( "no custom cache configuration was set, loading the default cache configuration" );
+
+ cacheManager = new CacheManager( getClass().getClassLoader().getResource( DIRECTORY_CACHESERVICE_XML ) );
+ }
+ else
+ {
+ LOG.info( "loading cache configuration from the file {}", configFile );
+
+ cacheManager = new CacheManager( configFile.getAbsolutePath() );
+ }
+ }
+
+
+ public void destroy()
+ {
+ if ( cacheManager.getStatus() == Status.STATUS_ALIVE )
+ {
+ LOG.info( "destroying the cache service" );
+
+ cacheManager.removalAll();
+
+ cacheManager.shutdown();
+ }
+ }
+
+
+ public Cache getCache( String name )
+ {
+ LOG.info( "fetching the cache named {}", name );
+
+ return cacheManager.getCache( name );
+ }
+}
Added: directory/apacheds/trunk/core-api/src/main/resources/directory-cacheservice.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/resources/directory-cacheservice.xml?rev=990902&view=auto
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/resources/directory-cacheservice.xml (added)
+++ directory/apacheds/trunk/core-api/src/main/resources/directory-cacheservice.xml Mon Aug 30 19:12:12 2010
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="ehcache.xsd"
+ updateCheck="false" monitoring="autodetect"
+ dynamicConfig="true" >
+
+ <diskStore path="java.io.tmpdir"/>
+
+ <cacheManagerEventListenerFactory class="" properties=""/>
+
+ <!--
+ 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="0"
+ eternal="false"
+ overflowToDisk="true"
+ timeToIdleSeconds="1200"
+ timeToLiveSeconds="1200">
+ </defaultCache>
+
+ <!--
+ Sample cache named sampleCache1
+ This cache contains a maximum in memory of 10000 elements, and will expire
+ an element if it is idle for more than 5 minutes and lives for more than
+ 10 minutes.
+
+ If there are more than 10000 elements it will overflow to the
+ disk cache, which in this configuration will go to wherever java.io.tmp is
+ defined on your system. On a standard Linux system this will be /tmp"
+ -->
+ <cache name="groupCache"
+ maxElementsInMemory="10000"
+ maxElementsOnDisk="1000"
+ eternal="true"
+ overflowToDisk="true"
+ diskSpoolBufferSizeMB="20"
+ timeToIdleSeconds="300"
+ timeToLiveSeconds="600"/>
+</ehcache>
\ No newline at end of file