01: /*
02: * Copyright 2007 Hippo
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS"
12: * BASIS, 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 nl.hippo.cms.background;
17:
18: import java.util.LinkedList;
19: import java.util.List;
20:
21: import org.apache.avalon.framework.configuration.Configurable;
22: import org.apache.avalon.framework.configuration.Configuration;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.avalon.framework.parameters.ParameterException;
25: import org.apache.avalon.framework.parameters.Parameters;
26: import org.apache.avalon.framework.service.ServiceManager;
27: import org.apache.cocoon.components.cron.JobScheduler;
28:
29: /**
30: * @author <a href="mailto:b.vanhalderen@hippo.nl">(Berry) A.W. van Halderen</a>
31: *
32: * @version $Id: TempFileCleanupManager.java 8209 2007-09-19 16:03:37Z ddam $
33: */
34: public class TempFileCleanupManager extends
35: AbstractBackgroundTaskManager implements Configurable {
36:
37: protected ServiceManager manager;
38: protected JobScheduler scheduler;
39: private int ttl; // interval after which files are being deleted in seconds
40: private TempFileCleanup cleaner;
41:
42: public TempFileCleanupManager() {
43: super ();
44: cleaner = new TempFileCleanup();
45: }
46:
47: public Runnable getTaskRunnable() {
48: return cleaner;
49: }
50:
51: public boolean isBackgroundTaskActive() {
52: return ttl > 0;
53: }
54:
55: public void parameterize(Parameters parameters)
56: throws ParameterException {
57: ttl = parameters.getParameterAsInteger("ttl", -1);
58:
59: int interval = parameters.getParameterAsInteger("interval", -1);
60:
61: if (interval == -1) {
62: setInterval(ttl / 2);
63: } else {
64: setInterval(ttl);
65: }
66:
67: cleaner.setCleanupAfterSecs(ttl);
68: }
69:
70: public void configure(Configuration cfg)
71: throws ConfigurationException {
72: List tempFilePatterns = null;
73: Configuration[] tempFilePatternsCfgs = cfg
74: .getChildren("pattern");
75: if (tempFilePatternsCfgs != null) {
76: tempFilePatterns = new LinkedList();
77: for (int i = 0; i < tempFilePatternsCfgs.length; i++) {
78: String s = tempFilePatternsCfgs[i].getValue();
79: if (s != null) {
80: tempFilePatterns.add(s);
81: }
82: }
83: }
84: if (tempFilePatterns != null && tempFilePatterns.size() > 0)
85: cleaner.setTempFileWildcardPatterns(tempFilePatterns);
86: }
87:
88: }
|