LCOV - code coverage report
Current view: top level - sshd - CommandExecutorQueueProvider.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 15 17 88.2 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2010 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.sshd;
      16             : 
      17             : import com.google.gerrit.server.config.GerritServerConfig;
      18             : import com.google.gerrit.server.config.ThreadSettingsConfig;
      19             : import com.google.gerrit.server.git.QueueProvider;
      20             : import com.google.gerrit.server.git.WorkQueue;
      21             : import com.google.inject.Inject;
      22             : import com.google.inject.Singleton;
      23             : import java.util.concurrent.ScheduledThreadPoolExecutor;
      24             : import org.eclipse.jgit.lib.Config;
      25             : 
      26             : @Singleton
      27             : public class CommandExecutorQueueProvider implements QueueProvider {
      28             : 
      29             :   private int poolSize;
      30             :   private final int batchThreads;
      31             :   private final ScheduledThreadPoolExecutor interactiveExecutor;
      32             :   private final ScheduledThreadPoolExecutor batchExecutor;
      33             : 
      34             :   @Inject
      35             :   public CommandExecutorQueueProvider(
      36             :       @GerritServerConfig Config config,
      37             :       ThreadSettingsConfig threadsSettingsConfig,
      38          17 :       WorkQueue queues) {
      39          17 :     poolSize = threadsSettingsConfig.getSshdThreads();
      40          17 :     batchThreads =
      41          17 :         config.getInt("sshd", "batchThreads", threadsSettingsConfig.getSshdBatchTreads());
      42          17 :     if (batchThreads > poolSize) {
      43          17 :       poolSize += batchThreads;
      44             :     }
      45          17 :     int interactiveThreads = Math.max(1, poolSize - batchThreads);
      46          17 :     interactiveExecutor =
      47          17 :         queues.createQueue(interactiveThreads, "SSH-Interactive-Worker", Thread.MIN_PRIORITY, true);
      48          17 :     if (batchThreads != 0) {
      49          17 :       batchExecutor =
      50          17 :           queues.createQueue(batchThreads, "SSH-Batch-Worker", Thread.MIN_PRIORITY, true);
      51             :     } else {
      52           0 :       batchExecutor = interactiveExecutor;
      53             :     }
      54          17 :   }
      55             : 
      56             :   @Override
      57             :   public ScheduledThreadPoolExecutor getQueue(QueueType type) {
      58          10 :     switch (type) {
      59             :       case INTERACTIVE:
      60          10 :         return interactiveExecutor;
      61             :       case BATCH:
      62             :       default:
      63           0 :         return batchExecutor;
      64             :     }
      65             :   }
      66             : }

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