mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 11:45:49 +01:00
Use constructor injection to simplify lifecycle (#994)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
parent
be1cd25743
commit
e2132a7a46
@ -76,7 +76,7 @@ import com.google.gson.JsonSyntaxException;
|
|||||||
* Last but not least, a pid can be defined in the first line of a cfg file by prefixing it with "pid:", e.g.
|
* Last but not least, a pid can be defined in the first line of a cfg file by prefixing it with "pid:", e.g.
|
||||||
* "pid: com.acme.smarthome.security".
|
* "pid: com.acme.smarthome.security".
|
||||||
*
|
*
|
||||||
* @author Kai Kreuzer - Initial contribution and API
|
* @author Kai Kreuzer - Initial contribution
|
||||||
* @author Petar Valchev - Added sort by modification time, when configuration files are read
|
* @author Petar Valchev - Added sort by modification time, when configuration files are read
|
||||||
* @author Ana Dimova - Reduce to a single watch thread for all class instances
|
* @author Ana Dimova - Reduce to a single watch thread for all class instances
|
||||||
* @author Henning Treu - Delete orphan exclusive configuration from configAdmin
|
* @author Henning Treu - Delete orphan exclusive configuration from configAdmin
|
||||||
@ -116,10 +116,15 @@ public class ConfigDispatcher {
|
|||||||
|
|
||||||
private ExclusivePIDMap exclusivePIDMap;
|
private ExclusivePIDMap exclusivePIDMap;
|
||||||
|
|
||||||
private ConfigurationAdmin configAdmin;
|
private final ConfigurationAdmin configAdmin;
|
||||||
|
|
||||||
private File exclusivePIDStore;
|
private File exclusivePIDStore;
|
||||||
|
|
||||||
|
@Activate
|
||||||
|
public ConfigDispatcher(final @Reference ConfigurationAdmin configAdmin) {
|
||||||
|
this.configAdmin = configAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
@Activate
|
@Activate
|
||||||
public void activate(BundleContext bundleContext) {
|
public void activate(BundleContext bundleContext) {
|
||||||
exclusivePIDStore = bundleContext.getDataFile(EXCLUSIVE_PID_STORE_FILE);
|
exclusivePIDStore = bundleContext.getDataFile(EXCLUSIVE_PID_STORE_FILE);
|
||||||
@ -431,15 +436,6 @@ public class ConfigDispatcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Reference
|
|
||||||
public void setConfigurationAdmin(ConfigurationAdmin configAdmin) {
|
|
||||||
this.configAdmin = configAdmin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unsetConfigurationAdmin(ConfigurationAdmin configAdmin) {
|
|
||||||
this.configAdmin = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a result of parseLine().
|
* Represents a result of parseLine().
|
||||||
*/
|
*/
|
||||||
|
@ -29,9 +29,8 @@ import org.osgi.service.component.annotations.Reference;
|
|||||||
/**
|
/**
|
||||||
* Watches file-system events and passes them to our {@link ConfigDispatcher}
|
* Watches file-system events and passes them to our {@link ConfigDispatcher}
|
||||||
*
|
*
|
||||||
* @author Kai Kreuzer - Initial contribution and API
|
* @author Kai Kreuzer - Initial contribution
|
||||||
* @author Stefan Triller - factored out this code from {@link ConfigDispatcher}
|
* @author Stefan Triller - factored out this code from {@link ConfigDispatcher}
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Component(immediate = true)
|
@Component(immediate = true)
|
||||||
public class ConfigDispatcherFileWatcher extends AbstractWatchService {
|
public class ConfigDispatcherFileWatcher extends AbstractWatchService {
|
||||||
@ -42,10 +41,12 @@ public class ConfigDispatcherFileWatcher extends AbstractWatchService {
|
|||||||
/** The default folder name of the configuration folder of services */
|
/** The default folder name of the configuration folder of services */
|
||||||
public static final String SERVICES_FOLDER = "services";
|
public static final String SERVICES_FOLDER = "services";
|
||||||
|
|
||||||
private ConfigDispatcher configDispatcher;
|
private final ConfigDispatcher configDispatcher;
|
||||||
|
|
||||||
public ConfigDispatcherFileWatcher() {
|
@Activate
|
||||||
|
public ConfigDispatcherFileWatcher(final @Reference ConfigDispatcher configDispatcher) {
|
||||||
super(getPathToWatch());
|
super(getPathToWatch());
|
||||||
|
this.configDispatcher = configDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getPathToWatch() {
|
private static String getPathToWatch() {
|
||||||
@ -57,8 +58,8 @@ public class ConfigDispatcherFileWatcher extends AbstractWatchService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Activate
|
@Activate
|
||||||
|
@Override
|
||||||
public void activate() {
|
public void activate() {
|
||||||
super.activate();
|
super.activate();
|
||||||
configDispatcher.processConfigFile(getSourcePath().toFile());
|
configDispatcher.processConfigFile(getSourcePath().toFile());
|
||||||
@ -98,13 +99,4 @@ public class ConfigDispatcherFileWatcher extends AbstractWatchService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Reference
|
|
||||||
public void setConfigDispatcher(ConfigDispatcher configDispatcher) {
|
|
||||||
this.configDispatcher = configDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unsetConfigDispatcher(ConfigDispatcher configDispatcher) {
|
|
||||||
this.configDispatcher = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,7 @@ public class ConfigDispatcherFileWatcherTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
initMocks(this);
|
initMocks(this);
|
||||||
|
|
||||||
configDispatcherFileWatcher = new TestConfigDispatcherFileWatcher();
|
configDispatcherFileWatcher = new TestConfigDispatcherFileWatcher(configDispatcher);
|
||||||
configDispatcherFileWatcher.setConfigDispatcher(configDispatcher);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -97,6 +96,9 @@ public class ConfigDispatcherFileWatcherTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class TestConfigDispatcherFileWatcher extends ConfigDispatcherFileWatcher {
|
public class TestConfigDispatcherFileWatcher extends ConfigDispatcherFileWatcher {
|
||||||
|
public TestConfigDispatcherFileWatcher(ConfigDispatcher configDispatcher) {
|
||||||
|
super(configDispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void processWatchEvent(WatchEvent<?> event, Kind<?> kind, Path path) {
|
protected void processWatchEvent(WatchEvent<?> event, Kind<?> kind, Path path) {
|
||||||
|
@ -69,8 +69,7 @@ public class ConfigDispatcherOSGiTest extends JavaOSGiTest {
|
|||||||
configAdmin = getService(ConfigurationAdmin.class);
|
configAdmin = getService(ConfigurationAdmin.class);
|
||||||
assertThat(configAdmin, is(notNullValue()));
|
assertThat(configAdmin, is(notNullValue()));
|
||||||
|
|
||||||
cd = new ConfigDispatcher();
|
cd = new ConfigDispatcher(configAdmin);
|
||||||
cd.setConfigurationAdmin(configAdmin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
|
Loading…
Reference in New Issue
Block a user