Java Code Examples for org.apache.reef.tang.Injector#getInstance()

The following examples show how to use org.apache.reef.tang.Injector#getInstance() . 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: NemoBackendTest.java    From nemo with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  this.dag = builder.addVertex(source).addVertex(map1).addVertex(groupByKey).addVertex(combine).addVertex(map2)
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.OneToOne, source, map1, Coder.DUMMY_CODER))
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.Shuffle,
          map1, groupByKey, Coder.DUMMY_CODER))
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.OneToOne,
          groupByKey, combine, Coder.DUMMY_CODER))
      .connectVertices(new IREdge(DataCommunicationPatternProperty.Value.OneToOne, combine, map2, Coder.DUMMY_CODER))
      .build();

  this.dag = CompiletimeOptimizer.optimize(dag, new PadoPolicy(), EMPTY_DAG_DIRECTORY);

  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(JobConf.DAGDirectory.class, "");
  this.physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class);
}
 
Example 2
Source File: PhysicalPlanGeneratorTest.java    From incubator-nemo with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasic() throws Exception {
  final Injector injector = Tang.Factory.getTang().newInjector();
  final PhysicalPlanGenerator physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class);

  final IRVertex v0 = newIRVertex(0, 5);
  final IRVertex v1 = newIRVertex(0, 3);
  final IRDAG irDAG = new IRDAG(new DAGBuilder<IRVertex, IREdge>()
    .addVertex(v0)
    .addVertex(v1)
    .connectVertices(newIREdge(v0, v1, CommunicationPatternProperty.Value.ONE_TO_ONE,
      DataFlowProperty.Value.PULL))
    .buildWithoutSourceSinkCheck());

  final DAG<Stage, StageEdge> stageDAG = physicalPlanGenerator.apply(irDAG);
  final Iterator<Stage> stages = stageDAG.getVertices().iterator();
  final Stage s0 = stages.next();
  final Stage s1 = stages.next();
}
 
Example 3
Source File: YarnLauncher.java    From incubator-heron with Apache License 2.0 6 votes vote down vote up
@Override
public boolean launch(PackingPlan packing) {
  Configuration reefRuntimeConf = getRuntimeConf();
  Configuration reefDriverConf = getHMDriverConf();
  Configuration reefClientConf = getClientConf();

  boolean ret;
  try {
    final Injector injector = Tang.Factory.getTang().newInjector(reefRuntimeConf, reefClientConf);
    final REEF reef = injector.getInstance(REEF.class);
    final ReefClientSideHandlers client = injector.getInstance(ReefClientSideHandlers.class);

    reef.submit(reefDriverConf);

    ret = client.waitForSchedulerJobResponse();
  } catch (InjectionException | InterruptedException e) {
    LOG.log(Level.WARNING, "Failed to launch REEF app", e);
    return false;
  }

  return ret;
}
 
Example 4
Source File: BlockStoreTest.java    From incubator-nemo with Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link SerializedMemoryStore}.
 *
 * @throws Exception exception on the way.
 */
@Test(timeout = 10000)
public void testSerMemoryStore() throws Exception {
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileInstance(SerializerManager.class, serializerManager);
  injector.bindVolatileParameter(JobConf.ExecutorMemoryMb.class, 640);
  injector.bindVolatileParameter(JobConf.MaxOffheapRatio.class, 0.2);
  final BlockStore serMemoryStore = injector.getInstance(SerializedMemoryStore.class);
  shuffle(serMemoryStore, serMemoryStore);
  concurrentRead(serMemoryStore, serMemoryStore);
  shuffleInHashRange(serMemoryStore, serMemoryStore);
}
 
Example 5
Source File: BlockManagerMasterTest.java    From nemo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  final LocalMessageDispatcher messageDispatcher = new LocalMessageDispatcher();
  final LocalMessageEnvironment messageEnvironment =
      new LocalMessageEnvironment(MessageEnvironment.MASTER_COMMUNICATION_ID, messageDispatcher);
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileInstance(MessageEnvironment.class, messageEnvironment);
  blockManagerMaster = injector.getInstance(BlockManagerMaster.class);
}
 
Example 6
Source File: LoggingScopeTest.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Use default log level in injecting LoggingScopeFactory constructor.
 * @throws InjectionException
 */
@Test
public void testLoggingScopeFactoryWithDefaultLogLevel() throws InjectionException {
  final Injector i = Tang.Factory.getTang().newInjector(Tang.Factory.getTang().newConfigurationBuilder().build());
  final LoggingScopeFactory localLogFactory = i.getInstance(LoggingScopeFactory.class);

  try (LoggingScope ls = localLogFactory.activeContextReceived("test")) {
    Assert.assertTrue(true);
  }
}
 
Example 7
Source File: RunningJobsImpl.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * @param jobIdentifier
 * @param remoteIdentifier
 * @return
 * @throws BindException
 * @throws InjectionException
 */
private synchronized RunningJobImpl newRunningJob(final String jobIdentifier, final String remoteIdentifier)
    throws BindException, InjectionException {
  final Injector child = this.injector.forkInjector();
  child.bindVolatileParameter(REEFImplementation.DriverRemoteIdentifier.class, remoteIdentifier);
  child.bindVolatileParameter(DriverIdentifier.class, jobIdentifier);
  return child.getInstance(RunningJobImpl.class);
}
 
Example 8
Source File: TestHttpServer.java    From reef with Apache License 2.0 5 votes vote down vote up
@Test
public void httpServerAddHandlerTest() throws Exception {

  final Configuration httpRuntimeConfiguration = HttpRuntimeConfiguration.CONF.build();

  final Configuration reefConfiguration = Tang.Factory.getTang().newConfigurationBuilder()
      .bindNamedParameter(RemoteConfiguration.ManagerName.class, "REEF_TEST_REMOTE_MANAGER")
      .bindNamedParameter(RemoteConfiguration.MessageCodec.class, REEFMessageCodec.class)
      .bindNamedParameter(JobIdentifier.class, "my job")
      .build();

  final Configuration finalConfig =
      Configurations.merge(httpRuntimeConfiguration, reefConfiguration);

  final Injector injector = Tang.Factory.getTang().newInjector(finalConfig);
  final HttpServer httpServer = injector.getInstance(HttpServer.class);
  final HttpServerReefEventHandler httpHandler =
      injector.getInstance(HttpServerReefEventHandler.class);

  httpServer.addHttpHandler(httpHandler);

  // Assert.assertTrue(true);
  // Cannot access private variables inside the server.
  // If it is returned, meaning it is added successfully.

  httpServer.stop();
}
 
Example 9
Source File: ClientEndpointTest.java    From nemo with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 3000)
public void testState() throws Exception {
  // Create a simple client endpoint that returns given job state.
  final StateTranslator stateTranslator = mock(StateTranslator.class);
  when(stateTranslator.translateState(any())).then(state -> state.getArgument(0));
  final ClientEndpoint clientEndpoint = new TestClientEndpoint(stateTranslator);
  assertEquals(clientEndpoint.getJobState(), JobState.State.READY);

  // Wait for connection but not connected.
  assertEquals(clientEndpoint.waitUntilJobFinish(100, TimeUnit.MILLISECONDS), JobState.State.READY);

  // Create a JobStateManager of an empty dag and create a DriverEndpoint with it.
  final DAGBuilder<IRVertex, IREdge> irDagBuilder = new DAGBuilder<>();
  final DAG<IRVertex, IREdge> irDAG = irDagBuilder.build();
  final Injector injector = Tang.Factory.getTang().newInjector();
  injector.bindVolatileParameter(JobConf.DAGDirectory.class, "");
  final PhysicalPlanGenerator physicalPlanGenerator = injector.getInstance(PhysicalPlanGenerator.class);
  final DAG<PhysicalStage, PhysicalStageEdge> physicalDAG = irDAG.convert(physicalPlanGenerator);

  final LocalMessageDispatcher messageDispatcher = new LocalMessageDispatcher();
  final LocalMessageEnvironment messageEnvironment =
      new LocalMessageEnvironment(MessageEnvironment.MASTER_COMMUNICATION_ID, messageDispatcher);
  injector.bindVolatileInstance(MessageEnvironment.class, messageEnvironment);
  final BlockManagerMaster pmm = injector.getInstance(BlockManagerMaster.class);
  final JobStateManager jobStateManager = new JobStateManager(
      new PhysicalPlan("TestPlan", physicalDAG, physicalPlanGenerator.getTaskIRVertexMap()),
      pmm, metricMessageHandler, MAX_SCHEDULE_ATTEMPT);

  final DriverEndpoint driverEndpoint = new DriverEndpoint(jobStateManager, clientEndpoint);

  // Check the current state.
  assertEquals(clientEndpoint.getJobState(), JobState.State.EXECUTING);

  // Wait for the job to finish but not finished
  assertEquals(clientEndpoint.waitUntilJobFinish(100, TimeUnit.MILLISECONDS), JobState.State.EXECUTING);

  // Check finish.
  jobStateManager.onJobStateChanged(JobState.State.COMPLETE);
  assertEquals(clientEndpoint.waitUntilJobFinish(), JobState.State.COMPLETE);
}
 
Example 10
Source File: DataTransferTest.java    From nemo with Apache License 2.0 5 votes vote down vote up
private BlockManagerWorker createWorker(final String executorId, final LocalMessageDispatcher messageDispatcher,
                                        final Injector nameClientInjector) {
  final LocalMessageEnvironment messageEnvironment = new LocalMessageEnvironment(executorId, messageDispatcher);
  final PersistentConnectionToMasterMap conToMaster = new PersistentConnectionToMasterMap(messageEnvironment);
  final Configuration executorConfiguration = TANG.newConfigurationBuilder()
      .bindNamedParameter(JobConf.ExecutorId.class, executorId)
      .bindNamedParameter(MessageParameters.SenderId.class, executorId)
      .build();
  final Injector injector = nameClientInjector.forkInjector(executorConfiguration);
  injector.bindVolatileInstance(MessageEnvironment.class, messageEnvironment);
  injector.bindVolatileInstance(PersistentConnectionToMasterMap.class, conToMaster);
  injector.bindVolatileParameter(JobConf.FileDirectory.class, TMP_LOCAL_FILE_DIRECTORY);
  injector.bindVolatileParameter(JobConf.GlusterVolumeDirectory.class, TMP_REMOTE_FILE_DIRECTORY);
  final BlockManagerWorker blockManagerWorker;
  final MetricManagerWorker metricManagerWorker;
  final SerializerManager serializerManager;
  try {
    blockManagerWorker = injector.getInstance(BlockManagerWorker.class);
    metricManagerWorker =  injector.getInstance(MetricManagerWorker.class);
    serializerManager = injector.getInstance(SerializerManager.class);
    serializerManagers.put(blockManagerWorker, serializerManager);
  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }

  // Unused, but necessary for wiring up the message environments
  final Executor executor = new Executor(
      executorId,
      EXECUTOR_CAPACITY,
      conToMaster,
      messageEnvironment,
      serializerManager,
      new DataTransferFactory(HASH_RANGE_MULTIPLIER, blockManagerWorker),
      metricManagerWorker);
  injector.bindVolatileInstance(Executor.class, executor);

  return blockManagerWorker;
}
 
Example 11
Source File: DefaultRemoteManagerFactory.java    From reef with Apache License 2.0 5 votes vote down vote up
@Override
public <T> RemoteManager getInstance(final String newRmName,
                                     final String newHostAddress,
                                     final int newListeningPort,
                                     final Codec<T> newCodec,
                                     final EventHandler<Throwable> newErrorHandler,
                                     final boolean newOrderingGuarantee,
                                     final int newNumberOfTries,
                                     final int newRetryTimeout,
                                     final LocalAddressProvider newLocalAddressProvider,
                                     final TcpPortProvider newTcpPortProvider) {
  try {

    final Injector newInjector = injector.forkInjector();

    if (newHostAddress != null) {
      newInjector.bindVolatileParameter(RemoteConfiguration.HostAddress.class, newHostAddress);
    }

    if (newListeningPort > 0) {
      newInjector.bindVolatileParameter(RemoteConfiguration.Port.class, newListeningPort);
    }

    newInjector.bindVolatileParameter(RemoteConfiguration.ManagerName.class, newRmName);
    newInjector.bindVolatileParameter(RemoteConfiguration.MessageCodec.class, newCodec);
    newInjector.bindVolatileParameter(RemoteConfiguration.ErrorHandler.class, newErrorHandler);
    newInjector.bindVolatileParameter(RemoteConfiguration.OrderingGuarantee.class, newOrderingGuarantee);
    newInjector.bindVolatileParameter(RemoteConfiguration.NumberOfTries.class, newNumberOfTries);
    newInjector.bindVolatileParameter(RemoteConfiguration.RetryTimeout.class, newRetryTimeout);
    newInjector.bindVolatileInstance(LocalAddressProvider.class, newLocalAddressProvider);
    newInjector.bindVolatileInstance(TransportFactory.class, this.transportFactory);
    newInjector.bindVolatileInstance(TcpPortProvider.class, newTcpPortProvider);

    return newInjector.getInstance(RemoteManager.class);

  } catch (final InjectionException e) {
    throw new RuntimeException(e);
  }
}
 
Example 12
Source File: HelloReefAzBatch.java    From reef with Apache License 2.0 5 votes vote down vote up
/**
 * Start the Hello REEF job with the Azure Batch runtime.
 *
 * @param args command line parameters.
 * @throws InjectionException configuration error.
 * @throws IOException
 */
public static void main(final String[] args) throws InjectionException, IOException {

  final Configuration partialConfiguration = getEnvironmentConfiguration();
  final Injector injector = Tang.Factory.getTang().newInjector(partialConfiguration);
  final AzureBatchRuntimeConfigurationProvider runtimeConfigurationProvider =
      injector.getInstance(AzureBatchRuntimeConfigurationProvider.class);
  final Configuration driverConfiguration = getDriverConfiguration();

  try (REEF reef = Tang.Factory.getTang().newInjector(
      runtimeConfigurationProvider.getAzureBatchRuntimeConfiguration()).getInstance(REEF.class)) {
    reef.submit(driverConfiguration);
  }
  LOG.log(Level.INFO, "Job Submitted");
}
 
Example 13
Source File: NetworkServiceTest.java    From reef with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultithreadedSharedConnMessagingNetworkServiceRate() throws Exception {

  Assume.assumeFalse("Use log level INFO to run benchmarking", LOG.isLoggable(Level.FINEST));

  LOG.log(Level.FINEST, name.getMethodName());

  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 nameServerPort = server.getPort();

    final int[] messageSizes = {2000}; // {1,16,32,64,512,64*1024,1024*1024};

    for (final int size : messageSizes) {
      final int numMessages = 300000 / (Math.max(1, size / 512));
      final int numThreads = 2;
      final int totalNumMessages = numMessages * numThreads;
      final Monitor monitor = new Monitor();


      // network service
      final String name2 = "task2";
      final String name1 = "task1";
      final Configuration nameResolverConf =
          Tang.Factory.getTang().newConfigurationBuilder(NameResolverConfiguration.CONF
          .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, this.localAddress)
          .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServerPort)
          .build())
          .build();

      final Injector injector2 = Tang.Factory.getTang().newInjector(nameResolverConf);

      LOG.log(Level.FINEST, "=== Test network service receiver start");
      LOG.log(Level.FINEST, "=== Test network service sender start");
      try (NameResolver nameResolver = injector2.getInstance(NameResolver.class)) {
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class, factory);
        injector2.bindVolatileInstance(NameResolver.class, nameResolver);
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceCodec.class, new StringCodec());
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceTransportFactory.class,
            injector.getInstance(MessagingTransportFactory.class));
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class,
            new ExceptionHandler());

        final Injector injectorNs2 = injector2.forkInjector();
        injectorNs2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class,
            new MessageHandler<String>(name2, monitor, totalNumMessages));
        final NetworkService<String> ns2 = injectorNs2.getInstance(NetworkService.class);

        final Injector injectorNs1 = injector2.forkInjector();
        injectorNs1.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class,
            new MessageHandler<String>(name1, null, 0));
        final NetworkService<String> ns1 = injectorNs1.getInstance(NetworkService.class);

        ns2.registerId(factory.getNewInstance(name2));
        final int port2 = ns2.getTransport().getListeningPort();
        server.register(factory.getNewInstance("task2"), new InetSocketAddress(this.localAddress, port2));

        ns1.registerId(factory.getNewInstance(name1));
        final int port1 = ns1.getTransport().getListeningPort();
        server.register(factory.getNewInstance("task1"), new InetSocketAddress(this.localAddress, port1));

        final Identifier destId = factory.getNewInstance(name2);

        try (Connection<String> conn = ns1.newConnection(destId)) {
          conn.open();

          final String message = StringUtils.repeat('1', size);
          final ExecutorService e = Executors.newCachedThreadPool();

          final long start = System.currentTimeMillis();
          for (int i = 0; i < numThreads; i++) {
            e.submit(new Runnable() {

              @Override
              public void run() {
                for (int i = 0; i < numMessages; i++) {
                  conn.write(message);
                }
              }
            });
          }


          e.shutdown();
          e.awaitTermination(30, TimeUnit.SECONDS);
          monitor.mwait();

          final long end = System.currentTimeMillis();
          final double runtime = ((double) end - start) / 1000;

          LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + totalNumMessages / runtime + 
              " bandwidth(bytes/s): " + ((double) totalNumMessages * 2 * size) / runtime); // x2 for unicode chars
        }
      }
    }
  }
}
 
Example 14
Source File: TestHttpServer.java    From reef with Apache License 2.0 4 votes vote down vote up
@Test
public void httpServerConflictPortTest() throws Exception {

  final Configuration httpRuntimeConfiguration = HttpRuntimeConfiguration.CONF.build();

  final Injector injector1 = Tang.Factory.getTang().newInjector(httpRuntimeConfiguration);
  final HttpServer httpServer1 = injector1.getInstance(HttpServer.class);

  final Injector injector2 = Tang.Factory.getTang().newInjector(httpRuntimeConfiguration);
  final HttpServer httpServer2 = injector2.getInstance(HttpServer.class);

  Assert.assertNotEquals(8080, httpServer2.getPort());

  httpServer1.stop();
  httpServer2.stop();
}
 
Example 15
Source File: DataTransferTest.java    From incubator-nemo with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws InjectionException {
  final Configuration configuration = Tang.Factory.getTang().newConfigurationBuilder()
    .bindNamedParameter(JobConf.ScheduleSerThread.class, "1")
    .build();
  final Injector baseInjector = Tang.Factory.getTang().newInjector(configuration);
  baseInjector.bindVolatileInstance(EvaluatorRequestor.class, mock(EvaluatorRequestor.class));
  final Injector dispatcherInjector = LocalMessageDispatcher.forkInjector(baseInjector);
  final Injector injector = LocalMessageEnvironment.forkInjector(dispatcherInjector,
    MessageEnvironment.MASTER_COMMUNICATION_ID);

  final PlanRewriter planRewriter = mock(PlanRewriter.class);
  injector.bindVolatileInstance(PlanRewriter.class, planRewriter);

  injector.bindVolatileInstance(PubSubEventHandlerWrapper.class, mock(PubSubEventHandlerWrapper.class));
  final AtomicInteger executorCount = new AtomicInteger(0);
  injector.bindVolatileInstance(ClientRPC.class, mock(ClientRPC.class));
  injector.bindVolatileInstance(MetricManagerMaster.class, mock(MetricManagerMaster.class));
  injector.bindVolatileInstance(MetricMessageHandler.class, mock(MetricMessageHandler.class));
  injector.bindVolatileParameter(JobConf.DAGDirectory.class, EMPTY_DAG_DIRECTORY);
  injector.bindVolatileParameter(JobConf.JobId.class, "jobId");

  // Necessary for wiring up the message environments
  injector.bindVolatileInstance(Scheduler.class, injector.getInstance(BatchScheduler.class));
  injector.getInstance(RuntimeMaster.class);
  final BlockManagerMaster master = injector.getInstance(BlockManagerMaster.class);
  final MetricManagerWorker metricMessageSender = injector.getInstance(MetricManagerWorker.class);

  final Injector nameClientInjector = createNameClientInjector();
  nameClientInjector.bindVolatileParameter(JobConf.JobId.class, "data transfer test");

  this.master = master;
  final Pair<BlockManagerWorker, IntermediateDataIOFactory> pair1 = createWorker(
    EXECUTOR_ID_PREFIX + executorCount.getAndIncrement(), dispatcherInjector, nameClientInjector);
  this.worker1 = pair1.left();
  this.transferFactory = pair1.right();
  this.worker2 = createWorker(EXECUTOR_ID_PREFIX + executorCount.getAndIncrement(), dispatcherInjector,
    nameClientInjector).left();

  this.metricMessageSender = metricMessageSender;
}
 
Example 16
Source File: SmallMessagesTest.java    From reef with Apache License 2.0 4 votes vote down vote up
public SmallMessagesTest() throws InjectionException {
  final Injector injector = Tang.Factory.getTang().newInjector();
  this.localAddressProvider = injector.getInstance(LocalAddressProvider.class);
  this.tpFactory = injector.getInstance(TransportFactory.class);
}
 
Example 17
Source File: NetworkServiceTest.java    From reef with Apache License 2.0 4 votes vote down vote up
/**
 * NetworkService messaging rate benchmark.
 */
@Test
public void testMessagingNetworkServiceBatchingRate() throws Exception {

  Assume.assumeFalse("Use log level INFO to run benchmarking", LOG.isLoggable(Level.FINEST));

  LOG.log(Level.FINEST, name.getMethodName());

  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 nameServerPort = server.getPort();

    final int batchSize = 1024 * 1024;
    final int[] messageSizes = {32, 64, 512};

    for (final int size : messageSizes) {
      final int numMessages = 300 / (Math.max(1, size / 512));
      final Monitor monitor = new Monitor();

      // network service
      final String name2 = "task2";
      final String name1 = "task1";
      final Configuration nameResolverConf =
          Tang.Factory.getTang().newConfigurationBuilder(NameResolverConfiguration.CONF
          .set(NameResolverConfiguration.NAME_SERVER_HOSTNAME, this.localAddress)
          .set(NameResolverConfiguration.NAME_SERVICE_PORT, nameServerPort)
          .build())
          .build();

      final Injector injector2 = Tang.Factory.getTang().newInjector(nameResolverConf);

      LOG.log(Level.FINEST, "=== Test network service receiver start");
      LOG.log(Level.FINEST, "=== Test network service sender start");
      try (NameResolver nameResolver = injector2.getInstance(NameResolver.class)) {
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceIdentifierFactory.class, factory);
        injector2.bindVolatileInstance(NameResolver.class, nameResolver);
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceCodec.class, new StringCodec());
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceTransportFactory.class,
            injector.getInstance(MessagingTransportFactory.class));
        injector2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceExceptionHandler.class,
            new ExceptionHandler());

        final Injector injectorNs2 = injector2.forkInjector();
        injectorNs2.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class,
            new MessageHandler<String>(name2, monitor, numMessages));
        final NetworkService<String> ns2 = injectorNs2.getInstance(NetworkService.class);

        final Injector injectorNs1 = injector2.forkInjector();
        injectorNs1.bindVolatileParameter(NetworkServiceParameters.NetworkServiceHandler.class,
            new MessageHandler<String>(name1, null, 0));
        final NetworkService<String> ns1 = injectorNs1.getInstance(NetworkService.class);

        ns2.registerId(factory.getNewInstance(name2));
        final int port2 = ns2.getTransport().getListeningPort();
        server.register(factory.getNewInstance("task2"), new InetSocketAddress(this.localAddress, port2));

        ns1.registerId(factory.getNewInstance(name1));
        final int port1 = ns1.getTransport().getListeningPort();
        server.register(factory.getNewInstance("task1"), new InetSocketAddress(this.localAddress, port1));

        final Identifier destId = factory.getNewInstance(name2);
        final String message = StringUtils.repeat('1', batchSize);

        final long start = System.currentTimeMillis();
        try (Connection<String> conn = ns1.newConnection(destId)) {
          conn.open();
          for (int i = 0; i < numMessages; i++) {
            conn.write(message);
          }
          monitor.mwait();
        } catch (final NetworkException e) {
          e.printStackTrace();
          throw new RuntimeException(e);
        }
        final long end = System.currentTimeMillis();
        final double runtime = ((double) end - start) / 1000;
        final long numAppMessages = numMessages * batchSize / size;
        LOG.log(Level.FINEST, "size: " + size + "; messages/s: " + numAppMessages / runtime +
            " bandwidth(bytes/s): " + ((double) numAppMessages * 2 * size) / runtime); // x2 for unicode chars
      }
    }
  }
}
 
Example 18
Source File: REEFExecutor.java    From reef with Apache License 2.0 4 votes vote down vote up
/**
 * The starting point of the executor.
 */
public static void main(final String[] args) throws Exception {
  final Injector injector = Tang.Factory.getTang().newInjector(parseCommandLine(args));
  final REEFExecutor reefExecutor = injector.getInstance(REEFExecutor.class);
  reefExecutor.onStart();
}
 
Example 19
Source File: LargeMsgTest.java    From reef with Apache License 2.0 4 votes vote down vote up
public LargeMsgTest() throws InjectionException {
  final Injector injector = Tang.Factory.getTang().newInjector();
  this.localAddressProvider = injector.getInstance(LocalAddressProvider.class);
  this.tpFactory = injector.getInstance(TransportFactory.class);
}
 
Example 20
Source File: LocalMessageEnvironment.java    From incubator-nemo with Apache License 2.0 3 votes vote down vote up
/**
 * Extends {@code baseInjector} to have {@link LocalMessageEnvironment} instance for the given {@code senderId}.
 *
 * @param baseInjector provided by {@link LocalMessageDispatcher#getInjector()}
 *                     or {@link LocalMessageDispatcher#forkInjector(Injector)}
 * @param senderId     the identifier for the sender
 * @return an {@link Injector} which has {@link LocalMessageDispatcher} instance for {@link MessageEnvironment}
 * @throws InjectionException when fails to inject {@link MessageEnvironment}
 */
public static Injector forkInjector(final Injector baseInjector, final String senderId) throws InjectionException {
  final Injector injector = baseInjector.forkInjector(TANG.newConfigurationBuilder()
    .bindNamedParameter(MessageParameters.SenderId.class, senderId).build());
  injector.getInstance(MessageEnvironment.class);
  return injector;
}