Use constructor injection (#1212)

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
pull/1219/head
Christoph Weitkamp 2019-11-14 20:58:47 +01:00 committed by Wouter Born
parent 403b55c8fc
commit d23fb59ed7
3 changed files with 13 additions and 13 deletions

View File

@ -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>

View File

@ -48,7 +48,9 @@ import org.jupnp.model.types.UDAServiceId;
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;
@ -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<>();
@ -194,26 +196,24 @@ public class UpnpIOServiceImpl implements UpnpIOService, RegistryListener {
}
}
@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);
}

View File

@ -85,8 +85,7 @@ public class UpnpIOServiceTest {
when(upnpServiceMock.getRegistry()).thenReturn(upnpRegistry);
when(upnpServiceMock.getControlPoint()).thenReturn(controlPoint);
upnpIoService = new UpnpIOServiceImpl();
upnpIoService.setUpnpService(upnpServiceMock);
upnpIoService = new UpnpIOServiceImpl(upnpServiceMock);
}
@Test