Package: DefaultMediaFileSystem
DefaultMediaFileSystem
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DefaultMediaFileSystem() |
|
|
|
|
|
||||||||||||||||||||
afterPropertiesSet() |
|
|
|
|
|
||||||||||||||||||||
as(Class) |
|
|
|
|
|
||||||||||||||||||||
as(Class, As.NotFoundBehaviour) |
|
|
|
|
|
||||||||||||||||||||
asMany(Class) |
|
|
|
|
|
||||||||||||||||||||
asOptional(Class) |
|
|
|
|
|
||||||||||||||||||||
destroy() |
|
|
|
|
|
||||||||||||||||||||
getRoot() |
|
|
|
|
|
||||||||||||||||||||
getRootPath() |
|
|
|
|
|
||||||||||||||||||||
maybeAs(Class) |
|
|
|
|
|
||||||||||||||||||||
onPowerOnNotification(PowerOnNotification) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
||||||||||||||||||||
waitForPowerOn() |
|
|
|
|
|
Coverage
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.model.impl;
28:
29: import javax.annotation.Nonnull;
30: import java.util.concurrent.CountDownLatch;
31: import java.nio.file.Path;
32: import it.tidalwave.util.NotFoundException;
33: import it.tidalwave.util.annotation.VisibleForTesting;
34: import it.tidalwave.util.spi.PriorityAsSupport;
35: import it.tidalwave.messagebus.annotation.ListensTo;
36: import it.tidalwave.messagebus.annotation.SimpleMessageSubscriber;
37: import it.tidalwave.bluemarine2.model.MediaFileSystem;
38: import it.tidalwave.bluemarine2.model.MediaFolder;
39: import it.tidalwave.bluemarine2.model.ModelPropertyNames;
40: import it.tidalwave.bluemarine2.message.PowerOnNotification;
41: import lombok.Getter;
42: import lombok.experimental.Delegate;
43: import lombok.extern.slf4j.Slf4j;
44: import static java.util.concurrent.TimeUnit.SECONDS;
45:
46: /***********************************************************************************************************************
47: *
48: * @author Fabrizio Giudici
49: *
50: **********************************************************************************************************************/
51: @SimpleMessageSubscriber @Slf4j
52: public class DefaultMediaFileSystem implements MediaFileSystem
53: {
54: private final CountDownLatch initialized = new CountDownLatch(1);
55:
56: @Getter
57: private Path rootPath;
58:
59: @Delegate
60: private final PriorityAsSupport asSupport = new PriorityAsSupport(this);
61:
62: /*******************************************************************************************************************
63: *
64: *
65: ******************************************************************************************************************/
66: @Override @Nonnull
67: public MediaFolder getRoot()
68: {
69: waitForPowerOn();
70: return new FileSystemMediaFolder(rootPath, null, rootPath);
71: }
72:
73: /*******************************************************************************************************************
74: *
75: *
76: ******************************************************************************************************************/
77: @VisibleForTesting public void onPowerOnNotification (@ListensTo @Nonnull final PowerOnNotification notification)
78: throws NotFoundException
79: {
80: log.info("onPowerOnNotification({})", notification);
81: rootPath = notification.getProperties().get(ModelPropertyNames.ROOT_PATH).resolve("Music");
82: log.info(">>>> rootPath: {}", rootPath);
83: initialized.countDown();
84: }
85:
86: /*******************************************************************************************************************
87: *
88: *
89: ******************************************************************************************************************/
90: private void waitForPowerOn()
91: {
92: try
93: {
94:• if (!initialized.await(10, SECONDS))
95: {
96: throw new IllegalStateException("rooPath null: did not receive PowerOnNotification");
97: }
98: }
99: catch (InterruptedException ex)
100: {
101: throw new IllegalStateException("Interrupted while waiting for PowerOnNotification");
102: }
103: }
104: }