org.apache.reef.wake.IdentifierFactory Java Examples

The following examples show how to use org.apache.reef.wake.IdentifierFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RemoteIdentifierFactoryTest.java    From reef with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoteManagerIdentifier() throws Exception {
  final RemoteManagerFactory remoteManagerFactory = Tang.Factory.getTang().newInjector()
      .getInstance(RemoteManagerFactory.class);

  final Map<Class<?>, Codec<?>> clazzToCodecMap = new HashMap<>();
  clazzToCodecMap.put(TestEvent.class, new TestEventCodec());
  final Codec<?> codec = new MultiCodec<Object>(clazzToCodecMap);


  try (RemoteManager rm =
           remoteManagerFactory.getInstance("TestRemoteManager", 0, codec, new LoggingEventHandler<Throwable>())) {
    final RemoteIdentifier id = rm.getMyIdentifier();

    final IdentifierFactory factory = new DefaultIdentifierFactory();
    final Identifier newId = factory.getNewInstance(id.toString());

    Assert.assertEquals(id, newId);
  }
}
 
Example #2
Source File: NameRegistryClient.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a naming registry client.
 *
 * @param serverAddr a name server address
 * @param serverPort a name server port
 * @param timeout    timeout in ms
 * @param factory    an identifier factory
 */
NameRegistryClient(final String serverAddr,
                          final int serverPort,
                          final long timeout,
                          final IdentifierFactory factory,
                          final LocalAddressProvider localAddressProvider) {

  this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
  this.timeout = timeout;
  this.codec = NamingCodecFactory.createRegistryCodec(factory);
  this.replyQueue = new LinkedBlockingQueue<>();

  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, localAddressProvider.getLocalAddress());
  injector.bindVolatileParameter(RemoteConfiguration.RemoteClientStage.class,
      new SyncStage<>(new NamingRegistryClientHandler(new NamingRegistryResponseHandler(replyQueue), codec)));

  try {
    this.transport = injector.getInstance(NettyMessagingTransport.class);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #3
Source File: NameLookupClient.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a naming lookup client.
 *
 * @param serverAddr a server address
 * @param serverPort a server port number
 * @param timeout    request timeout in ms
 * @param factory    an identifier factory
 * @param retryCount a count of retrying lookup
 * @param retryTimeout retry timeout
 * @param replyQueue a reply queue
 * @param transport  a transport
 */
NameLookupClient(final String serverAddr,
                        final int serverPort,
                        final long timeout,
                        final IdentifierFactory factory,
                        final int retryCount,
                        final int retryTimeout,
                        final BlockingQueue<NamingLookupResponse> replyQueue,
                        final Transport transport) {
  this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
  this.timeout = timeout;
  this.cache = new NameCache(timeout);
  this.codec = NamingCodecFactory.createFullCodec(factory);
  this.replyQueue = replyQueue;
  this.retryCount = retryCount;
  this.retryTimeout = retryTimeout;
  this.transport = transport;
}
 
Example #4
Source File: NameLookupClient.java    From reef with Apache License 2.0 6 votes vote down vote up
/**
  * Constructs a naming lookup client.
  *
  * @param serverAddr a server address
  * @param serverPort a server port number
  * @param timeout    request timeout in ms
  * @param factory    an identifier factory
  * @param tpFactory  a transport factory
  */
@Inject
private NameLookupClient(
          @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) {
  this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
  this.timeout = timeout;
  this.cache = new NameCache(timeout);
  this.codec = NamingCodecFactory.createLookupCodec(factory);
  this.replyQueue = new LinkedBlockingQueue<>();

  this.transport = tpFactory.newInstance(localAddressProvider.getLocalAddress(), 0,
          new SyncStage<>(new NamingLookupClientHandler(
                  new NamingLookupResponseHandler(this.replyQueue), this.codec)),
          null, retryCount, retryTimeout);

  this.retryCount = retryCount;
  this.retryTimeout = retryTimeout;
}
 
Example #5
Source File: TopologySerializer.java    From reef with Apache License 2.0 6 votes vote down vote up
private static TopologySimpleNode decodeHelper(
    final DataInputStream dstream,
    final List<Identifier> activeSlaveTasks,
    final IdentifierFactory ifac) throws IOException {
  final String taskId = dstream.readUTF();
  activeSlaveTasks.add(ifac.getNewInstance(taskId));
  final TopologySimpleNode retNode = new TopologySimpleNode(taskId);

  final int children = dstream.readInt();
  for (int index = 0; index < children; index++) {
    final TopologySimpleNode child = decodeHelper(dstream, activeSlaveTasks, ifac);
    retNode.addChild(child);
  }

  return retNode;
}
 
Example #6
Source File: DataTransferTest.java    From nemo with Apache License 2.0 6 votes vote down vote up
private Injector createNameClientInjector() {
  try {
    final Configuration configuration = TANG.newConfigurationBuilder()
        .bindImplementation(IdentifierFactory.class, StringIdentifierFactory.class)
        .build();
    final Injector injector = TANG.newInjector(configuration);
    final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class);
    final NameServer nameServer = injector.getInstance(NameServer.class);
    final Configuration nameClientConfiguration = NameResolverConfiguration.CONF
        .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddressProvider.getLocalAddress())
        .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServer.getPort())
        .build();
    return injector.forkInjector(nameClientConfiguration);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #7
Source File: NcsMessageEnvironment.java    From nemo with Apache License 2.0 6 votes vote down vote up
@Inject
private NcsMessageEnvironment(
    final NetworkConnectionService networkConnectionService,
    final IdentifierFactory idFactory,
    @Parameter(MessageParameters.SenderId.class) final String senderId) {
  this.networkConnectionService = networkConnectionService;
  this.idFactory = idFactory;
  this.senderId = senderId;
  this.replyFutureMap = new ReplyFutureMap<>();
  this.listenerConcurrentMap = new ConcurrentHashMap<>();
  this.receiverToConnectionMap = new HashMap<>();
  this.connectionFactory = networkConnectionService.registerConnectionFactory(
      idFactory.getNewInstance(NCS_CONN_FACTORY_ID),
      new ControlMessageCodec(),
      new NcsMessageHandler(),
      new NcsLinkListener(),
      idFactory.getNewInstance(senderId));
}
 
Example #8
Source File: GrpcMessageEnvironment.java    From nemo with Apache License 2.0 6 votes vote down vote up
@Inject
private GrpcMessageEnvironment(
    final LocalAddressProvider localAddressProvider,
    final NameResolver nameResolver,
    final IdentifierFactory idFactory,
    @Parameter(MessageParameters.SenderId.class) final String localSenderId) {
  this.nameResolver = nameResolver;
  this.idFactory = idFactory;
  this.grpcServer = new GrpcMessageServer(localAddressProvider, nameResolver, idFactory, localSenderId);

  try {
    this.grpcServer.start();
  } catch (final Exception e) {
    LOG.warn("Failed to start grpc server", e);
    throw new RuntimeException(e);
  }
}
 
Example #9
Source File: DataTransferTest.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
private Injector createNameClientInjector() {
  try {
    final Configuration configuration = TANG.newConfigurationBuilder()
      .bindImplementation(IdentifierFactory.class, StringIdentifierFactory.class)
      .build();
    final Injector injector = TANG.newInjector(configuration);
    final LocalAddressProvider localAddressProvider = injector.getInstance(LocalAddressProvider.class);
    final NameServer nameServer = injector.getInstance(NameServer.class);
    final Configuration nameClientConfiguration = NameResolverConfiguration.CONF
      .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, localAddressProvider.getLocalAddress())
      .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServer.getPort())
      .build();
    return injector.forkInjector(nameClientConfiguration);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example #10
Source File: GrpcMessageEnvironment.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Inject
private GrpcMessageEnvironment(
  final LocalAddressProvider localAddressProvider,
  final NameResolver nameResolver,
  final IdentifierFactory idFactory,
  @Parameter(MessageParameters.SenderId.class) final String localSenderId) {
  this.nameResolver = nameResolver;
  this.idFactory = idFactory;
  this.grpcServer = new GrpcMessageServer(localAddressProvider, nameResolver, idFactory, localSenderId);
  this.localSenderId = localSenderId;

  try {
    this.grpcServer.start();
  } catch (final Exception e) {
    LOG.warn("Failed to start grpc server", e);
    throw new RuntimeException(e);
  }
}
 
Example #11
Source File: NcsMessageEnvironment.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Inject
private NcsMessageEnvironment(
  final NetworkConnectionService networkConnectionService,
  final IdentifierFactory idFactory,
  @Parameter(MessageParameters.SenderId.class) final String senderId) {
  this.networkConnectionService = networkConnectionService;
  this.idFactory = idFactory;
  this.senderId = senderId;
  this.replyFutureMap = new ReplyFutureMap<>();
  this.listenerConcurrentMap = new ConcurrentHashMap<>();
  this.receiverToConnectionMap = new ConcurrentHashMap<>();
  this.connectionFactory = networkConnectionService.registerConnectionFactory(
    idFactory.getNewInstance(NCS_CONN_FACTORY_ID),
    new ControlMessageCodec(),
    new NcsMessageHandler(),
    new NcsLinkListener(),
    idFactory.getNewInstance(senderId));
}
 
Example #12
Source File: UtilsTest.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Generic parseList test.
 */
@Test
public void testParseList() {
  final IdentifierFactory factory = new StringIdentifierFactory();

  final List<Identifier> list1 = Utils.parseList("1,2,3", factory);
  final List<ComparableIdentifier> list2 = Utils.parseList("1,2,3", factory);
}
 
Example #13
Source File: NameClient.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
   * Constructs a naming client.
   *
   * @param serverAddr a server address
   * @param serverPort a server port number
   * @param timeout timeout in ms
   * @param factory an identifier factory
   * @param retryCount the number of retries
   * @param retryTimeout retry timeout
   * @param localAddressProvider a local address provider
   * @param tpFactory transport factory
   */
@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) {

  final BlockingQueue<NamingLookupResponse> replyLookupQueue = new LinkedBlockingQueue<>();
  final BlockingQueue<NamingRegisterResponse> replyRegisterQueue = new LinkedBlockingQueue<>();
  final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory);

  this.transport = tpFactory.newInstance(localAddressProvider.getLocalAddress(), 0,
      new SyncStage<>(new NamingClientEventHandler(
          new NamingResponseHandler(replyLookupQueue, replyRegisterQueue), codec)),
      null, retryCount, retryTimeout);

  this.lookupClient = new NameLookupClient(serverAddr, serverPort, timeout, factory,
      retryCount, retryTimeout, replyLookupQueue, this.transport);

  this.registryClient = new NameRegistryClient(serverAddr, serverPort, timeout,
      factory, replyRegisterQueue, this.transport);
}
 
Example #14
Source File: NemoDriver.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
private Configuration getExecutorNcsConfiguration() {
  return Tang.Factory.getTang().newConfigurationBuilder()
    .bindNamedParameter(NameResolverNameServerPort.class, Integer.toString(nameServer.getPort()))
    .bindNamedParameter(NameResolverNameServerAddr.class, localAddressProvider.getLocalAddress())
    .bindImplementation(IdentifierFactory.class, StringIdentifierFactory.class)
    .build();
}
 
Example #15
Source File: NameRegistryClient.java    From reef with Apache License 2.0 5 votes vote down vote up
NameRegistryClient(final String serverAddr, final int serverPort,
                          final long timeout, final IdentifierFactory factory,
                          final BlockingQueue<NamingRegisterResponse> replyQueue,
                          final Transport transport) {
  this.serverSocketAddr = new InetSocketAddress(serverAddr, serverPort);
  this.timeout = timeout;
  this.codec = NamingCodecFactory.createFullCodec(factory);
  this.replyQueue = replyQueue;
  this.transport = transport;
}
 
Example #16
Source File: RemoteIdentifierFactoryTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoteIdentifierFactory() {
  System.out.println(LOG_PREFIX + name.getMethodName());

  final Map<String, Class<? extends Identifier>> typeToIdMap = new HashMap<>();
  typeToIdMap.put("test", TestRemoteIdentifier.class);
  final IdentifierFactory factory = new DefaultIdentifierFactory(typeToIdMap);

  final String idName = "test://name";
  final Identifier id = factory.getNewInstance(idName);
  System.out.println(id.toString());

  Assert.assertTrue(id instanceof TestRemoteIdentifier);
}
 
Example #17
Source File: NameServerImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param port    a listening port number
 * @param factory an identifier factory
 * @param localAddressProvider a local address provider
 * Constructs a name server
 */
@Inject
private NameServerImpl(
    @Parameter(RemoteConfiguration.HostAddress.class) final String hostAddress,
    @Parameter(NameServerParameters.NameServerPort.class) final int port,
    @Parameter(NameServerParameters.NameServerIdentifierFactory.class) final IdentifierFactory factory,
    final TcpPortProvider portProvider,
    final LocalAddressProvider localAddressProvider) {

  final Injector injector = Tang.Factory.getTang().newInjector();

  this.localAddressProvider = localAddressProvider;
  this.reefEventStateManager = null;
  final Codec<NamingMessage> codec = NamingCodecFactory.createFullCodec(factory);
  final EventHandler<NamingMessage> handler = createEventHandler(codec);

  String host = UNKNOWN_HOST_NAME.equals(hostAddress) ? localAddressProvider.getLocalAddress() : hostAddress;
  injector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, host);
  injector.bindVolatileParameter(RemoteConfiguration.Port.class, port);
  injector.bindVolatileInstance(TcpPortProvider.class, portProvider);
  injector.bindVolatileParameter(RemoteConfiguration.RemoteServerStage.class,
      new SyncStage<>(new NamingServerHandler(handler, codec)));

  try {
    this.transport = injector.getInstance(NettyMessagingTransport.class);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }

  this.port = transport.getListeningPort();
  this.idToAddrMap = Collections.synchronizedMap(new HashMap<Identifier, InetSocketAddress>());

  LOG.log(Level.FINE, "NameServer starting, listening at port {0}", this.port);
}
 
Example #18
Source File: BindNSToTask.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
public BindNSToTask(
    final NetworkService<?> ns,
    @Parameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class) final IdentifierFactory idFac) {
  this.ns = ns;
  this.idFac = idFac;
}
 
Example #19
Source File: UnbindNSFromTask.java    From reef with Apache License 2.0 5 votes vote down vote up
@Inject
public UnbindNSFromTask(
    final NetworkService<?> ns,
    @Parameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class) final IdentifierFactory idFac) {
  this.ns = ns;
  this.idFac = idFac;
}
 
Example #20
Source File: LocalNameResolverTest.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.apache.reef.io.network.naming.LocalNameResolverImpl#close()}.
 *
 * @throws Exception
 */
@Test
public final void testClose() throws Exception {
  final String localAddress = localAddressProvider.getLocalAddress();
  final IdentifierFactory factory = new StringIdentifierFactory();
  try (NameResolver resolver = Tang.Factory.getTang().newInjector(LocalNameResolverConfiguration.CONF
      .set(LocalNameResolverConfiguration.CACHE_TIMEOUT, 10000)
      .build()).getInstance(NameResolver.class)) {
    final Identifier id = factory.getNewInstance("Task1");
    resolver.register(id, new InetSocketAddress(localAddress, 7001));
    resolver.unregister(id);
    Thread.sleep(100);
  }
}
 
Example #21
Source File: NetworkConnectionServiceMessageCodec.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a network connection service message codec.
 */
NetworkConnectionServiceMessageCodec(
    final IdentifierFactory factory,
    final Map<String, NetworkConnectionFactory> connFactoryMap) {
  this.factory = factory;
  this.connFactoryMap = connFactoryMap;
  this.isStreamingCodecMap = new ConcurrentHashMap<>();
}
 
Example #22
Source File: TopologySerializerTest.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void testEncodeDecode() {
  final IdentifierFactory ifac = new StringIdentifierFactory();

  // create a topology: Task-0[Task-1[Task-3], Task-2]
  final TaskNode rootNode = new TaskNodeImpl(null, null, null, "Task-0", null, true);
  final TaskNode childNode1 = new TaskNodeImpl(null, null, null, "Task-1", null, false);
  final TaskNode childNode2 = new TaskNodeImpl(null, null, null, "Task-2", null, false);
  final TaskNode childNode3 = new TaskNodeImpl(null, null, null, "Task-3", null, false);
  rootNode.addChild(childNode1);
  rootNode.addChild(childNode2);
  childNode1.addChild(childNode3);

  final Pair<TopologySimpleNode, List<Identifier>> retPair =
      TopologySerializer.decode(TopologySerializer.encode(rootNode), ifac);

  // check topology is recovered
  assertEquals(retPair.getFirst().getTaskId(), "Task-0");
  for (final TopologySimpleNode child : retPair.getFirst().getChildren()) {
    if (child.getTaskId().equals("Task-1")) {
      for (final TopologySimpleNode childchild : child.getChildren()) {
        assertEquals(childchild.getTaskId(), "Task-3");
      }
    } else {
      assertTrue(child.getTaskId().equals("Task-2"));
    }
  }

  // check identifier list contains [Task-0, Task-1, Task-2, Task-3] and nothing else
  assertTrue(retPair.getSecond().contains(ifac.getNewInstance("Task-0")));
  assertTrue(retPair.getSecond().contains(ifac.getNewInstance("Task-1")));
  assertTrue(retPair.getSecond().contains(ifac.getNewInstance("Task-2")));
  assertTrue(retPair.getSecond().contains(ifac.getNewInstance("Task-3")));
  assertEquals(retPair.getSecond().size(), 4);
}
 
Example #23
Source File: LocalNameResolverTest.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.apache.reef.io.network.naming.LocalNameResolverImpl#lookup(Identifier id)}.
 * To check caching behavior with expireAfterAccess & expireAfterWrite
 * Changing NameCache's pattern to expireAfterAccess causes this test to fail
 *
 * @throws Exception
 */
@Test
public final void testLookup() throws Exception {
  final IdentifierFactory factory = new StringIdentifierFactory();
  final String localAddress = localAddressProvider.getLocalAddress();
  try (NameResolver resolver = Tang.Factory.getTang().newInjector(LocalNameResolverConfiguration.CONF
      .set(LocalNameResolverConfiguration.CACHE_TIMEOUT, 150)
      .build()).getInstance(NameResolver.class)) {
    final Identifier id = factory.getNewInstance("Task1");
    final InetSocketAddress socketAddr = new InetSocketAddress(localAddress, 7001);
    resolver.register(id, socketAddr);
    InetSocketAddress lookupAddr = resolver.lookup(id); // caches the entry
    Assert.assertTrue(socketAddr.equals(lookupAddr));
    resolver.unregister(id);
    Thread.sleep(100);
    try {
      lookupAddr = resolver.lookup(id);
      Thread.sleep(100);
      //With expireAfterAccess, the previous lookup would reset expiry to 150ms
      //more and 100ms wait will not expire the item and will return the cached value
      //With expireAfterWrite, the extra wait of 100 ms will expire the item
      //resulting in NamingException and the test passes
      lookupAddr = resolver.lookup(id);
      Assert.assertNull("resolver.lookup(id)", lookupAddr);
    } catch (final Exception e) {
      if (e instanceof ExecutionException) {
        Assert.assertTrue("Execution Exception cause is instanceof NamingException",
            e.getCause() instanceof NamingException);
      } else {
        throw e;
      }
    }
  }
}
 
Example #24
Source File: NetworkConnectionServiceTest.java    From reef with Apache License 2.0 5 votes vote down vote up
public NetworkConnectionServiceTest() throws InjectionException {
  localAddressProvider = Tang.Factory.getTang().newInjector().getInstance(LocalAddressProvider.class);
  localAddress = localAddressProvider.getLocalAddress();

  final IdentifierFactory idFac = new StringIdentifierFactory();
  this.groupCommClientId = idFac.getNewInstance("groupComm");
  this.shuffleClientId = idFac.getNewInstance("shuffle");
}
 
Example #25
Source File: NamingTest.java    From reef with Apache License 2.0 5 votes vote down vote up
private static NameLookupClient getNewNameLookupClient(final String serverAddr,
                                                       final int serverPort,
                                                       final long timeout,
                                                       final int retryCount,
                                                       final int retryTimeout,
                                                       final Optional<LocalAddressProvider> localAddressProvider,
                                                       final Optional<IdentifierFactory> factory)
    throws InjectionException {


  final Configuration injectorConf = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(NameResolverNameServerAddr.class, serverAddr)
      .bindNamedParameter(NameResolverNameServerPort.class, Integer.toString(serverPort))
      .bindNamedParameter(NameResolverCacheTimeout.class, Long.toString(timeout))
      .bindNamedParameter(NameResolverRetryCount.class, Integer.toString(retryCount))
      .bindNamedParameter(NameResolverRetryTimeout.class, Integer.toString(retryTimeout))
      .build();

  final Injector injector = Tang.Factory.getTang().newInjector(injectorConf);
  if (localAddressProvider.isPresent()) {
    injector.bindVolatileInstance(LocalAddressProvider.class, localAddressProvider.get());
  }

  if (factory.isPresent()) {
    injector.bindVolatileInstance(IdentifierFactory.class, factory.get());
  }

  return injector.getInstance(NameLookupClient.class);
}
 
Example #26
Source File: NameClientTest.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link org.apache.reef.io.network.naming.NameClient#close()}.
 *
 * @throws Exception
 */
@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);
    }
  }
}
 
Example #27
Source File: NcsMessageContext.java    From nemo with Apache License 2.0 5 votes vote down vote up
NcsMessageContext(final String senderId,
                  final ConnectionFactory connectionFactory,
                  final IdentifierFactory idFactory) {
  this.senderId = senderId;
  this.connectionFactory = connectionFactory;
  this.idFactory = idFactory;
}
 
Example #28
Source File: JobLauncher.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Get driver ncs configuration.
 *
 * @return driver ncs configuration.
 */
private static Configuration getDriverNcsConf() {
  return Configurations.merge(NameServerConfiguration.CONF.build(),
    LocalNameResolverConfiguration.CONF.build(),
    TANG.newConfigurationBuilder()
      .bindImplementation(IdentifierFactory.class, StringIdentifierFactory.class)
      .build());
}
 
Example #29
Source File: GrpcMessageClient.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param nameResolver name resolver.
 * @param idFactory    identifier factory.
 * @param receiverId   id of the receiver.
 */
GrpcMessageClient(final NameResolver nameResolver,
                  final IdentifierFactory idFactory,
                  final String receiverId) {
  this.nameResolver = nameResolver;
  this.idFactory = idFactory;
  this.receiverId = receiverId;
}
 
Example #30
Source File: GrpcMessageServer.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param localAddressProvider local address provider.
 * @param nameResolver         name resolver.
 * @param idFactory            identifier factory.
 * @param localSenderId        id of the local sender.
 */
GrpcMessageServer(final LocalAddressProvider localAddressProvider,
                  final NameResolver nameResolver,
                  final IdentifierFactory idFactory,
                  final String localSenderId) {
  this.localAddressProvider = localAddressProvider;
  this.nameResolver = nameResolver;
  this.idFactory = idFactory;
  this.localSenderId = localSenderId;
  this.listenerMap = new ConcurrentHashMap<>();
}