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

com.fireflysource.common.lifecycle.AbstractLifeCycle Maven / Gradle / Ivy

There is a newer version: 5.0.2
Show newest version
package com.fireflysource.common.lifecycle;

import java.util.concurrent.atomic.AtomicBoolean;

public abstract class AbstractLifeCycle implements LifeCycle {

    protected AtomicBoolean start = new AtomicBoolean(false);

    @Override
    public boolean isStarted() {
        return start.get();
    }

    @Override
    public boolean isStopped() {
        return !start.get();
    }

    @Override
    public void start() {
        if (start.compareAndSet(false, true)) {
            init();
        }
    }

    @Override
    public void stop() {
        if (start.compareAndSet(true, false)) {
            try {
                destroy();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    abstract protected void init();

    abstract protected void destroy();

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy