@Test public final void testClose() throws Exception { final String localAddress = localAddressProvider.getLocalAddress(); final IdentifierFactory factory = new StringIdentifierFactory(); final Injector injector = Tang.Factory.getTang().newInjector(); injector.bindVolatileParameter(NameServerParameters.NameServerIdentifierFactory.class, factory); injector.bindVolatileInstance(LocalAddressProvider.class, this.localAddressProvider); try (NameServer server = injector.getInstance(NameServer.class)) { final int serverPort = server.getPort(); final Configuration nameResolverConf = NameResolverConfiguration.CONF .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddress) .set(NameResolverConfiguration.NAME_SERVICE_PORT, serverPort) .set(NameResolverConfiguration.CACHE_TIMEOUT, 10000) .set(NameResolverConfiguration.RETRY_TIMEOUT, RETRY_TIMEOUT) .set(NameResolverConfiguration.RETRY_COUNT, RETRY_COUNT) .build(); try (NameResolver client = Tang.Factory.getTang().newInjector(nameResolverConf).getInstance(NameClient.class)) { final Identifier id = factory.getNewInstance("Task1"); client.register(id, new InetSocketAddress(localAddress, 7001)); client.unregister(id); Thread.sleep(100); } } }
@Override public void close() throws Exception { if (this.lookupClient != null) { this.lookupClient.close(); } if (this.registryClient != null) { this.registryClient.close(); } if (this.transport != null) { this.transport.close(); } }
NameClient implements NameResolver { @Override public void close() throws Exception { if (this.lookupClient != null) { this.lookupClient.close(); } if (this.registryClient != null) { this.registryClient.close(); } if (this.transport != null) { this.transport.close(); } } }
NameClient implements NameResolver { @Override public void close() throws Exception { if (this.lookupClient != null) { this.lookupClient.close(); } if (this.registryClient != null) { this.registryClient.close(); } if (this.transport != null) { this.transport.close(); } } @Inject private  NameClient(
      @Parameter(NameResolverNameServerAddr.class) final String serverAddr,
      @Parameter(NameResolverNameServerPort.class) final int serverPort,
      @Parameter(NameResolverCacheTimeout.class) final long timeout,
      @Parameter(NameResolverIdentifierFactory.class) final IdentifierFactory factory,
      @Parameter(NameResolverRetryCount.class) final int retryCount,
      @Parameter(NameResolverRetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory); }
NameClient implements NameResolver { @Override public void close() throws Exception { if (this.lookupClient != null) { this.lookupClient.close(); } if (this.registryClient != null) { this.registryClient.close(); } if (this.transport != null) { this.transport.close(); } } @Inject private  NameClient(
      @Parameter(NameResolverNameServerAddr.class) final String serverAddr,
      @Parameter(NameResolverNameServerPort.class) final int serverPort,
      @Parameter(NameResolverCacheTimeout.class) final long timeout,
      @Parameter(NameResolverIdentifierFactory.class) final IdentifierFactory factory,
      @Parameter(NameResolverRetryCount.class) final int retryCount,
      @Parameter(NameResolverRetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory); @Override void register(final Identifier id, final InetSocketAddress addr); @Override void unregister(final Identifier id); @Override InetSocketAddress lookup(final Identifier id); InetSocketAddress remoteLookup(final Identifier id); @Override void close(); }
NameClient implements NameResolver { @Override public void close() throws Exception { if (this.lookupClient != null) { this.lookupClient.close(); } if (this.registryClient != null) { this.registryClient.close(); } if (this.transport != null) { this.transport.close(); } } @Inject private  NameClient(
      @Parameter(NameResolverNameServerAddr.class) final String serverAddr,
      @Parameter(NameResolverNameServerPort.class) final int serverPort,
      @Parameter(NameResolverCacheTimeout.class) final long timeout,
      @Parameter(NameResolverIdentifierFactory.class) final IdentifierFactory factory,
      @Parameter(NameResolverRetryCount.class) final int retryCount,
      @Parameter(NameResolverRetryTimeout.class) final int retryTimeout,
      final LocalAddressProvider localAddressProvider,
      final TransportFactory tpFactory); @Override void register(final Identifier id, final InetSocketAddress addr); @Override void unregister(final Identifier id); @Override InetSocketAddress lookup(final Identifier id); InetSocketAddress remoteLookup(final Identifier id); @Override void close();  }