LCOV - code coverage report
Current view: top level - server/logging - LoggingContextAwareScheduledExecutorService.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 6 9 66.7 %
Date: 2022-11-19 15:00:39 Functions: 3 5 60.0 %

          Line data    Source code
       1             : // Copyright (C) 2018 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.logging;
      16             : 
      17             : import java.util.concurrent.Callable;
      18             : import java.util.concurrent.ScheduledExecutorService;
      19             : import java.util.concurrent.ScheduledFuture;
      20             : import java.util.concurrent.TimeUnit;
      21             : 
      22             : /**
      23             :  * A {@link ScheduledExecutorService} that copies the {@link LoggingContext} on executing a {@link
      24             :  * Runnable} to the executing thread.
      25             :  */
      26             : public class LoggingContextAwareScheduledExecutorService extends LoggingContextAwareExecutorService
      27             :     implements ScheduledExecutorService {
      28             :   private final ScheduledExecutorService scheduledExecutorService;
      29             : 
      30             :   public LoggingContextAwareScheduledExecutorService(
      31             :       ScheduledExecutorService scheduledExecutorService) {
      32          21 :     super(scheduledExecutorService);
      33          21 :     this.scheduledExecutorService = scheduledExecutorService;
      34          21 :   }
      35             : 
      36             :   @Override
      37             :   public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
      38          15 :     return scheduledExecutorService.schedule(LoggingContext.copy(command), delay, unit);
      39             :   }
      40             : 
      41             :   @Override
      42             :   public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit) {
      43           0 :     return scheduledExecutorService.schedule(LoggingContext.copy(callable), delay, unit);
      44             :   }
      45             : 
      46             :   @Override
      47             :   public ScheduledFuture<?> scheduleAtFixedRate(
      48             :       Runnable command, long initialDelay, long period, TimeUnit unit) {
      49           7 :     return scheduledExecutorService.scheduleAtFixedRate(
      50           7 :         LoggingContext.copy(command), initialDelay, period, unit);
      51             :   }
      52             : 
      53             :   @Override
      54             :   public ScheduledFuture<?> scheduleWithFixedDelay(
      55             :       Runnable command, long initialDelay, long delay, TimeUnit unit) {
      56           0 :     return scheduledExecutorService.scheduleWithFixedDelay(
      57           0 :         LoggingContext.copy(command), initialDelay, delay, unit);
      58             :   }
      59             : }

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