LCOV - code coverage report
Current view: top level - server/config - SysExecutorModule.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 18 83.3 %
Date: 2022-11-19 15:00:39 Functions: 6 6 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2012 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.config;
      16             : 
      17             : import static com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService;
      18             : 
      19             : import com.google.common.util.concurrent.ListeningExecutorService;
      20             : import com.google.common.util.concurrent.MoreExecutors;
      21             : import com.google.gerrit.server.CacheRefreshExecutor;
      22             : import com.google.gerrit.server.FanOutExecutor;
      23             : import com.google.gerrit.server.git.WorkQueue;
      24             : import com.google.inject.AbstractModule;
      25             : import com.google.inject.Provides;
      26             : import com.google.inject.Singleton;
      27             : import java.util.concurrent.ExecutorService;
      28             : import org.eclipse.jgit.lib.Config;
      29             : 
      30             : /**
      31             :  * Module providing different executors.
      32             :  *
      33             :  * <p>This module is intended to be installed at the top level when creating a {@code sysInjector}
      34             :  * in {@code Daemon} or similar, not nested in another module. This ensures the module can be
      35             :  * swapped out for the googlesource.com implementation.
      36             :  */
      37         138 : public class SysExecutorModule extends AbstractModule {
      38             :   @Override
      39         138 :   protected void configure() {}
      40             : 
      41             :   @Provides
      42             :   @Singleton
      43             :   @ReceiveCommitsExecutor
      44             :   public ExecutorService provideReceiveCommitsExecutor(
      45             :       @GerritServerConfig Config config, WorkQueue queues) {
      46         138 :     int poolSize =
      47         138 :         config.getInt(
      48         138 :             "receive", null, "threadPoolSize", Runtime.getRuntime().availableProcessors());
      49         138 :     return queues.createQueue(poolSize, "ReceiveCommits", true);
      50             :   }
      51             : 
      52             :   @Provides
      53             :   @Singleton
      54             :   @SendEmailExecutor
      55             :   public ExecutorService provideSendEmailExecutor(
      56             :       @GerritServerConfig Config config, WorkQueue queues) {
      57         138 :     int poolSize = config.getInt("sendemail", null, "threadPoolSize", 1);
      58         138 :     if (poolSize == 0) {
      59         138 :       return newDirectExecutorService();
      60             :     }
      61           0 :     return queues.createQueue(poolSize, "SendEmail", true);
      62             :   }
      63             : 
      64             :   @Provides
      65             :   @Singleton
      66             :   @FanOutExecutor
      67             :   public ExecutorService provideFanOutExecutor(
      68             :       @GerritServerConfig Config config, WorkQueue queues) {
      69         138 :     int poolSize = config.getInt("execution", null, "fanOutThreadPoolSize", 25);
      70         138 :     if (poolSize == 0) {
      71           0 :       return newDirectExecutorService();
      72             :     }
      73         138 :     return queues.createQueue(poolSize, "FanOut");
      74             :   }
      75             : 
      76             :   @Provides
      77             :   @Singleton
      78             :   @CacheRefreshExecutor
      79             :   public ListeningExecutorService provideCacheRefreshExecutor(
      80             :       @GerritServerConfig Config config, WorkQueue queues) {
      81         138 :     int poolSize = config.getInt("cache", null, "refreshThreadPoolSize", 2);
      82         138 :     if (poolSize == 0) {
      83           0 :       return newDirectExecutorService();
      84             :     }
      85         138 :     return MoreExecutors.listeningDecorator(queues.createQueue(poolSize, "CacheRefresh"));
      86             :   }
      87             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750