Package: SiteResetterOnFileSystemChange$1
SiteResetterOnFileSystemChange$1
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
notify(ResourceFileSystemChangedEvent) |
|
|
|
|
|
||||||||||||||||||||
{...} |
|
|
|
|
|
Coverage
1: /*
2: * #%L
3: * *********************************************************************************************************************
4: *
5: * NorthernWind - lightweight CMS
6: * http://northernwind.tidalwave.it - git clone https://bitbucket.org/tidalwave/northernwind-src.git
7: * %%
8: * Copyright (C) 2011 - 2023 Tidalwave s.a.s. (http://tidalwave.it)
9: * %%
10: * *********************************************************************************************************************
11: *
12: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
13: * the License. You may obtain a copy of the License at
14: *
15: * http://www.apache.org/licenses/LICENSE-2.0
16: *
17: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
18: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
19: * specific language governing permissions and limitations under the License.
20: *
21: * *********************************************************************************************************************
22: *
23: *
24: * *********************************************************************************************************************
25: * #L%
26: */
27: package it.tidalwave.northernwind.core.model.spi;
28:
29: import javax.annotation.Nonnull;
30: import javax.annotation.PostConstruct;
31: import javax.inject.Inject;
32: import javax.inject.Named;
33: import javax.inject.Provider;
34: import it.tidalwave.messagebus.MessageBus;
35: import it.tidalwave.messagebus.MessageBus.Listener;
36: import it.tidalwave.northernwind.core.model.ResourceFileSystemChangedEvent;
37: import it.tidalwave.northernwind.core.model.SiteProvider;
38: import lombok.extern.slf4j.Slf4j;
39:
40: /***********************************************************************************************************************
41: *
42: * A simple utility that forces a reset of the {@link it.tidalwave.northernwind.core.model.Site} when a change in the
43: * underlying file system is detected.
44: *
45: * @author Fabrizio Giudici
46: *
47: **********************************************************************************************************************/
48: @Slf4j
49: public class SiteResetterOnFileSystemChange // TODO: rename to SiteReloaderOnFileSystemChange
50: {
51: @Inject
52: private Provider<SiteProvider> siteProvider;
53:
54: @Inject @Named("applicationMessageBus")
55: private MessageBus messageBus;
56:
57: private final Listener<ResourceFileSystemChangedEvent> listener = new Listener<>()
58: {
59: @Override
60: public void notify (@Nonnull final ResourceFileSystemChangedEvent event)
61: {
62: // FIXME: the originator of the event could be a child filesystem in case of composite filesystems.
63: // Either the event is listened by the parent and reposted, or we must be able to find whether a
64: // given filesystem is the parent of another
65: //
66: // e.g. if (siteProvider.get().getSite().getFileSystemProvider().contains(event.getFileSystemProvider()))
67: //
68: // log.info("event fileSystemProvider {}", event.getFileSystemProvider());
69: // log.info("site fileSystemProvider {}", siteProvider.get().getSite().getFileSystemProvider());
70:
71: // if (event.getFileSystemProvider() == siteProvider.get().getSite().getFileSystemProvider())
72: // {
73: log.info("Detected file change, resetting site...");
74: siteProvider.get().reload();
75: // }
76: }
77: };
78:
79: @PostConstruct
80: /* package */ void initialize() // FIXME: unsubscribe on @PreDestroy
81: {
82: messageBus.subscribe(ResourceFileSystemChangedEvent.class, listener);
83: log.info("SiteResetterOnFileSystemChange installed");
84: }
85: }