@Test public void testDAAdvertOnBoot() throws Exception { final AtomicInteger daAdvertCount = new AtomicInteger(0); final AtomicBoolean failure = new AtomicBoolean(false); MessageListener listener = new MessageListener() { public void handle(MessageEvent event) { try { Message message = event.getMessage(); if (message.getMessageType() != Message.DA_ADVERT_TYPE) assert false; daAdvertCount.incrementAndGet(); DAAdvert daAdvert = (DAAdvert)message; assert daAdvert.getSLPError() == SLPError.NO_ERROR; assert daAdvert.isMulticast(); DirectoryAgentInfo directoryAgent = DirectoryAgentInfo.from(daAdvert); assert !directoryAgent.isShuttingDown(); assert directoryAgent.getURL().startsWith(DirectoryAgentInfo.SERVICE_TYPE.asString()); assert directoryAgent.getHostAddress() != null; assert directoryAgent.getHostAddress().trim().length() > 0; } catch (Throwable x) { failure.set(true); } } }; Settings udpSettings = newSettings(); UDPConnectorServer.Factory udpServerFactory = Factories.newInstance(udpSettings, UDP_CONNECTOR_SERVER_FACTORY_KEY); UDPConnectorServer udpConnectorServer = udpServerFactory.newUDPConnectorServer(udpSettings); udpConnectorServer.start(); udpConnectorServer.addMessageListener(listener); try { StandardDirectoryAgentServer da = StandardDirectoryAgentServer.newInstance(newSettings()); da.start(); try { Thread.sleep(500); udpConnectorServer.removeMessageListener(listener); } finally { da.stop(); } assert daAdvertCount.get() == 1; assert !failure.get(); } finally { udpConnectorServer.stop(); } }
public static StandardDirectoryAgentServer newInstance(Settings settings) { UDPConnector udpConnector = Factories.<UDPConnector.Factory>newInstance(settings, UDP_CONNECTOR_FACTORY_KEY).newUDPConnector(settings); TCPConnector tcpConnector = Factories.<TCPConnector.Factory>newInstance(settings, TCP_CONNECTOR_FACTORY_KEY).newTCPConnector(settings); UDPConnectorServer udpConnectorServer = Factories.<UDPConnectorServer.Factory>newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY).newUDPConnectorServer(settings); TCPConnectorServer tcpConnectorServer = Factories.<TCPConnectorServer.Factory>newInstance(settings, TCP_CONNECTOR_SERVER_FACTORY_KEY).newTCPConnectorServer(settings); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); return new StandardDirectoryAgentServer(udpConnector, tcpConnector, udpConnectorServer, tcpConnectorServer, scheduledExecutorService, settings); }
StandardDirectoryAgentServer extends AbstractServer { public static StandardDirectoryAgentServer newInstance(Settings settings) { UDPConnector udpConnector = Factories.<UDPConnector.Factory>newInstance(settings, UDP_CONNECTOR_FACTORY_KEY).newUDPConnector(settings); TCPConnector tcpConnector = Factories.<TCPConnector.Factory>newInstance(settings, TCP_CONNECTOR_FACTORY_KEY).newTCPConnector(settings); UDPConnectorServer udpConnectorServer = Factories.<UDPConnectorServer.Factory>newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY).newUDPConnectorServer(settings); TCPConnectorServer tcpConnectorServer = Factories.<TCPConnectorServer.Factory>newInstance(settings, TCP_CONNECTOR_SERVER_FACTORY_KEY).newTCPConnectorServer(settings); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); return new StandardDirectoryAgentServer(udpConnector, tcpConnector, udpConnectorServer, tcpConnectorServer, scheduledExecutorService, settings); } }
StandardDirectoryAgentServer extends AbstractServer { public static StandardDirectoryAgentServer newInstance(Settings settings) { UDPConnector udpConnector = Factories.<UDPConnector.Factory>newInstance(settings, UDP_CONNECTOR_FACTORY_KEY).newUDPConnector(settings); TCPConnector tcpConnector = Factories.<TCPConnector.Factory>newInstance(settings, TCP_CONNECTOR_FACTORY_KEY).newTCPConnector(settings); UDPConnectorServer udpConnectorServer = Factories.<UDPConnectorServer.Factory>newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY).newUDPConnectorServer(settings); TCPConnectorServer tcpConnectorServer = Factories.<TCPConnectorServer.Factory>newInstance(settings, TCP_CONNECTOR_SERVER_FACTORY_KEY).newTCPConnectorServer(settings); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); return new StandardDirectoryAgentServer(udpConnector, tcpConnector, udpConnectorServer, tcpConnectorServer, scheduledExecutorService, settings); } StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService);  StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService, Settings settings); }
StandardDirectoryAgentServer extends AbstractServer { public static StandardDirectoryAgentServer newInstance(Settings settings) { UDPConnector udpConnector = Factories.<UDPConnector.Factory>newInstance(settings, UDP_CONNECTOR_FACTORY_KEY).newUDPConnector(settings); TCPConnector tcpConnector = Factories.<TCPConnector.Factory>newInstance(settings, TCP_CONNECTOR_FACTORY_KEY).newTCPConnector(settings); UDPConnectorServer udpConnectorServer = Factories.<UDPConnectorServer.Factory>newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY).newUDPConnectorServer(settings); TCPConnectorServer tcpConnectorServer = Factories.<TCPConnectorServer.Factory>newInstance(settings, TCP_CONNECTOR_SERVER_FACTORY_KEY).newTCPConnectorServer(settings); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); return new StandardDirectoryAgentServer(udpConnector, tcpConnector, udpConnectorServer, tcpConnectorServer, scheduledExecutorService, settings); } StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService);  StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService, Settings settings); static void main(String[] args); static StandardDirectoryAgentServer newInstance(Settings settings); String[] getAddresses(); void setAddresses(String[] addresses); int getPort(); void setPort(int port); Scopes getScopes(); void setScopes(Scopes scopes); Attributes getAttributes(); void setAttributes(Attributes attributes); String getLanguage(); void setLanguage(String language); int getAdvertisementPeriod(); void setAdvertisementPeriod(int advertisementPeriod); int getExpiredServicesPurgePeriod(); void setExpiredServicesPurgePeriod(int expiredServicesPurgePeriod); void addServiceListener(ServiceListener listener); void removeServiceListener(ServiceListener listener); List<ServiceInfo> getServices(); }
StandardDirectoryAgentServer extends AbstractServer { public static StandardDirectoryAgentServer newInstance(Settings settings) { UDPConnector udpConnector = Factories.<UDPConnector.Factory>newInstance(settings, UDP_CONNECTOR_FACTORY_KEY).newUDPConnector(settings); TCPConnector tcpConnector = Factories.<TCPConnector.Factory>newInstance(settings, TCP_CONNECTOR_FACTORY_KEY).newTCPConnector(settings); UDPConnectorServer udpConnectorServer = Factories.<UDPConnectorServer.Factory>newInstance(settings, UDP_CONNECTOR_SERVER_FACTORY_KEY).newUDPConnectorServer(settings); TCPConnectorServer tcpConnectorServer = Factories.<TCPConnectorServer.Factory>newInstance(settings, TCP_CONNECTOR_SERVER_FACTORY_KEY).newTCPConnectorServer(settings); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); return new StandardDirectoryAgentServer(udpConnector, tcpConnector, udpConnectorServer, tcpConnectorServer, scheduledExecutorService, settings); } StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService);  StandardDirectoryAgentServer(UDPConnector udpConnector, TCPConnector tcpConnector, UDPConnectorServer udpConnectorServer, TCPConnectorServer tcpConnectorServer, ScheduledExecutorService scheduledExecutorService, Settings settings); static void main(String[] args); static StandardDirectoryAgentServer newInstance(Settings settings); String[] getAddresses(); void setAddresses(String[] addresses); int getPort(); void setPort(int port); Scopes getScopes(); void setScopes(Scopes scopes); Attributes getAttributes(); void setAttributes(Attributes attributes); String getLanguage(); void setLanguage(String language); int getAdvertisementPeriod(); void setAdvertisementPeriod(int advertisementPeriod); int getExpiredServicesPurgePeriod(); void setExpiredServicesPurgePeriod(int expiredServicesPurgePeriod); void addServiceListener(ServiceListener listener); void removeServiceListener(ServiceListener listener); List<ServiceInfo> getServices();  }