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

com.bazaarvoice.emodb.common.dropwizard.lifecycle.SimpleLifeCycleRegistry Maven / Gradle / Ivy

There is a newer version: 6.5.190
Show newest version
package com.bazaarvoice.emodb.common.dropwizard.lifecycle;

import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import io.dropwizard.lifecycle.Managed;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;

/**
 * Simple implementation of {@link LifeCycleRegistry}.
 */
public class SimpleLifeCycleRegistry implements LifeCycleRegistry, Managed, Closeable {
    private final List _managed = Lists.newArrayList();

    @Override
    public void start() throws Exception {
        for (Managed managed : _managed) {
            managed.start();
        }
    }

    @Override
    public void stop() throws Exception {
        for (Managed managed : Lists.reverse(_managed)) {
            managed.stop();
        }
        _managed.clear();
    }

    @Override
    public void close() throws IOException {
        try {
            stop();
        } catch (Exception e) {
            Throwables.propagateIfInstanceOf(e, IOException.class);
            throw Throwables.propagate(e);
        }
    }

    @Override
    public  T manage(T managed) {
        _managed.add(managed);
        return managed;
    }

    @Override
    public  T manage(T closeable) {
        _managed.add(new ManagedCloseable(closeable));
        return closeable;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy