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

com.github.sarxos.webcam.WebcamShutdownHook Maven / Gradle / Ivy

Go to download

This library allows you to use your PC webcam, IP or network cameras directly from Java. It's compatible with most operating systems (Windows, Linux, MacOS).

The newest version!
package com.github.sarxos.webcam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Shutdown hook to be executed when JVM exits gracefully. This class intention
 * is to be used internally only.
 * 
 * @author Bartosz Firyn (sarxos)
 */
public final class WebcamShutdownHook extends Thread {

	/**
	 * Logger.
	 */
	private static final Logger LOG = LoggerFactory.getLogger(WebcamShutdownHook.class);

	/**
	 * Number of shutdown hook instance.
	 */
	private static int number = 0;

	/**
	 * Webcam instance to be disposed / closed.
	 */
	private Webcam webcam = null;

	/**
	 * Create new shutdown hook instance.
	 * 
	 * @param webcam the webcam for which hook is intended
	 */
	protected WebcamShutdownHook(Webcam webcam) {
		super("shutdown-hook-" + (++number));
		this.webcam = webcam;
		this.setUncaughtExceptionHandler(WebcamExceptionHandler.getInstance());
	}

	@Override
	public void run() {
		LOG.info("Automatic {} deallocation", webcam.getName());
		webcam.dispose();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy