Skip to content

Commit

Permalink
Use constructor injection (#1212)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
  • Loading branch information
cweitkamp authored and wborn committed Nov 14, 2019
1 parent 403b55c commit d23fb59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion bundles/org.openhab.core.io.transport.upnp/pom.xml
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down
Expand Up @@ -48,7 +48,9 @@
import org.jupnp.model.types.UDN;
import org.jupnp.registry.Registry;
import org.jupnp.registry.RegistryListener;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -75,7 +77,7 @@ public class UpnpIOServiceImpl implements UpnpIOService, RegistryListener {
private static final int DEFAULT_POLLING_INTERVAL = 60;
private static final String POOL_NAME = "upnp-io";

private UpnpService upnpService;
private final UpnpService upnpService;

final Set<UpnpIOParticipant> participants = new CopyOnWriteArraySet<>();
final Map<UpnpIOParticipant, ScheduledFuture> pollingJobs = new ConcurrentHashMap<>();
Expand Down Expand Up @@ -194,26 +196,24 @@ protected void failed(GENASubscription subscription, UpnpResponse response, Exce
}
}

@Activate
public UpnpIOServiceImpl(final @Reference UpnpService upnpService) {
this.upnpService = upnpService;
}

@Activate
public void activate() {
logger.debug("Starting UPnP IO service...");
upnpService.getRegistry().getRemoteDevices().forEach(device -> informParticipants(device, true));
upnpService.getRegistry().addListener(this);
}

@Deactivate
public void deactivate() {
logger.debug("Stopping UPnP IO service...");
upnpService.getRegistry().removeListener(this);
}

@Reference
protected void setUpnpService(UpnpService upnpService) {
this.upnpService = upnpService;
}

protected void unsetUpnpService(UpnpService upnpService) {
this.upnpService = null;
}

private Device getDevice(UpnpIOParticipant participant) {
return upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true);
}
Expand Down
Expand Up @@ -85,8 +85,7 @@ public void setup() throws Exception {
when(upnpServiceMock.getRegistry()).thenReturn(upnpRegistry);
when(upnpServiceMock.getControlPoint()).thenReturn(controlPoint);

upnpIoService = new UpnpIOServiceImpl();
upnpIoService.setUpnpService(upnpServiceMock);
upnpIoService = new UpnpIOServiceImpl(upnpServiceMock);
}

@Test
Expand Down

0 comments on commit d23fb59

Please sign in to comment.