001/*
002 *  Copyright 2018 Anyware Services
003 *
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package org.ametys.web.cache.scheduler;
017
018import org.apache.avalon.framework.configuration.Configuration;
019import org.apache.avalon.framework.configuration.ConfigurationException;
020import org.apache.avalon.framework.configuration.DefaultConfiguration;
021
022import org.ametys.core.schedule.Runnable;
023import org.ametys.plugins.core.impl.schedule.StaticRunnable;
024import org.ametys.runtime.config.Config;
025
026/**
027 * A {@link Runnable} for invalidating FO cache if enabled in config (by web.invalidate.focache.scheduler.enabled)
028 * If os, will thus run at startup.
029 */
030public class InvalidateFOCacheRunnable extends StaticRunnable
031{
032    @Override
033    public void configure(Configuration configuration) throws ConfigurationException
034    {
035        DefaultConfiguration modifiedConfiguration = new DefaultConfiguration(configuration);
036        DefaultConfiguration fireProcessConfig = new DefaultConfiguration("fire-process");
037        String fireProcess = (boolean) Config.getInstance().getValue("web.invalidate.focache.scheduler.enabled") ? "startup" : "never";
038        fireProcessConfig.setValue(fireProcess);
039        modifiedConfiguration.addChild(fireProcessConfig);
040        
041        // Call configure of StaticRunnable
042        super.configure(modifiedConfiguration);
043    }
044}