Return-Path: X-Original-To: apmail-camel-dev-archive@www.apache.org Delivered-To: apmail-camel-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C11761023B for ; Sat, 9 Nov 2013 14:51:48 +0000 (UTC) Received: (qmail 44937 invoked by uid 500); 9 Nov 2013 14:51:48 -0000 Delivered-To: apmail-camel-dev-archive@camel.apache.org Received: (qmail 44656 invoked by uid 500); 9 Nov 2013 14:51:47 -0000 Mailing-List: contact dev-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list dev@camel.apache.org Received: (qmail 44647 invoked by uid 99); 9 Nov 2013 14:51:46 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Nov 2013 14:51:46 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of claus.ibsen@gmail.com designates 209.85.223.172 as permitted sender) Received: from [209.85.223.172] (HELO mail-ie0-f172.google.com) (209.85.223.172) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Nov 2013 14:51:41 +0000 Received: by mail-ie0-f172.google.com with SMTP id tp5so5325890ieb.3 for ; Sat, 09 Nov 2013 06:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=XPa5yh1d0nUd1WemWj9eMzBkoN4q7ZnGNAwr2CRLtQM=; b=sro+jt1ojNzwSEdaITFTlFj9uAl6FvWuvVM0QG2bwPKSbJAb44QfYWWNjm8V34xTZq 8CfGPuK6R1CfQH/LjIkFGhbjCZ9HJHl4+CkZfkf6xLFMtrA7HxwPvnaJvsjZZzHZipNC tmQSb+YWlcTaIHnr6FbT6aGHhXXzMydgZPOb6n74dUdke+NrnCtLozPv+doOiz0lN4xo 75tzJRahaI7OgsvYZBsgQFbwQLzC4rb6hKh+eerFBpq98AfWOf4o0TJ3no2Vnm1LhW8e E1xPtPaP4KuPRsMaWMmMQXwMDzBBkvKXFfjPsfAMVr4vJevF8Vhb38/JJKrM6tQobCaX xUIA== X-Received: by 10.50.136.200 with SMTP id qc8mr6557464igb.52.1384008681050; Sat, 09 Nov 2013 06:51:21 -0800 (PST) MIME-Version: 1.0 Received: by 10.64.168.38 with HTTP; Sat, 9 Nov 2013 06:50:59 -0800 (PST) In-Reply-To: References: From: Claus Ibsen Date: Sat, 9 Nov 2013 15:50:59 +0100 Message-ID: Subject: Re: git commit: CAMEL-6948: Releasing a non-singleton producer by ProducerCache should not only stop the producer but also shutdown it as well if it is a ShutdownableService. To: dev Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org Hi There is a stopAndShutdownService method on ServiceHelper in the util package. Its maybe nicer to use to than the type cast. Then you can do that in one command. And this is also how we stop/start/shutdown services in a cleaner way. And if you enabled TRACE/DEBUG logging the service helper can log what happens as well. On Fri, Nov 8, 2013 at 9:46 PM, wrote: > Updated Branches: > refs/heads/master f74ff2cf6 -> f744afd9c > > > CAMEL-6948: Releasing a non-singleton producer by ProducerCache should not only stop the producer but also shutdown it as well if it is a ShutdownableService. > > Project: http://git-wip-us.apache.org/repos/asf/camel/repo > Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f744afd9 > Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f744afd9 > Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f744afd9 > > Branch: refs/heads/master > Commit: f744afd9c39a1fc9261ad68dabe06a51a238fac9 > Parents: f74ff2c > Author: Babak Vahdat > Authored: Fri Nov 8 21:45:59 2013 +0100 > Committer: Babak Vahdat > Committed: Fri Nov 8 21:45:59 2013 +0100 > > ---------------------------------------------------------------------- > .../org/apache/camel/impl/ProducerCache.java | 6 +++ > .../camel/impl/DefaultProducerCacheTest.java | 53 +++++++++++++++++--- > 2 files changed, 51 insertions(+), 8 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/camel/blob/f744afd9/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java > ---------------------------------------------------------------------- > diff --git a/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java b/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java > index 6b292c0..b35eca5 100644 > --- a/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java > +++ b/camel-core/src/main/java/org/apache/camel/impl/ProducerCache.java > @@ -30,6 +30,7 @@ import org.apache.camel.Processor; > import org.apache.camel.Producer; > import org.apache.camel.ProducerCallback; > import org.apache.camel.ServicePoolAware; > +import org.apache.camel.ShutdownableService; > import org.apache.camel.processor.UnitOfWorkProducer; > import org.apache.camel.spi.ServicePool; > import org.apache.camel.support.ServiceSupport; > @@ -137,6 +138,11 @@ public class ProducerCache extends ServiceSupport { > } else if (!producer.isSingleton()) { > // stop non singleton producers as we should not leak resources > producer.stop(); > + > + // shutdown as well in case the producer is shutdownable > + if (producer instanceof ShutdownableService) { > + ShutdownableService.class.cast(producer).shutdown(); > + } > } > } > > > http://git-wip-us.apache.org/repos/asf/camel/blob/f744afd9/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java > ---------------------------------------------------------------------- > diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java > index 5ad0f42..803302c 100644 > --- a/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java > +++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerCacheTest.java > @@ -30,7 +30,8 @@ import org.apache.camel.Producer; > */ > public class DefaultProducerCacheTest extends ContextTestSupport { > > - private static final AtomicInteger COUNTER = new AtomicInteger(); > + private final AtomicInteger stopCounter = new AtomicInteger(); > + private final AtomicInteger shutdownCounter = new AtomicInteger(); > > public void testCacheProducerAcquireAndRelease() throws Exception { > ProducerCache cache = new ProducerCache(this, context); > @@ -56,7 +57,7 @@ public class DefaultProducerCacheTest extends ContextTestSupport { > assertEquals("Size should be 0", 0, cache.size()); > > for (int i = 0; i < 8; i++) { > - Endpoint e = new MyEndpoint(i); > + Endpoint e = new MyEndpoint(true, i); > Producer p = cache.acquireProducer(e); > cache.releaseProducer(e, p); > } > @@ -64,19 +65,50 @@ public class DefaultProducerCacheTest extends ContextTestSupport { > assertEquals("Size should be 5", 5, cache.size()); > > // should have stopped the 3 evicted > - assertEquals(3, COUNTER.get()); > + assertEquals(3, stopCounter.get()); > > cache.stop(); > > // should have stopped all 8 > - assertEquals(8, COUNTER.get()); > + assertEquals(8, stopCounter.get()); > + } > + > + public void testReleaseProducerInvokesStopAndShutdownByNonSingeltonProducers() throws Exception { > + ProducerCache cache = new ProducerCache(this, context, 1); > + cache.start(); > + > + assertEquals("Size should be 0", 0, cache.size()); > + > + for (int i = 0; i < 3; i++) { > + Endpoint e = new MyEndpoint(false, i); > + Producer p = cache.acquireProducer(e); > + cache.releaseProducer(e, p); > + } > + > + assertEquals("Size should be 0", 0, cache.size()); > + > + // should have stopped all 3 > + assertEquals(3, stopCounter.get()); > + > + // should have shutdown all 3 > + assertEquals(3, shutdownCounter.get()); > + > + cache.stop(); > + > + // no more stop after stopping the cache > + assertEquals(3, stopCounter.get()); > + > + // no more shutdown after stopping the cache > + assertEquals(3, shutdownCounter.get()); > } > > private final class MyEndpoint extends DefaultEndpoint { > > - private int number; > + private final boolean isSingleton; > + private final int number; > > - private MyEndpoint(int number) { > + private MyEndpoint(boolean isSingleton, int number) { > + this.isSingleton = isSingleton; > this.number = number; > } > > @@ -92,7 +124,7 @@ public class DefaultProducerCacheTest extends ContextTestSupport { > > @Override > public boolean isSingleton() { > - return true; > + return isSingleton; > } > > @Override > @@ -114,7 +146,12 @@ public class DefaultProducerCacheTest extends ContextTestSupport { > > @Override > protected void doStop() throws Exception { > - COUNTER.incrementAndGet(); > + stopCounter.incrementAndGet(); > + } > + > + @Override > + protected void doShutdown() throws Exception { > + shutdownCounter.incrementAndGet(); > } > } > > -- Claus Ibsen ----------------- Red Hat, Inc. Email: cibsen@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen