public void run() { try { running = true; // This is to disable the set of URL URLStreamHandlerFactory // inside StreamClientImpl. Now handled with new coded added to // azureus core. System.setProperty(HACK_STREAM_HANDLER_SYSTEM_PROPERTY, "alreadyWorkedAroundTheEvilJDK"); service = new UpnpServiceImpl(new DesktopUpnpServiceConfiguration()) { @Override protected ProtocolFactory createProtocolFactory() { return new ProtocolFactoryImpl(this) { @Override protected ReceivingAsync<?> createReceivingSearch( IncomingDatagramMessage<UpnpRequest> incomingRequest) { return new ReceivingSearch(getUpnpService(), incomingRequest) { @Override protected List<OutgoingSearchResponse> createServiceTypeMessages( LocalDevice device, NetworkAddress activeStreamServer) { List<OutgoingSearchResponse> result = Collections.emptyList(); try { result = super.createServiceTypeMessages(device, activeStreamServer); } catch (Throwable e) { } return result; } }; } }; } }; Runtime.getRuntime() .addShutdownHook( new Thread() { @Override public void run() { running = false; service.shutdown(); } }); if (LibrarySettings.LIBRARY_WIFI_SHARING_ENABLED.getValue()) { this.service.getRegistry().addDevice(getLocalDevice()); // refresh the list with all known devices for (Device<?, ?, ?> device : this.service.getRegistry().getDevices()) { registryListener.deviceAdded(device); } // getting ready for future device advertisements this.service.getRegistry().addListener(registryListener); } while (running) { Thread.sleep(10000); if (LibrarySettings.LIBRARY_WIFI_SHARING_ENABLED.getValue()) { this.service.getControlPoint().search(); } } } catch (Throwable e) { LOG.log(Level.WARNING, "Exception occured with the UPnP framework", e); } }
protected void assertUPnPActive() throws IOException { if (!LibrarySettings.LIBRARY_WIFI_SHARING_ENABLED.getValue()) { throw new IOException("UPnP deactivated"); } }