ServiceDiscoveryReader(final DiscoveryClientConfig discoveryConfig, final ObjectMapper objectMapper, final StateOfTheWorldHolder stateHolder) { super(discoveryConfig, objectMapper); this.stateHolder = stateHolder; this.penaltyTime = discoveryConfig.getPenaltyTime().getMillis() * 1000000L; }
ServiceDiscoveryRunnable(final String connectString, final DiscoveryClientConfig discoveryConfig, @Nonnull final Set<ServiceDiscoveryTask> visitors) { super(connectString, discoveryConfig.getTickInterval().getMillis()); this.visitors = visitors; this.scanTicks = discoveryConfig.getScanInterval().getMillis() / discoveryConfig.getTickInterval().getMillis(); this.discoveryRoot = discoveryConfig.getRoot(); LOG.info("Scan Ticks is %d (Tick interval is %dms)", scanTicks, discoveryConfig.getTickInterval().getMillis()); }
@Inject public ReadOnlyDiscoveryClientImpl(@Named(DiscoveryClientModule.ZOOKEEPER_CONNECT_NAME) final String connectString, final DiscoveryClientConfig discoveryConfig, final ObjectMapper objectMapper) { super(discoveryConfig.isEnabled()); if (discoveryConfig.isEnabled()) { Preconditions.checkState(!StringUtils.isBlank(connectString), "no zookeeper server configured!"); } this.connectString = connectString; this.discoveryConfig = discoveryConfig; serviceDiscoveryVisitors.add(new ServiceDiscoveryReader(discoveryConfig, objectMapper, getStateOfTheWorldHolder())); }
public synchronized void stop() { if (discoveryConfig.isEnabled()) { if (discoveryThread == null) { LOG.warn("Client was never started!"); } else { discoveryThread.interrupt(); try { discoveryThread.join(discoveryConfig.getZookeeperTimeout().getMillis()); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } LOG.info("Stopped Discovery client"); } } } }
public synchronized void start() if (!discoveryConfig.isEnabled()) { LOG.info("Discovery service is disabled."); try { if (waitForWorldChange(discoveryConfig.getWorldChangeTimeout().getMillis(), TimeUnit.MILLISECONDS)) { LOG.debug("World just changed!");
protected final String getNodePath(final String nodeName) { return discoveryConfig.getRoot() + "/" + nodeName; }
@Inject public DiscoveryClientImpl(@Named(DiscoveryClientModule.ZOOKEEPER_CONNECT_NAME) final String connectString, final DiscoveryClientConfig discoveryConfig, final ObjectMapper objectMapper) { super(connectString, discoveryConfig, objectMapper); announcer = new ServiceDiscoveryAnnouncer(discoveryConfig, objectMapper); if (discoveryConfig.isAnnounceEnabled()) { serviceDiscoveryVisitors.add(announcer); } else { LOG.info("Service announcement is administratively disabled!"); } }
@Inject public ZookeeperJobProcessor(@Named(DiscoveryClientModule.ZOOKEEPER_CONNECT_NAME) final String connectString, final DiscoveryClientConfig discoveryClientConfig) { this.processingThread = new Thread(new JobProcessingRunnable(connectString, discoveryClientConfig.getTickInterval().getMillis())); this.processingThread.setName("zookeeper-job-processor"); this.processingThread.setDaemon(true); }
if (!latch.await(discoveryConfig.getZookeeperTimeout().getMillis(), TimeUnit.MILLISECONDS)) { LOG.warn("Timeout waiting for callbacks, some nodes were not parsed.");
@Provides @Singleton @Named(ZOOKEEPER_CONNECT_NAME) String getConnectString(@Named(ZOOKEEPER_CONNECT_NAME) final Map<Integer, InetSocketAddress> zookeeperServers, final DiscoveryClientConfig clientConfig) { final StringBuilder sb = new StringBuilder(); for (final InetSocketAddress address : zookeeperServers.values()) { if (sb.length() > 0) { sb.append(','); } sb.append(address.getAddress().getHostAddress()).append(':').append(address.getPort()); } if (sb.length() == 0) { if (clientConfig.isEnabled()) { throw new IllegalStateException("Service discovery is enabled but no servers found!"); } else { LOG.info("No servers found!"); } } return sb.toString(); }
if (!clientConfig.isEnabled()) { LOG.warn("Service Discovery is administratively disabled.");
if (!discoveryClientConfig.isEnabled()) { throw new ServiceNotAvailableException("Service discovery is disabled!");