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

io.deephaven.io.logger.LogBufferGlobal Maven / Gradle / Ivy

There is a newer version: 0.36.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.io.logger;

import java.util.Objects;
import java.util.Optional;

public class LogBufferGlobal {

    private static LogBuffer INSTANCE;

    public static void setInstance(LogBuffer logBuffer) {
        synchronized (LogBufferGlobal.class) {
            if (INSTANCE != null) {
                throw new IllegalStateException("Should only LogBufferGlobal#setInstance once");
            }
            INSTANCE = Objects.requireNonNull(logBuffer, "logBuffer must not be null");
        }
    }

    public static Optional getInstance() {
        synchronized (LogBufferGlobal.class) {
            return Optional.ofNullable(INSTANCE);
        }
    }

    public static void clear(LogBuffer logBuffer) {
        synchronized (LogBufferGlobal.class) {
            if (logBuffer != INSTANCE) {
                throw new IllegalStateException("Can only clear existing log buffer");
            }
            INSTANCE = null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy