<commit_before>/*
 * Copyright 2012-2013 Continuuity,Inc. All Rights Reserved.
 */
package com.continuuity.app.guice;

import com.continuuity.app.authorization.AuthorizationFactory;
import com.continuuity.app.deploy.Manager;
import com.continuuity.app.deploy.ManagerFactory;
import com.continuuity.app.store.StoreFactory;
import com.continuuity.common.conf.CConfiguration;
import com.continuuity.common.conf.Constants;
import com.continuuity.common.runtime.RuntimeModule;
import com.continuuity.common.twill.InMemoryReactorServiceManager;
import com.continuuity.common.twill.ReactorServiceManager;
import com.continuuity.common.utils.Networks;
import com.continuuity.data.stream.StreamServiceManager;
import com.continuuity.data2.datafabric.dataset.DatasetExecutorServiceManager;
import com.continuuity.explore.service.ExploreServiceManager;
import com.continuuity.gateway.handlers.AppFabricHttpHandler;
import com.continuuity.gateway.handlers.MonitorHandler;
import com.continuuity.gateway.handlers.PingHandler;
import com.continuuity.gateway.handlers.ServiceHttpHandler;
import com.continuuity.http.HttpHandler;
import com.continuuity.internal.app.authorization.PassportAuthorizationFactory;
import com.continuuity.internal.app.deploy.LocalManager;
import com.continuuity.internal.app.deploy.pipeline.ApplicationWithPrograms;
import com.continuuity.internal.app.runtime.distributed.TransactionServiceManager;
import com.continuuity.internal.app.runtime.schedule.DataSetBasedScheduleStore;
import com.continuuity.internal.app.runtime.schedule.DistributedSchedulerService;
import com.continuuity.internal.app.runtime.schedule.ExecutorThreadPool;
import com.continuuity.internal.app.runtime.schedule.LocalSchedulerService;
import com.continuuity.internal.app.runtime.schedule.Scheduler;
import com.continuuity.internal.app.runtime.schedule.SchedulerService;
import com.continuuity.internal.app.store.MDTBasedStoreFactory;
import com.continuuity.internal.pipeline.SynchronousPipelineFactory;
import com.continuuity.logging.run.LogSaverServiceManager;
import com.continuuity.metrics.runtime.MetricsProcessorServiceManager;
import com.continuuity.metrics.runtime.MetricsServiceManager;
import com.continuuity.pipeline.PipelineFactory;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.google.inject.util.Modules;
import org.apache.twill.filesystem.Location;
import org.quartz.SchedulerException;
import org.quartz.core.JobRunShellFactory;
import org.quartz.core.QuartzScheduler;
import org.quartz.core.QuartzSchedulerResources;
import org.quartz.impl.DefaultThreadExecutor;
import org.quartz.impl.DirectSchedulerFactory;
import org.quartz.impl.StdJobRunShellFactory;
import org.quartz.impl.StdScheduler;
import org.quartz.simpl.CascadingClassLoadHelper;
import org.quartz.spi.ClassLoadHelper;
import org.quartz.spi.JobStore;

import java.net.InetAddress;
import java.net.InetSocketAddress;

/**
 * AppFabric Service Runtime Module.
 */
public final class AppFabricServiceRuntimeModule extends RuntimeModule {

  @Override
  public Module getInMemoryModules() {
    return Modules.combine(new AppFabricServiceModule(),
                           new AbstractModule() {
                             @Override
                             protected void configure() {
                               bind(SchedulerService.class).to(LocalSchedulerService.class).in(Scopes.SINGLETON);
                               bind(Scheduler.class).to(SchedulerService.class);
                             }
                           });
  }

  @Override
  public Module getSingleNodeModules() {

    return Modules.combine(new AppFabricServiceModule(),
                           new AbstractModule() {
                             @Override
                             protected void configure() {
                               bind(SchedulerService.class).to(LocalSchedulerService.class).in(Scopes.SINGLETON);
                               bind(Scheduler.class).to(SchedulerService.class);
                             }
                           });
  }

  @Override
  public Module getDistributedModules() {


    return Modules.combine(new AppFabricServiceModule(),
                           new AbstractModule() {
                             @Override
                             protected void configure() {
                               bind(SchedulerService.class).to(DistributedSchedulerService.class).in(Scopes.SINGLETON);
                               bind(Scheduler.class).to(SchedulerService.class);

                             }
                           });
  }
  /**
   * Guice module for AppFabricServer. Requires data-fabric related bindings being available.
   */
  private static final class AppFabricServiceModule extends AbstractModule {

    @Override
    protected void configure() {
      bind(PipelineFactory.class).to(SynchronousPipelineFactory.class);

      install(
        new FactoryModuleBuilder()
          .implement(new TypeLiteral<Manager<Location, ApplicationWithPrograms>>() { },
                     new TypeLiteral<LocalManager<Location, ApplicationWithPrograms>>() { })
          .build(new TypeLiteral<ManagerFactory<Location, ApplicationWithPrograms>>() { })
      );

      bind(AuthorizationFactory.class).to(PassportAuthorizationFactory.class);

      bind(StoreFactory.class).to(MDTBasedStoreFactory.class);

      Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class,
                                                                        Names.named("appfabric.http.handler"));
      handlerBinder.addBinding().to(AppFabricHttpHandler.class);
      handlerBinder.addBinding().to(PingHandler.class);
      handlerBinder.addBinding().to(MonitorHandler.class);
      handlerBinder.addBinding().to(ServiceHttpHandler.class);

      MapBinder<String, ReactorServiceManager> mapBinder = MapBinder.newMapBinder(binder(), String.class,
                                                                                  ReactorServiceManager.class);
      mapBinder.addBinding(Constants.Service.LOGSAVER).to(LogSaverServiceManager.class);
      mapBinder.addBinding(Constants.Service.TRANSACTION).to(TransactionServiceManager.class);
      mapBinder.addBinding(Constants.Service.METRICS_PROCESSOR).to(MetricsProcessorServiceManager.class);
      mapBinder.addBinding(Constants.Service.METRICS).to(MetricsServiceManager.class);
      mapBinder.addBinding(Constants.Service.APP_FABRIC_HTTP).to(InMemoryReactorServiceManager.class);
      mapBinder.addBinding(Constants.Service.STREAMS).to(StreamServiceManager.class);
      mapBinder.addBinding(Constants.Service.DATASET_EXECUTOR).to(DatasetExecutorServiceManager.class);
      mapBinder.addBinding(Constants.Service.EXPLORE_HTTP_USER_SERVICE).to(ExploreServiceManager.class);
    }
<commit_msg>Revert modules<commit_after>/*
 * Copyright 2012-2013 Continuuity,Inc. All Rights Reserved.
 */
package com.continuuity.app.guice;

import com.continuuity.app.authorization.AuthorizationFactory;
import com.continuuity.app.deploy.Manager;
import com.continuuity.app.deploy.ManagerFactory;
import com.continuuity.app.store.StoreFactory;
import com.continuuity.common.conf.CConfiguration;
import com.continuuity.common.conf.Constants;
import com.continuuity.common.runtime.RuntimeModule;
import com.continuuity.common.twill.InMemoryReactorServiceManager;
import com.continuuity.common.twill.ReactorServiceManager;
import com.continuuity.common.utils.Networks;
import com.continuuity.data.stream.StreamServiceManager;
import com.continuuity.data2.datafabric.dataset.DatasetExecutorServiceManager;
import com.continuuity.explore.service.ExploreServiceManager;
import com.continuuity.gateway.handlers.AppFabricHttpHandler;
import com.continuuity.gateway.handlers.MonitorHandler;
import com.continuuity.gateway.handlers.PingHandler;
import com.continuuity.gateway.handlers.ServiceHttpHandler;
import com.continuuity.http.HttpHandler;
import com.continuuity.internal.app.authorization.PassportAuthorizationFactory;
import com.continuuity.internal.app.deploy.LocalManager;
import com.continuuity.internal.app.deploy.pipeline.ApplicationWithPrograms;
import com.continuuity.internal.app.runtime.batch.InMemoryTransactionServiceManager;
import com.continuuity.internal.app.runtime.distributed.TransactionServiceManager;
import com.continuuity.internal.app.runtime.schedule.DataSetBasedScheduleStore;
import com.continuuity.internal.app.runtime.schedule.DistributedSchedulerService;
import com.continuuity.internal.app.runtime.schedule.ExecutorThreadPool;
import com.continuuity.internal.app.runtime.schedule.LocalSchedulerService;
import com.continuuity.internal.app.runtime.schedule.Scheduler;
import com.continuuity.internal.app.runtime.schedule.SchedulerService;
import com.continuuity.internal.app.store.MDTBasedStoreFactory;
import com.continuuity.internal.pipeline.SynchronousPipelineFactory;
import com.continuuity.logging.run.InMemoryLogSaverServiceMananger;
import com.continuuity.logging.run.LogSaverServiceManager;
import com.continuuity.metrics.runtime.MetricsProcessorServiceManager;
import com.continuuity.metrics.runtime.MetricsServiceManager;
import com.continuuity.pipeline.PipelineFactory;
import com.google.common.base.Supplier;
import com.google.common.base.Throwables;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.google.inject.util.Modules;
import org.apache.twill.filesystem.Location;
import org.quartz.SchedulerException;
import org.quartz.core.JobRunShellFactory;
import org.quartz.core.QuartzScheduler;
import org.quartz.core.QuartzSchedulerResources;
import org.quartz.impl.DefaultThreadExecutor;
import org.quartz.impl.DirectSchedulerFactory;
import org.quartz.impl.StdJobRunShellFactory;
import org.quartz.impl.StdScheduler;
import org.quartz.simpl.CascadingClassLoadHelper;
import org.quartz.spi.ClassLoadHelper;
import org.quartz.spi.JobStore;

import java.net.InetAddress;
import java.net.InetSocketAddress;

/**
 * AppFabric Service Runtime Module.
 */
public final class AppFabricServiceRuntimeModule extends RuntimeModule {

  @Override
  public Module getInMemoryModules() {
    return Modules.combine(new AppFabricServiceModule(),
                           new AbstractModule() {
                             @Override
                             protected void configure() {
                               bind(SchedulerService.class).to(LocalSchedulerService.class).in(Scopes.SINGLETON);
                               bind(Scheduler.class).to(SchedulerService.class);

                               MapBinder<String, ReactorServiceManager> mapBinder = MapBinder.newMapBinder(
                                 binder(), String.class, ReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.LOGSAVER).to(
                                 InMemoryLogSaverServiceMananger.class);
                               mapBinder.addBinding(Constants.Service.TRANSACTION).to(
                                 InMemoryTransactionServiceManager.class);
                               //Using LogSaverServiceManager since status check and logs are not available
                               //for metrics.processor as well
                               mapBinder.addBinding(Constants.Service.METRICS_PROCESSOR).to(
                                 InMemoryLogSaverServiceMananger.class);
                               mapBinder.addBinding(Constants.Service.METRICS).to(InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.APP_FABRIC_HTTP).to(
                                 InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.STREAMS).to(InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.DATASET_EXECUTOR).to(
                                 InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.EXPLORE_HTTP_USER_SERVICE)
                                 .to(InMemoryReactorServiceManager.class);
                             }
                           });
  }

  @Override
  public Module getSingleNodeModules() {

    return Modules.combine(new AppFabricServiceModule(),
                           new AbstractModule() {
                             @Override
                             protected void configure() {
                               bind(SchedulerService.class).to(LocalSchedulerService.class).in(Scopes.SINGLETON);
                               bind(Scheduler.class).to(SchedulerService.class);

                               MapBinder<String, ReactorServiceManager> mapBinder = MapBinder.newMapBinder(
                                 binder(), String.class, ReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.LOGSAVER).to(
                                 InMemoryLogSaverServiceMananger.class);
                               mapBinder.addBinding(Constants.Service.TRANSACTION).to(
                                 InMemoryTransactionServiceManager.class);
                               //Using LogSaverServiceManager since status check and logs are not available
                               //for metrics.processor as well
                               mapBinder.addBinding(Constants.Service.METRICS_PROCESSOR).to(
                                 InMemoryLogSaverServiceMananger.class);
                               mapBinder.addBinding(Constants.Service.METRICS).to(InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.APP_FABRIC_HTTP).to(
                                 InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.STREAMS).to(InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.DATASET_EXECUTOR).to(
                                 InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.EXPLORE_HTTP_USER_SERVICE)
                                 .to(InMemoryReactorServiceManager.class);
                             }
                           });
  }

  @Override
  public Module getDistributedModules() {


    return Modules.combine(new AppFabricServiceModule(),
                           new AbstractModule() {
                             @Override
                             protected void configure() {
                               bind(SchedulerService.class).to(DistributedSchedulerService.class).in(Scopes.SINGLETON);
                               bind(Scheduler.class).to(SchedulerService.class);

                               MapBinder<String, ReactorServiceManager> mapBinder = MapBinder.newMapBinder(
                                 binder(), String.class, ReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.LOGSAVER).to(LogSaverServiceManager.class);
                               mapBinder.addBinding(Constants.Service.TRANSACTION).to(TransactionServiceManager.class);
                               mapBinder.addBinding(Constants.Service.METRICS_PROCESSOR).to(
                                 MetricsProcessorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.METRICS).to(MetricsServiceManager.class);
                               mapBinder.addBinding(Constants.Service.APP_FABRIC_HTTP).to(
                                 InMemoryReactorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.STREAMS).to(StreamServiceManager.class);
                               mapBinder.addBinding(Constants.Service.DATASET_EXECUTOR).to(
                                 DatasetExecutorServiceManager.class);
                               mapBinder.addBinding(Constants.Service.EXPLORE_HTTP_USER_SERVICE)
                                 .to(ExploreServiceManager.class);
                             }
                           });
  }
  /**
   * Guice module for AppFabricServer. Requires data-fabric related bindings being available.
   */
  private static final class AppFabricServiceModule extends AbstractModule {

    @Override
    protected void configure() {
      bind(PipelineFactory.class).to(SynchronousPipelineFactory.class);

      install(
        new FactoryModuleBuilder()
          .implement(new TypeLiteral<Manager<Location, ApplicationWithPrograms>>() { },
                     new TypeLiteral<LocalManager<Location, ApplicationWithPrograms>>() { })
          .build(new TypeLiteral<ManagerFactory<Location, ApplicationWithPrograms>>() { })
      );

      bind(AuthorizationFactory.class).to(PassportAuthorizationFactory.class);

      bind(StoreFactory.class).to(MDTBasedStoreFactory.class);

      Multibinder<HttpHandler> handlerBinder = Multibinder.newSetBinder(binder(), HttpHandler.class,
                                                                        Names.named("appfabric.http.handler"));
      handlerBinder.addBinding().to(AppFabricHttpHandler.class);
      handlerBinder.addBinding().to(PingHandler.class);
      handlerBinder.addBinding().to(MonitorHandler.class);
      handlerBinder.addBinding().to(ServiceHttpHandler.class);
    }

{'fraction_non_alphanumeric': 0.08536585365853659, 'fraction_numerical': 0.000988793671720501, 'mean_word_length': 2.703213995117982, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6991420', 'n_tokens_mistral': 4700, 'n_tokens_neox': 4634, 'n_words': 570}