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

com.github.andy2003.logging.snapshots.SnapshotManager Maven / Gradle / Ivy

The newest version!
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.github.andy2003.logging.snapshots;

import com.github.andy2003.core.TimeEventReceiver;
import com.github.andy2003.ui.time.TimeSourceManager;

/**
 *
 * @author Jan-Niklas Meier 
 */
public class SnapshotManager {

    private static SnapshotBuffer buffer;

    /**
     * Returns the current active {@link SnapshotBuffer}. If no SnapshotBuffer
     * is present one is created and buffering is started.
     * This method ensures that a new buffer is created after invocation.
     * @return
     */
    public static SnapshotBuffer getCurrentBuffer() {
        SnapshotBuffer oldbuffer = buffer;

        if(oldbuffer == null) {
            oldbuffer = new SnapshotBuffer();
            oldbuffer.startBuffering();
        }

        buffer = new SnapshotBuffer();
        startBuffering();

        return oldbuffer;
    }

    /**
     * Create a new SnapshotBuffer and start buffering.
     */
    public static void startBuffering() {
        if(buffer == null)
            buffer = new SnapshotBuffer();

        if(!buffer.isBuffering())
            buffer.startBuffering();
    }

    public static void enableBuffering() {
        TimeSourceManager.getGlobalTimeSource().register(receiver);
    }

    private static TimeEventReceiver receiver = new TimeEventReceiver() {

        public void paused() {

        }
	public void played() {
            buffer = new SnapshotBuffer();
            buffer.startBuffering();

        }
	public void stopped() {
            if(buffer != null && buffer.isBuffering()) {
                buffer.stopBuffering(0);
            }
        }
    };

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy