public boolean close ( ) { if ( open . compareAndSet ( true , false ) ) { LOG . debug ( "Closing webcam {}" , getName ( ) ) ; assert lock != null ; // close webcam WebcamCloseTask task = new WebcamCloseTask ( driver , device ) ; try { task . close ( ) ; } catch ( InterruptedException e ) { open . set ( true ) ; LOG . debug ( "Thread has been interrupted before webcam was closed!" , e ) ; return false ; } catch ( WebcamException e ) { open . set ( true ) ; throw e ; } // stop updater if ( asynchronous ) { updater . stop ( ) ; } // remove shutdown hook (it's not more necessary) removeShutdownHook ( ) ; // unlock webcam so other Java processes can start using it lock . unlock ( ) ; // notify listeners WebcamEvent we = new WebcamEvent ( WebcamEventType . CLOSED , this ) ; Iterator < WebcamListener > wli = listeners . iterator ( ) ; WebcamListener l = null ; while ( wli . hasNext ( ) ) { l = wli . next ( ) ; try { l . webcamClosed ( we ) ; } catch ( Exception e ) { LOG . error ( String . format ( "Notify webcam closed, exception when calling %s listener" , l . getClass ( ) ) , e ) ; } } notificator . shutdown ( ) ; while ( ! notificator . isTerminated ( ) ) { try { notificator . awaitTermination ( 100 , TimeUnit . MILLISECONDS ) ; } catch ( InterruptedException e ) { return false ; } } LOG . debug ( "Webcam {} has been closed" , getName ( ) ) ; } else { LOG . debug ( "Webcam {} is already closed" , getName ( ) ) ; } return true ; }
Close the webcam .