All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.tsl2.nano.execution.VolatileResult Maven / Gradle / Ivy

Go to download

TSL2 Framework Commons (Collections, Actions/Excecution, Readers, Xml, Print, Mail, FuzzyFinder, Proxies, Network-Structure)

There is a newer version: 2.5.1
Show newest version
/*
 * File: $HeadURL$
 * Id  : $Id$
 * 
 * created by: Tom
 * created on: 16.07.2016
 * 
 * Copyright: (c) Thomas Schneider 2016, all rights reserved
 */
package de.tsl2.nano.execution;

import java.io.Serializable;
import java.util.Map;

import de.tsl2.nano.core.ManagedException;
import de.tsl2.nano.historize.Volatile;

/**
 * A Runner (see {@link IPRunnable}) that checks, if it is already running - or (see {@link Volatile} the result already
 * expired.
 * 
 * @author Tom
 * @version $Revision$
 */
public class VolatileResult extends Volatile {
    IPRunnable> runner;
    boolean isRunning;

    public VolatileResult(long period, IPRunnable> runner) {
        super(period, null);
        this.runner = runner;
    }

    public T get(Map context, Object... extArgs) {
        return get(runner, context, extArgs);
    }
    
    public T get(IPRunnable> runner, Map context, Object... extArgs) {
        if (expired() && !isRunning)
            try {
                set(runner.run(context, extArgs));
            } catch(Exception ex) {
                //on errors , the expired should be set, too
                activate();
                ManagedException.forward(ex);
            } finally {
                isRunning = false;
            }
        return get();
    }
    
    public String getName() {
        return runner.getName();
    }
    public Map getParameter() {
        return runner.getParameter();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy