@Override public ExtensionCriterion read(Kryo kryo, Input input, Class<ExtensionCriterion> type) { ExtensionSelectorType exType = (ExtensionSelectorType) kryo.readClassAndObject(input); DeviceId deviceId = (DeviceId) kryo.readClassAndObject(input); DriverService driverService = DefaultServiceDirectory.getService(DriverService.class); byte[] bytes = (byte[]) kryo.readClassAndObject(input); ExtensionSelector selector; try { DriverHandler handler = new DefaultDriverHandler( new DefaultDriverData(driverService.getDriver(deviceId), deviceId)); ExtensionSelectorResolver resolver = handler.behaviour(ExtensionSelectorResolver.class); selector = resolver.getExtensionSelector(exType); selector.deserialize(bytes); } catch (ItemNotFoundException | IllegalArgumentException e) { selector = new UnresolvedExtensionSelector(bytes, exType); } return Criteria.extension(selector, deviceId); }
private void connectDevices() { RestProviderConfig cfg = cfgService.getConfig(appId, RestProviderConfig.class); try { if (cfg != null && cfg.getDevicesAddresses() != null) { // Precomputing the devices to be removed Set<RestSBDevice> toBeRemoved = new HashSet<>(controller.getDevices().values()); toBeRemoved.removeAll(cfg.getDevicesAddresses()); // Adding new devices cfg.getDevicesAddresses() .stream() .filter(device -> testDeviceConnection(device)) .forEach( device -> { deviceAdded(device); }); // Removing devices not wanted anymore toBeRemoved.stream().forEach(device -> deviceRemoved(device)); } } catch (ConfigException e) { log.error("Configuration error {}", e); } log.info("REST Devices {}", controller.getDevices()); controller .getDevices() .keySet() .forEach( deviceId -> { DriverHandler h = driverService.createHandler(deviceId); PortDiscovery portConfig = h.behaviour(PortDiscovery.class); if (portConfig != null) { providerService.updatePorts(deviceId, portConfig.getPorts()); } else { log.warn("No portGetter behaviour for device {}", deviceId); } }); }