private DeviceEvent createPort(Device device, Port newPort, Map<PortNumber, Port> ports) { ports.put(newPort.number(), newPort); return new DeviceEvent(PORT_ADDED, device, newPort); }
private List<DeviceEvent> pruneOldPorts(Device device, Map<PortNumber, Port> ports, Set<PortNumber> processed) { List<DeviceEvent> events = new ArrayList<>(); Iterator<Entry<PortNumber, Port>> iterator = ports.entrySet().iterator(); while (iterator.hasNext()) { Entry<PortNumber, Port> e = iterator.next(); PortNumber portNumber = e.getKey(); if (!processed.contains(portNumber)) { events.add(new DeviceEvent(PORT_REMOVED, device, e.getValue())); iterator.remove(); } } return events; }
@Override public DeviceEvent removeDevice(DeviceId deviceId) { Map<ProviderId, DeviceDescriptions> descs = getOrCreateDeviceDescriptions(deviceId); synchronized (descs) { Device device = devices.remove(deviceId); // should DEVICE_REMOVED carry removed ports? Map<PortNumber, Port> ports = devicePorts.get(deviceId); if (ports != null) { ports.clear(); } availableDevices.remove(deviceId); descs.clear(); return device == null ? null : new DeviceEvent(DEVICE_REMOVED, device, null); } }
@Override public DeviceEvent markOffline(DeviceId deviceId) { Map<ProviderId, DeviceDescriptions> providerDescs = getOrCreateDeviceDescriptions(deviceId); // locking device synchronized (providerDescs) { Device device = devices.get(deviceId); if (device == null) { return null; } boolean removed = availableDevices.remove(deviceId); if (removed) { // TODO: broadcast ... DOWN only? return new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, device, null); } return null; } }
@Override public DeviceEvent updatePortStatistics(ProviderId providerId, DeviceId deviceId, Collection<PortStatistics> portStats) { ConcurrentMap<PortNumber, PortStatistics> statsMap = devicePortStats.get(deviceId); if (statsMap == null) { statsMap = Maps.newConcurrentMap(); devicePortStats.put(deviceId, statsMap); } for (PortStatistics stat: portStats) { PortNumber portNumber = PortNumber.portNumber(stat.port()); statsMap.put(portNumber, stat); } return new DeviceEvent(PORT_STATS_UPDATED, devices.get(deviceId), null); }
private DeviceEvent createDevice(ProviderId providerId, Device newDevice) { // update composed device cache Device oldDevice = devices.putIfAbsent(newDevice.id(), newDevice); verify(oldDevice == null, "Unexpected Device in cache. PID:%s [old=%s, new=%s]", providerId, oldDevice, newDevice); if (!providerId.isAncillary()) { availableDevices.add(newDevice.id()); } return new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, newDevice, null); }
availableDevices.add(newDevice.id()); return new DeviceEvent(DeviceEvent.Type.DEVICE_UPDATED, newDevice, null); boolean added = availableDevices.add(newDevice.id()); return !added ? null : new DeviceEvent(DEVICE_AVAILABILITY_CHANGED, newDevice, null);
/** * Transform Port instance on the event to Optical specific port, if it is well-formed. * * @param event original event to transform * @return transformed {@link DeviceEvent} */ public DeviceEvent augment(DeviceEvent event) { final Port port = augment(event.port()); if (port == event.port()) { // If the Port not changed, pass through return event; } return new DeviceEvent(event.type(), event.subject(), port, event.time()); }
private DeviceEvent updatePort(Device device, Port oldPort, Port newPort, Map<PortNumber, Port> ports) { if (oldPort.isEnabled() != newPort.isEnabled() || oldPort.type() != newPort.type() || oldPort.portSpeed() != newPort.portSpeed() || !AnnotationsUtil.isEqual(oldPort.annotations(), newPort.annotations())) { ports.put(oldPort.number(), newPort); return new DeviceEvent(PORT_UPDATED, device, newPort); } return null; }