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

com.fasterxml.clustermate.service.cleanup.CleanupTask Maven / Gradle / Ivy

There is a newer version: 0.10.5
Show newest version
package com.fasterxml.clustermate.service.cleanup;

import java.util.concurrent.atomic.AtomicBoolean;

import com.fasterxml.clustermate.service.SharedServiceStuff;
import com.fasterxml.clustermate.service.Stores;
import com.fasterxml.clustermate.service.cluster.ClusterViewByServer;
import com.fasterxml.storemate.shared.TimeMaster;

public abstract class CleanupTask
{
    protected TimeMaster _timeMaster;
    
    protected AtomicBoolean _shutdown;

    protected long _startupTime;

    protected CleanupTask() { }

    protected void init(SharedServiceStuff stuff, Stores stores,
            ClusterViewByServer cluster, AtomicBoolean shutdown)
    {
        _timeMaster = stuff.getTimeMaster();
        _shutdown = shutdown;
    }

    /**
     * Method called by {@link CleanerUpper} when its own prepareForStop()
     * is called; sub-classes may react. Note that when method gets called,
     * {@link #_shutdown} has already been set to true.
     */
    protected void prepareForStop() {
        // Nothing generic to do here
    }
    
    protected boolean shouldStop() {
        return _shutdown.get();
    }

    protected T cleanUp() throws Exception
    {
        _startupTime = _timeMaster.currentTimeMillis();
        return _cleanUp();
    }

    protected abstract T _cleanUp() throws Exception;

    @Override
    public String toString() {
        return getClass().getName();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy