Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.facebook.presto.server;
 
 
 
 import static com.facebook.presto.execution.DataDefinitionExecution.DataDefinitionExecutionFactory;
 import static com.facebook.presto.execution.QueryExecution.QueryExecutionFactory;
 import static com.facebook.presto.execution.SqlQueryExecution.SqlQueryExecutionFactory;
 import static com.google.inject.multibindings.MapBinder.newMapBinder;
 import static io.airlift.concurrent.Threads.threadsNamed;
 import static io.airlift.configuration.ConfigurationModule.bindConfig;
 import static io.airlift.discovery.client.DiscoveryBinder.discoveryBinder;
 import static io.airlift.http.server.HttpServerBinder.httpServerBinder;
 import static io.airlift.jaxrs.JaxrsBinder.jaxrsBinder;
 import static io.airlift.json.JsonCodecBinder.jsonCodecBinder;
 import static java.util.concurrent.Executors.newCachedThreadPool;
 import static org.weakref.jmx.ObjectNames.generatedNameOf;
 import static org.weakref.jmx.guice.ExportBinder.newExporter;
 
 public class CoordinatorModule
         implements Module
 {
     @Override
     public void configure(Binder binder)
     {
         // TODO: currently, this module is ALWAYS installed (even for non-coordinators)
 
         httpServerBinder(binder).bindResource("/""webapp").withWelcomeFile("index.html");
 
         discoveryBinder(binder).bindSelector("presto");
 
         // query manager
         jaxrsBinder(binder).bind(QueryResource.class);
         jaxrsBinder(binder).bind(StageResource.class);
         binder.bind(QueryIdGenerator.class).in(.);
         binder.bind(QueryManager.class).to(SqlQueryManager.class).in(.);
         newExporter(binder).export(QueryManager.class).withGeneratedName();
         bindConfig(binder).to(QueryManagerConfig.class);
        // analyzer
        bindConfig(binder).to(FeaturesConfig.class);
        // split manager
        binder.bind(SplitManager.class).in(.);
        // node scheduler
        binder.bind(InternalNodeManager.class).to(DiscoveryNodeManager.class).in(.);
        binder.bind(NodeManager.class).to(Key.get(InternalNodeManager.class)).in(.);
        bindConfig(binder).to(NodeSchedulerConfig.class);
        binder.bind(NodeScheduler.class).in(.);
        binder.bind(NodeTaskMap.class).in(.);
        newExporter(binder).export(NodeScheduler.class).withGeneratedName();
        // query execution
        binder.bind(ExecutorService.class).annotatedWith(ForQueryExecution.class)
                .toInstance(newCachedThreadPool(threadsNamed("query-execution-%d")));
        binder.bind(QueryExecutionMBean.class).in(.);
        MapBinder<Class<? extends Statement>, QueryExecutionFactory<?>> executionBinder = newMapBinder(binder,
                new TypeLiteral<Class<? extends Statement>>() {}, new TypeLiteral<QueryExecutionFactory<?>>() {});
        binder.bind(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(Query.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(Explain.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowColumns.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowPartitions.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowFunctions.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowTables.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowSchemas.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowCatalogs.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(Use.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(ShowSession.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(CreateTable.class).to(SqlQueryExecutionFactory.class).in(.);
        executionBinder.addBinding(Insert.class).to(SqlQueryExecutionFactory.class).in(.);
        binder.bind(DataDefinitionExecutionFactory.class).in(.);
        bindDataDefinitionTask(binderexecutionBinderRenameTable.classRenameTableTask.class);
        bindDataDefinitionTask(binderexecutionBinderDropTable.classDropTableTask.class);
        bindDataDefinitionTask(binderexecutionBinderCreateView.classCreateViewTask.class);
        bindDataDefinitionTask(binderexecutionBinderDropView.classDropViewTask.class);
        bindDataDefinitionTask(binderexecutionBinderSetSession.classSetSessionTask.class);
        bindDataDefinitionTask(binderexecutionBinderResetSession.classResetSessionTask.class);
        jsonCodecBinder(binder).bindJsonCodec(ViewDefinition.class);
    }
    private static <T extends Statementvoid bindDataDefinitionTask(
            Binder binder,
            MapBinder<Class<? extends Statement>, QueryExecutionFactory<?>> executionBinder,
            Class<T> statement,
            Class<? extends DataDefinitionTask<T>> task)
    {
        MapBinder<Class<? extends Statement>, DataDefinitionTask<?>> taskBinder = newMapBinder(binder,
                new TypeLiteral<Class<? extends Statement>>() {}, new TypeLiteral<DataDefinitionTask<?>>() {});
        taskBinder.addBinding(statement).to(task).in(.);
        executionBinder.addBinding(statement).to(DataDefinitionExecutionFactory.class).in(.);
    }
New to GrepCode? Check out our FAQ X