KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > FopImageCacheCleaner


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.frontend;
17
18 import org.apache.avalon.framework.activity.Initializable;
19 import org.apache.avalon.framework.configuration.Configurable;
20 import org.apache.avalon.framework.configuration.Configuration;
21 import org.apache.avalon.framework.configuration.ConfigurationException;
22 import org.apache.avalon.framework.thread.ThreadSafe;
23 import org.apache.avalon.framework.logger.AbstractLogEnabled;
24 import org.apache.avalon.framework.service.ServiceManager;
25 import org.apache.avalon.framework.service.Serviceable;
26 import org.apache.avalon.framework.service.ServiceException;
27 import org.apache.cocoon.components.thread.RunnableManager;
28
29 /**
30  * Cleans the FOP image cache at scheduled intervals.
31  */

32 public class FopImageCacheCleaner extends AbstractLogEnabled implements Initializable, Configurable, ThreadSafe, Serviceable {
33     private ServiceManager serviceManager;
34     private long interval;
35     private long initialDelay;
36
37     public void service(ServiceManager serviceManager) throws ServiceException {
38         this.serviceManager = serviceManager;
39     }
40
41     public void initialize() throws Exception JavaDoc {
42         RunnableManager runnableManager = (RunnableManager)serviceManager.lookup(RunnableManager.ROLE);
43         try {
44             runnableManager.execute(new CleanCacheCommand(), initialDelay, interval);
45         } finally {
46             serviceManager.release(runnableManager);
47         }
48     }
49
50     public void configure(Configuration configuration) throws ConfigurationException {
51         initialDelay = configuration.getChild("offset").getValueAsLong();
52         interval = configuration.getChild("period").getValueAsLong();
53     }
54
55     final class CleanCacheCommand implements Runnable JavaDoc {
56         public void run() {
57             getLogger().debug("Clearing FOP image cache.");
58             org.apache.fop.image.FopImageFactory.resetCache();
59         }
60     }
61 }
62
Popular Tags