Use constructor injection (#1212)
Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>pull/1219/head
parent
403b55c8fc
commit
d23fb59ed7
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -48,7 +48,9 @@ import org.jupnp.model.types.UDAServiceId;
|
||||||
import org.jupnp.model.types.UDN;
|
import org.jupnp.model.types.UDN;
|
||||||
import org.jupnp.registry.Registry;
|
import org.jupnp.registry.Registry;
|
||||||
import org.jupnp.registry.RegistryListener;
|
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.Component;
|
||||||
|
import org.osgi.service.component.annotations.Deactivate;
|
||||||
import org.osgi.service.component.annotations.Reference;
|
import org.osgi.service.component.annotations.Reference;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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 int DEFAULT_POLLING_INTERVAL = 60;
|
||||||
private static final String POOL_NAME = "upnp-io";
|
private static final String POOL_NAME = "upnp-io";
|
||||||
|
|
||||||
private UpnpService upnpService;
|
private final UpnpService upnpService;
|
||||||
|
|
||||||
final Set<UpnpIOParticipant> participants = new CopyOnWriteArraySet<>();
|
final Set<UpnpIOParticipant> participants = new CopyOnWriteArraySet<>();
|
||||||
final Map<UpnpIOParticipant, ScheduledFuture> pollingJobs = new ConcurrentHashMap<>();
|
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() {
|
public void activate() {
|
||||||
logger.debug("Starting UPnP IO service...");
|
logger.debug("Starting UPnP IO service...");
|
||||||
upnpService.getRegistry().getRemoteDevices().forEach(device -> informParticipants(device, true));
|
upnpService.getRegistry().getRemoteDevices().forEach(device -> informParticipants(device, true));
|
||||||
upnpService.getRegistry().addListener(this);
|
upnpService.getRegistry().addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deactivate
|
||||||
public void deactivate() {
|
public void deactivate() {
|
||||||
logger.debug("Stopping UPnP IO service...");
|
logger.debug("Stopping UPnP IO service...");
|
||||||
upnpService.getRegistry().removeListener(this);
|
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) {
|
private Device getDevice(UpnpIOParticipant participant) {
|
||||||
return upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true);
|
return upnpService.getRegistry().getDevice(new UDN(participant.getUDN()), true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,8 +85,7 @@ public class UpnpIOServiceTest {
|
||||||
when(upnpServiceMock.getRegistry()).thenReturn(upnpRegistry);
|
when(upnpServiceMock.getRegistry()).thenReturn(upnpRegistry);
|
||||||
when(upnpServiceMock.getControlPoint()).thenReturn(controlPoint);
|
when(upnpServiceMock.getControlPoint()).thenReturn(controlPoint);
|
||||||
|
|
||||||
upnpIoService = new UpnpIOServiceImpl();
|
upnpIoService = new UpnpIOServiceImpl(upnpServiceMock);
|
||||||
upnpIoService.setUpnpService(upnpServiceMock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue