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.plugins; 16 : 17 : import com.google.common.util.concurrent.Uninterruptibles; 18 : import java.util.concurrent.CountDownLatch; 19 : import java.util.concurrent.TimeUnit; 20 : 21 : class PluginScannerThread extends Thread { 22 13 : private final CountDownLatch done = new CountDownLatch(1); 23 : private final PluginLoader loader; 24 : private final long checkFrequencyMillis; 25 : 26 13 : PluginScannerThread(PluginLoader loader, long checkFrequencyMillis) { 27 13 : this.loader = loader; 28 13 : this.checkFrequencyMillis = checkFrequencyMillis; 29 13 : setDaemon(true); 30 13 : setName("PluginScanner"); 31 13 : } 32 : 33 : @Override 34 : public void run() { 35 : for (; ; ) { 36 : try { 37 0 : if (done.await(checkFrequencyMillis, TimeUnit.MILLISECONDS)) { 38 0 : return; 39 : } 40 0 : } catch (InterruptedException e) { 41 : // Ignored 42 0 : } 43 0 : loader.rescan(); 44 : } 45 : } 46 : 47 : void end() { 48 0 : done.countDown(); 49 0 : Uninterruptibles.joinUninterruptibly(this); 50 0 : } 51 : }