Skip to content

Commit

Permalink
Make shutdown protected, refs #289
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jan 12, 2015
1 parent 6b1ac58 commit 7c673a8
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.swing.JApplet;

import com.github.sarxos.webcam.WebcamCaptureFrameworkDestroyer;
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamResolution;
Expand Down Expand Up @@ -61,7 +62,7 @@ public void start() {
public void destroy() {
System.out.println("Destroy");
webcam.close();
Webcam.shutdown();
WebcamCaptureFrameworkDestroyer.destroy();
System.out.println("Destroyed");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.sarxos.webcam;

/**
* IMPORTANT! This approach should be used only in case of Applets (due to its non standard
* lifecycle).
*
* @author Bartosz Firyn (sarxos)
*/
public class WebcamCaptureFrameworkDestroyer {

public static final void destroy() {
Webcam.shutdown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ public void startCamera(ActionEvent event) {
public void disposeCamera(ActionEvent event) {
stopCamera = true;
closeCamera();
Webcam.shutdown();
btnStopCamera.setDisable(true);
btnStartCamera.setDisable(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public void handle(ActionEvent arg0) {
protected void disposeWebCamCamera() {
stopCamera = true;
webCam.close();
Webcam.shutdown();
btnCamreaStart.setDisable(true);
btnCamreaStop.setDisable(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,11 @@ public WebcamLock getLock() {
}

/**
* Shutdown webcam framework.
* Shutdown webcam framework. This method should be used <b>ONLY</b> when you
* are exiting JVM, but please <b>do not invoke it</b> if you really don't
* need to.
*/
public static void shutdown() {
protected static void shutdown() {

// stop discovery service
WebcamDiscoveryService discovery = getDiscoveryServiceRef();
Expand Down

0 comments on commit 7c673a8

Please sign in to comment.