001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.wicket.util.file;
018
019import java.io.File;
020
021import org.apache.commons.io.FileDeleteStrategy;
022
023/**
024 * Keeps track of files awaiting deletion, and deletes them when an associated marker object is
025 * reclaimed by the garbage collector.
026 * 
027 * <p>
028 * Needed to remove files created temporarily for the needs of FileUpload functionality.
029 */
030public interface IFileCleaner
031{
032
033        /**
034         * Track the specified file, using the provided marker, deleting the file when the marker
035         * instance is garbage collected.
036         * 
037         * @param file
038         *            the file to be tracked, not null
039         * @param marker
040         *            the marker object used to track the file, not null
041         * @throws NullPointerException
042         *             if the file is null
043         */
044        void track(File file, Object marker);
045
046        /**
047         * Track the specified file, using the provided marker, deleting the file when the marker
048         * instance is garbage collected.
049         * 
050         * @param file
051         *            the file to be tracked, not null
052         * @param marker
053         *            the marker object used to track the file, not null
054         * @param deleteStrategy
055         *            the strategy that actually deletes the file. E.g. to delete a non-empty folder the
056         *            strategy should delete all children first
057         * @throws NullPointerException
058         *             if the file is null
059         */
060        void track(File file, Object marker, FileDeleteStrategy deleteStrategy);
061
062        /**
063         * Call this method to stop the cleaner and to free all allocated resources by it
064         */
065        void destroy();
066}