@Test public void testSetNotificationHandler() throws UnknownHostException { InetAddress address = InetAddress.getByName("localhost"); int port = 10213; Map<String,Object> incoming = new LinkedHashMap<>(); List<Object> l = new ArrayList<>(); l.add("localhost"); l.add("notValidAddress"); l.add(1354); incoming.put("receiveAddresses", l); l = new ArrayList<>(); l.add(port); l.add(-1); l.add(123456789); incoming.put("receivePorts", l); l = new ArrayList<>(); List<Object> subl = new ArrayList<>(); subl.add("invalid address"); subl.add(2000); l.add(subl); subl = new ArrayList<>(); subl.add("localhost"); subl.add(-1); l.add(subl); subl = new ArrayList<>(); subl.add(2000); subl.add("localhost"); l.add(subl); subl = new ArrayList<>(); subl.add("localhost"); subl.add(port); l.add(subl); incoming.put("receiveServers", l); UDPNotificationHandler handler = new UDPNotificationHandler(incoming, client); ConfigurableUDPSource.setNotificationHandler(handler, sourceName, incoming); assert ConfigurableUDPSource.notificationHandlers.get(sourceName) == handler; l = (List) ConfigurableUDPSource.sourcePorts.get(sourceName); assert l.contains(port); assert l.size() == 1; l = (List) ConfigurableUDPSource.sourceAddresses.get(sourceName); assert l.contains(address); assert l.size() == 1; subl = new ArrayList<>(); subl.add(address); subl.add(port); l = (List) ConfigurableUDPSource.sourceServers.get(sourceName); assert l.contains(subl); assert l.size() == 1; ConfigurableUDPSource.sourceServers.clear(); incoming = new LinkedHashMap<>(); incoming.put("receiveAllAddresses", true); incoming.put("receiveAllPorts", true); handler = new UDPNotificationHandler(incoming, client); ConfigurableUDPSource.setNotificationHandler(handler, sourceName, incoming); assert ConfigurableUDPSource.notificationHandlers.get(sourceName) == handler; String addr = (String) ConfigurableUDPSource.sourceAddresses.get(sourceName); assert addr.equals(ConfigurableUDPSource.ALL_ADDR); int prt = (Integer) ConfigurableUDPSource.sourcePorts.get(sourceName); assert prt == ConfigurableUDPSource.ALL_PORTS; incoming = new LinkedHashMap<>(); subl = new ArrayList<>(); subl.add("localhost"); subl.add(port); l.add(subl); incoming.put("receiveServers", l); handler = new UDPNotificationHandler(incoming, client); ConfigurableUDPSource.setNotificationHandler(handler, sourceName, incoming); assert ConfigurableUDPSource.notificationHandlers.get(sourceName) == handler; addr = (String) ConfigurableUDPSource.sourceAddresses.get(sourceName); assert addr.equals(ConfigurableUDPSource.NO_ADDR); prt = (Integer) ConfigurableUDPSource.sourcePorts.get(sourceName); assert prt == ConfigurableUDPSource.NO_PORTS; subl = new ArrayList<>(); subl.add(address); subl.add(port); l = (List) ConfigurableUDPSource.sourceServers.get(sourceName); assert l.contains(subl); assert l.size() == 1; }
public static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming) { log.trace("Setting Notification handler for '{}'", sourceName); notificationHandlers.put(sourceName, handler); List<InetAddress> addresses = null; List<Integer> ports = null; List<List> servers = null; if (incoming != null) { if (incoming.get("receiveAddresses") instanceof List) { addresses = getValidInetAddresses((List) incoming.get("receiveAddresses"), sourceName); } if (incoming.get("receivePorts") instanceof List) { ports = getValidPorts((List) incoming.get("receivePorts")); } if (incoming.get("receiveServers") instanceof List) { servers = getValidServers((List) incoming.get("receiveServers")); } } if (addresses != null) { sourceAddresses.put(sourceName, addresses); log.debug("Source '{}' listening for addresses {}", sourceName, addresses); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && ports == null) { sourceAddresses.put(sourceName, NO_ADDR); } else { sourceAddresses.put(sourceName, ALL_ADDR); log.debug("Source '{}' listening for all addresses", sourceName); } if (ports != null) { sourcePorts.put(sourceName, ports); log.debug("Source '{}' listening on ports {}", sourceName, ports); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && addresses == null) { sourcePorts.put(sourceName, NO_PORTS); } else { sourcePorts.put(sourceName, ALL_PORTS); log.debug("Source '{}' listening on all ports", sourceName); } if (servers != null) { sourceServers.put(sourceName, servers); } }
ConfigurableUDPSource { public static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming) { log.trace("Setting Notification handler for '{}'", sourceName); notificationHandlers.put(sourceName, handler); List<InetAddress> addresses = null; List<Integer> ports = null; List<List> servers = null; if (incoming != null) { if (incoming.get("receiveAddresses") instanceof List) { addresses = getValidInetAddresses((List) incoming.get("receiveAddresses"), sourceName); } if (incoming.get("receivePorts") instanceof List) { ports = getValidPorts((List) incoming.get("receivePorts")); } if (incoming.get("receiveServers") instanceof List) { servers = getValidServers((List) incoming.get("receiveServers")); } } if (addresses != null) { sourceAddresses.put(sourceName, addresses); log.debug("Source '{}' listening for addresses {}", sourceName, addresses); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && ports == null) { sourceAddresses.put(sourceName, NO_ADDR); } else { sourceAddresses.put(sourceName, ALL_ADDR); log.debug("Source '{}' listening for all addresses", sourceName); } if (ports != null) { sourcePorts.put(sourceName, ports); log.debug("Source '{}' listening on ports {}", sourceName, ports); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && addresses == null) { sourcePorts.put(sourceName, NO_PORTS); } else { sourcePorts.put(sourceName, ALL_PORTS); log.debug("Source '{}' listening on all ports", sourceName); } if (servers != null) { sourceServers.put(sourceName, servers); } } }
ConfigurableUDPSource { public static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming) { log.trace("Setting Notification handler for '{}'", sourceName); notificationHandlers.put(sourceName, handler); List<InetAddress> addresses = null; List<Integer> ports = null; List<List> servers = null; if (incoming != null) { if (incoming.get("receiveAddresses") instanceof List) { addresses = getValidInetAddresses((List) incoming.get("receiveAddresses"), sourceName); } if (incoming.get("receivePorts") instanceof List) { ports = getValidPorts((List) incoming.get("receivePorts")); } if (incoming.get("receiveServers") instanceof List) { servers = getValidServers((List) incoming.get("receiveServers")); } } if (addresses != null) { sourceAddresses.put(sourceName, addresses); log.debug("Source '{}' listening for addresses {}", sourceName, addresses); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && ports == null) { sourceAddresses.put(sourceName, NO_ADDR); } else { sourceAddresses.put(sourceName, ALL_ADDR); log.debug("Source '{}' listening for all addresses", sourceName); } if (ports != null) { sourcePorts.put(sourceName, ports); log.debug("Source '{}' listening on ports {}", sourceName, ports); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && addresses == null) { sourcePorts.put(sourceName, NO_PORTS); } else { sourcePorts.put(sourceName, ALL_PORTS); log.debug("Source '{}' listening on all ports", sourceName); } if (servers != null) { sourceServers.put(sourceName, servers); } }  }
ConfigurableUDPSource { public static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming) { log.trace("Setting Notification handler for '{}'", sourceName); notificationHandlers.put(sourceName, handler); List<InetAddress> addresses = null; List<Integer> ports = null; List<List> servers = null; if (incoming != null) { if (incoming.get("receiveAddresses") instanceof List) { addresses = getValidInetAddresses((List) incoming.get("receiveAddresses"), sourceName); } if (incoming.get("receivePorts") instanceof List) { ports = getValidPorts((List) incoming.get("receivePorts")); } if (incoming.get("receiveServers") instanceof List) { servers = getValidServers((List) incoming.get("receiveServers")); } } if (addresses != null) { sourceAddresses.put(sourceName, addresses); log.debug("Source '{}' listening for addresses {}", sourceName, addresses); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && ports == null) { sourceAddresses.put(sourceName, NO_ADDR); } else { sourceAddresses.put(sourceName, ALL_ADDR); log.debug("Source '{}' listening for all addresses", sourceName); } if (ports != null) { sourcePorts.put(sourceName, ports); log.debug("Source '{}' listening on ports {}", sourceName, ports); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && addresses == null) { sourcePorts.put(sourceName, NO_PORTS); } else { sourcePorts.put(sourceName, ALL_PORTS); log.debug("Source '{}' listening on all ports", sourceName); } if (servers != null) { sourceServers.put(sourceName, servers); } }  static DatagramSocket createUDPSocket(int port, InetAddress address, String sourceName); static DatagramSocket listenOnUDPSocket(int port, InetAddress address, String sourceName); static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming); static void main(String[] args); static void sendFromDatagram(DatagramPacket packet, List<String> sources); }
ConfigurableUDPSource { public static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming) { log.trace("Setting Notification handler for '{}'", sourceName); notificationHandlers.put(sourceName, handler); List<InetAddress> addresses = null; List<Integer> ports = null; List<List> servers = null; if (incoming != null) { if (incoming.get("receiveAddresses") instanceof List) { addresses = getValidInetAddresses((List) incoming.get("receiveAddresses"), sourceName); } if (incoming.get("receivePorts") instanceof List) { ports = getValidPorts((List) incoming.get("receivePorts")); } if (incoming.get("receiveServers") instanceof List) { servers = getValidServers((List) incoming.get("receiveServers")); } } if (addresses != null) { sourceAddresses.put(sourceName, addresses); log.debug("Source '{}' listening for addresses {}", sourceName, addresses); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && ports == null) { sourceAddresses.put(sourceName, NO_ADDR); } else { sourceAddresses.put(sourceName, ALL_ADDR); log.debug("Source '{}' listening for all addresses", sourceName); } if (ports != null) { sourcePorts.put(sourceName, ports); log.debug("Source '{}' listening on ports {}", sourceName, ports); } else if (servers != null && !valueIsTrue(incoming, "receiveAllAddresses") && !valueIsTrue(incoming, "receiveAllPorts") && addresses == null) { sourcePorts.put(sourceName, NO_PORTS); } else { sourcePorts.put(sourceName, ALL_PORTS); log.debug("Source '{}' listening on all ports", sourceName); } if (servers != null) { sourceServers.put(sourceName, servers); } }  static DatagramSocket createUDPSocket(int port, InetAddress address, String sourceName); static DatagramSocket listenOnUDPSocket(int port, InetAddress address, String sourceName); static void setNotificationHandler(UDPNotificationHandler handler, String sourceName, Map incoming); static void main(String[] args); static void sendFromDatagram(DatagramPacket packet, List<String> sources);  }