From cb71fdecb62f7f863e8b824816218d554ba96c20 Mon Sep 17 00:00:00 2001 From: Gerd Behrmann Date: Wed, 5 Mar 2014 14:45:42 +0100 Subject: [PATCH] pool: Fix logging context for thread pool Fixes the logging context in a thread pool used by migration tasks, pool to pool tasks, and sticky bit expiration. Target: trunk Request: 2.8 Request: 2.7 Request: 2.6 Acked-by: Tigran Mkrtchyan Patch: http://rb.dcache.org/r/6675/ (cherry picked from commit 4f79cb3dbd2e7662da7f73dacae68a8f129b5101) --- .../util/CDCExecutorServiceDecorator.java | 6 +- .../CDCScheduledExecutorServiceDecorator.java | 63 +++++++++++++++++++ .../org/dcache/pool/classic/pool.xml | 22 ++++--- 3 files changed, 79 insertions(+), 12 deletions(-) create mode 100644 modules/dcache/src/main/java/org/dcache/util/CDCScheduledExecutorServiceDecorator.java diff --git a/modules/dcache/src/main/java/org/dcache/util/CDCExecutorServiceDecorator.java b/modules/dcache/src/main/java/org/dcache/util/CDCExecutorServiceDecorator.java index f3844227fd7..18cc1af61ea 100644 --- a/modules/dcache/src/main/java/org/dcache/util/CDCExecutorServiceDecorator.java +++ b/modules/dcache/src/main/java/org/dcache/util/CDCExecutorServiceDecorator.java @@ -93,7 +93,7 @@ public void execute(Runnable command) _delegate.execute(wrap(command)); } - private Runnable wrap(final Runnable task) + protected Runnable wrap(final Runnable task) { final CDC cdc = new CDC(); return new Runnable() @@ -111,7 +111,7 @@ public void run() }; } - private Callable wrap(final Callable task) + protected Callable wrap(final Callable task) { final CDC cdc = new CDC(); return new Callable() { @@ -128,7 +128,7 @@ public T call() throws Exception }; } - private Collection> wrap(Collection> tasks) + protected Collection> wrap(Collection> tasks) { return Lists.newArrayList(transform(tasks, new Function, Callable>() { diff --git a/modules/dcache/src/main/java/org/dcache/util/CDCScheduledExecutorServiceDecorator.java b/modules/dcache/src/main/java/org/dcache/util/CDCScheduledExecutorServiceDecorator.java new file mode 100644 index 00000000000..26299eb2dd3 --- /dev/null +++ b/modules/dcache/src/main/java/org/dcache/util/CDCScheduledExecutorServiceDecorator.java @@ -0,0 +1,63 @@ +/* dCache - http://www.dcache.org/ + * + * Copyright (C) 2014 Deutsches Elektronen-Synchrotron + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.dcache.util; + +import java.util.concurrent.Callable; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +public class CDCScheduledExecutorServiceDecorator + extends CDCExecutorServiceDecorator + implements ScheduledExecutorService +{ + public CDCScheduledExecutorServiceDecorator(ScheduledExecutorService delegate) + { + super(delegate); + } + + @Override + protected ScheduledExecutorService delegate() + { + return (ScheduledExecutorService) super.delegate(); + } + + @Override + public ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) + { + return delegate().schedule(wrap(command), delay, unit); + } + + @Override + public ScheduledFuture schedule(Callable callable, long delay, TimeUnit unit) + { + return delegate().schedule(wrap(callable), delay, unit); + } + + @Override + public ScheduledFuture scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) + { + return delegate().scheduleAtFixedRate(wrap(command), initialDelay, period, unit); + } + + @Override + public ScheduledFuture scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) + { + return delegate().scheduleWithFixedDelay(wrap(command), initialDelay, delay, unit); + } +} diff --git a/modules/dcache/src/main/resources/org/dcache/pool/classic/pool.xml b/modules/dcache/src/main/resources/org/dcache/pool/classic/pool.xml index 4d1760f1a03..1bb621e61eb 100644 --- a/modules/dcache/src/main/resources/org/dcache/pool/classic/pool.xml +++ b/modules/dcache/src/main/resources/org/dcache/pool/classic/pool.xml @@ -216,15 +216,19 @@ - Thread pool for background tasks - - - + class="org.dcache.util.CDCScheduledExecutorServiceDecorator"> + Thread pool for background tasks + + + + + + +