@@ -0,0 +1,3289 @@
+/*%0A * Copyright 2001-2004 The Apache Software Foundation.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22)%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage org.apache.jcs.yajcache.file;%0A%0Aimport java.io.Serializable;%0Aimport org.apache.commons.lang.SerializationUtils;%0Aimport org.apache.jcs.yajcache.core.ICacheChangeListener;%0Aimport org.apache.jcs.yajcache.event.CacheChangeEvent;%0A%0Aimport org.apache.jcs.yajcache.lang.annotation.*;%0Aimport org.apache.jcs.yajcache.core.ICache;%0Aimport org.apache.jcs.yajcache.core.ICacheChangeHandler;%0A/**%0A *%0A * Handle cache change events by persisting to or removing from the file system.%0A * @author Hanson Char%0A */%0A@CopyRightApache%0Apublic class CacheFileManager%3CV%3E %0A        implements ICacheChangeListener%3CV%3E, ICacheChangeHandler%3CV%3E%0A%7B%0A    private ICache%3CV%3E cache;%0A    %0A    public CacheFileManager(ICache%3CV%3E cache) %7B%0A        this.cache = cache;%0A        // Creates the file directory for the cache%0A        CacheFileUtils.inst.mkCacheDirs(cache.getName());%0A    %7D%0A    @Implements(ICacheChangeListener.class)%0A    public void cacheChange(@NonNullable CacheChangeEvent%3CV%3E event) %7B%0A        event.dispatch(this);%0A    %7D%0A    %0A    @Implements(ICacheChangeHandler.class)%0A    public boolean handlePut(@NonNullable String cacheName, %0A            @NonNullable String key, @NonNullable V value) %0A    %7B%0A        if (value instanceof Serializable) %7B%0A            byte%5B%5D ba = SerializationUtils.serialize((Serializable)value);%0A            CacheFileDAO.inst.writeCacheItem(%0A                cacheName, CacheFileContentType.JAVA_SERIALIZATION, key, ba);%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A    @Implements(ICacheChangeHandler.class)%0A    public boolean handleRemove(%0A            @NonNullable String cacheName, @NonNullable String key) %0A    %7B%0A        return CacheFileDAO.inst.removeCacheItem(cacheName, key);%0A    %7D%0A    @Implements(ICacheChangeHandler.class)%0A    public boolean handleClear(@NonNullable String cacheName) %7B%0A        return CacheFileUtils.inst.rmCacheDir(cacheName);%0A    %7D%0A    %0A    @TODO(%22Avoid multiple serialization for the same put%22)%0A    @Implements(ICacheChangeHandler.class)%0A    public boolean handlePutCopy(@NonNullable String cacheName, %0A            @NonNullable String key, @NonNullable V value) %0A    %7B%0A        return false;%0A    %7D%0A    @TODO(%22Avoid multiple serialization for the same put%22)%0A    @Implements(ICacheChangeHandler.class)%0A    public boolean handlePutBeanCopy(@NonNullable String cacheName, %0A            @NonNullable String key, @NonNullable V value) %0A    %7B%0A        return false;%0A    %7D%0A    @TODO(%22Avoid multiple serialization for the same put%22)%0A    @Implements(ICacheChangeHandler.class)%0A    public boolean handlePutBeanClone(@NonNullable String cacheName, %0A            @NonNullable String key, @NonNullable V value) %0A    %7B%0A        return false;%0A    %7D%0A%7D%0A

implement cache change listener and handler