-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
103 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
webcam-capture/src/main/java/com/github/sarxos/webcam/WebcamShutdownHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
LOG.info("Automatic {} deallocation", webcam.getName()); | ||
webcam.dispose(); | ||
} | ||
} |