private void handleResourceRequest ( EventModel eventModel ) { if ( MusicUsageResource . isPermanent ( eventModel ) ) { ResourceModel resourceModel = eventModel . getListResourceContainer ( ) . provideResource ( MusicUsageResource . ID ) . stream ( ) . filter ( MusicUsageResource :: isPermanent ) . findAny ( ) . orElse ( null ) ; //should not happen //a partially applied function which takes an Identification an returns an Optional StartMusicRequest Function < Identification , Optional < StartMusicRequest > > getStartMusicRequest = own -> StartMusicRequest . createStartMusicRequest ( resourceModel . getProvider ( ) , own ) ; //if we have a trackInfo we create it with the trackInfo as a parameter getStartMusicRequest = TrackInfoResource . getTrackInfo ( eventModel ) . map ( trackInfo -> ( Function < Identification , Optional < StartMusicRequest > > ) own -> StartMusicRequest . createStartMusicRequest ( resourceModel . getProvider ( ) , own , trackInfo ) ) . orElse ( getStartMusicRequest ) ; //if we have a trackInfo we create it with the playlist as a parameter getStartMusicRequest = PlaylistResource . getPlaylist ( eventModel ) . map ( playlist -> ( Function < Identification , Optional < StartMusicRequest > > ) own -> StartMusicRequest . createStartMusicRequest ( resourceModel . getProvider ( ) , own , playlist ) ) . orElse ( getStartMusicRequest ) ; //composes a new Function which appends the Volume to the result getStartMusicRequest = getStartMusicRequest . andThen ( VolumeResource . getVolume ( eventModel ) . flatMap ( volume -> IdentificationManagerM . getInstance ( ) . getIdentification ( this ) . map ( identification -> new VolumeResource ( identification , volume ) ) ) . map ( resource -> ( Function < Optional < StartMusicRequest > , Optional < StartMusicRequest > > ) opt -> opt . map ( event -> ( StartMusicRequest ) event . addResource ( resource ) ) ) . orElse ( Function . identity ( ) ) :: apply ) ; IdentificationManagerM . getInstance ( ) . getIdentification ( this ) . flatMap ( getStartMusicRequest :: apply ) . ifPresent ( this :: fire ) ; } else { play ( eventModel ) ; if ( ! runsInPlay ) { blockRequest = lock . newCondition ( ) ; lock . lock ( ) ; try { blockRequest . await ( 10 , TimeUnit . MINUTES ) ; } catch ( InterruptedException e ) { debug ( "interrupted" , e ) ; } finally { lock . unlock ( ) ; } } } }
handles the a request to start playing music via Resource