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