diff options
Diffstat (limited to 'gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollectionRunner.java')
-rw-r--r-- | gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollectionRunner.java | 91 |
1 files changed, 0 insertions, 91 deletions
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollectionRunner.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollectionRunner.java deleted file mode 100644 index 4d8a61f47d..0000000000 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/GarbageCollectionRunner.java +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2014 The Android Open Source Project -// -// 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.google.gerrit.server.git; - -import static com.google.gerrit.server.config.ScheduleConfig.MISSING_CONFIG; - -import com.google.common.collect.Lists; -import com.google.gerrit.extensions.events.LifecycleListener; -import com.google.gerrit.server.config.GcConfig; -import com.google.gerrit.server.config.ScheduleConfig; -import com.google.gerrit.server.project.ProjectCache; -import com.google.inject.Inject; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** Runnable to enable scheduling gc to run periodically */ -public class GarbageCollectionRunner implements Runnable { - private static final Logger gcLog = LoggerFactory.getLogger(GarbageCollection.LOG_NAME); - private static final Logger log = LoggerFactory.getLogger(GarbageCollectionRunner.class); - - static class Lifecycle implements LifecycleListener { - private final WorkQueue queue; - private final GarbageCollectionRunner gcRunner; - private final GcConfig gcConfig; - - @Inject - Lifecycle(WorkQueue queue, GarbageCollectionRunner gcRunner, GcConfig config) { - this.queue = queue; - this.gcRunner = gcRunner; - this.gcConfig = config; - } - - @Override - public void start() { - ScheduleConfig scheduleConfig = gcConfig.getScheduleConfig(); - long interval = scheduleConfig.getInterval(); - long delay = scheduleConfig.getInitialDelay(); - if (delay == MISSING_CONFIG && interval == MISSING_CONFIG) { - log.info("Ignoring missing gc schedule configuration"); - } else if (delay < 0 || interval <= 0) { - log.warn("Ignoring invalid gc schedule configuration: {}", scheduleConfig); - } else { - @SuppressWarnings("unused") - Future<?> possiblyIgnoredError = - queue - .getDefaultQueue() - .scheduleAtFixedRate(gcRunner, delay, interval, TimeUnit.MILLISECONDS); - } - } - - @Override - public void stop() { - // handled by WorkQueue.stop() already - } - } - - private final GarbageCollection.Factory garbageCollectionFactory; - private final ProjectCache projectCache; - - @Inject - GarbageCollectionRunner( - GarbageCollection.Factory garbageCollectionFactory, ProjectCache projectCache) { - this.garbageCollectionFactory = garbageCollectionFactory; - this.projectCache = projectCache; - } - - @Override - public void run() { - gcLog.info("Triggering gc on all repositories"); - garbageCollectionFactory.create().run(Lists.newArrayList(projectCache.all())); - } - - @Override - public String toString() { - return "GC runner"; - } -} |