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

org.mockserver.stop.StopEventQueue Maven / Gradle / Ivy

There is a newer version: 5.15.0
Show newest version
package org.mockserver.stop;

import com.google.common.annotations.VisibleForTesting;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author jamesdbloom
 */
public class StopEventQueue implements Stoppable {

    @VisibleForTesting
    protected final List stoppables = new ArrayList();

    public void register(Stoppable stoppable) {
        synchronized (stoppables) {
            stoppables.add(stoppable);
        }
    }

    public void unregister(Stoppable stoppable) {
        synchronized (stoppables) {
            stoppables.remove(stoppable);
        }
    }

    public void clear() {
        synchronized (stoppables) {
            stoppables.clear();
        }
    }

    @Override
    public void stop() {
        synchronized (stoppables) {
            for (Stoppable stoppable : new ArrayList(stoppables)) {
                unregister(stoppable);
                stoppable.stop();
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy