Skip to content

Commit

Permalink
feat(Reactive): delete file observation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Oct 20, 2020
1 parent bd7c695 commit e9ea525
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void afterInitialization() {
fileWatcher.setFileWatcherHandler(new FileWatcherHandler() {
@Override
public void onCreated(Path file) {
log.info("onCreated: {}", file);
log.debug("Created file observed: {}", file);
Video video = new Video();
video.setName(file.getFileName().toString());
video.setLocation(file);
Expand All @@ -49,12 +49,13 @@ public void onCreated(Path file) {

@Override
public void onDeleted(Path file) {
log.info("onDeleted: {}", file);
log.debug("Deleted file observed: {}", file);
Mono.just(file).then(videoRepository.deleteVideoByPath(file)).subscribe();
}

@Override
public void onModified(Path file) {
log.info("onModified: {}", file);
log.info("Modified file observed: {}", file);
Video video = new Video();
video.setName(file.getFileName().toString());
video.setLocation(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.file.Path;

/**
* Description: VideoRepository, change description here.
*
Expand Down Expand Up @@ -33,6 +35,14 @@ public interface VideoRepository {
*/
Mono<Video> addVideo(Video video);

/**
* Delete video by path mono.
*
* @param path the path
* @return the mono
*/
Mono<Video> deleteVideoByPath(Path path);

/**
* Delete video by name mono.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.file.Path;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -39,10 +40,12 @@ public Flux<Video> getAllVideos() {

@Override
public Mono<Video> addVideo(Video video) {
return Mono.fromCallable(() -> {
log.debug(VIDEO_CACHE.toString());
return VIDEO_CACHE.put(video.getName(), video);
});
return Mono.fromCallable(() -> VIDEO_CACHE.put(video.getName(), video));
}

@Override
public Mono<Video> deleteVideoByPath(Path path) {
return this.deleteVideoByName(path.getFileName().toString());
}

@Override
Expand Down

0 comments on commit e9ea525

Please sign in to comment.