Return-Path: X-Original-To: apmail-aries-commits-archive@www.apache.org Delivered-To: apmail-aries-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6473D4744 for ; Sun, 15 May 2011 15:51:09 +0000 (UTC) Received: (qmail 38557 invoked by uid 500); 15 May 2011 15:51:09 -0000 Delivered-To: apmail-aries-commits-archive@aries.apache.org Received: (qmail 38490 invoked by uid 500); 15 May 2011 15:51:09 -0000 Mailing-List: contact commits-help@aries.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@aries.apache.org Delivered-To: mailing list commits@aries.apache.org Received: (qmail 38482 invoked by uid 99); 15 May 2011 15:51:09 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 May 2011 15:51:09 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 15 May 2011 15:51:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 686242388A29; Sun, 15 May 2011 15:50:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1103435 - in /aries/trunk/quiesce/quiesce-manager/src/main: java/org/apache/aries/quiesce/manager/impl/ resources/ resources/org/ resources/org/apache/ resources/org/apache/aries/ resources/org/apache/aries/quiesce/ resources/org/apache/ar... Date: Sun, 15 May 2011 15:50:43 -0000 To: commits@aries.apache.org From: not@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110515155043.686242388A29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: not Date: Sun May 15 15:50:42 2011 New Revision: 1103435 URL: http://svn.apache.org/viewvc?rev=1103435&view=rev Log: ARIES-467 Externalize messages into a properties files Added: aries/trunk/quiesce/quiesce-manager/src/main/resources/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/quiesceMessages.properties (with props) Modified: aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/QuiesceManagerImpl.java Modified: aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/QuiesceManagerImpl.java URL: http://svn.apache.org/viewvc/aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/QuiesceManagerImpl.java?rev=1103435&r1=1103434&r2=1103435&view=diff ============================================================================== --- aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/QuiesceManagerImpl.java (original) +++ aries/trunk/quiesce/quiesce-manager/src/main/java/org/apache/aries/quiesce/manager/impl/QuiesceManagerImpl.java Sun May 15 15:50:42 2011 @@ -35,6 +35,7 @@ import java.util.concurrent.TimeoutExcep import org.apache.aries.quiesce.manager.QuiesceCallback; import org.apache.aries.quiesce.manager.QuiesceManager; import org.apache.aries.quiesce.participant.QuiesceParticipant; +import org.apache.aries.util.nls.MessageUtil; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; @@ -44,9 +45,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class QuiesceManagerImpl implements QuiesceManager { - - /** Logger */ + + /** Logger */ private static final Logger LOGGER = LoggerFactory.getLogger(QuiesceManagerImpl.class.getName()); + /** MessageUtil */ + private static final MessageUtil MESSAGES = MessageUtil.createMessageUtil(QuiesceManagerImpl.class, "org.apache.aries.quiesce.manager.nls.quiesceMessages"); /** The default timeout to use */ private static int defaultTimeout = 60000; /** The container's {@link BundleContext} */ @@ -62,20 +65,20 @@ public class QuiesceManagerImpl implemen /** The thread pool to execute quiesce commands */ private ExecutorService executor = new ThreadPoolExecutor(0, 10, 10, TimeUnit.SECONDS, new LinkedBlockingQueue(),new ThreadFactory() { - - public Thread newThread(Runnable arg0) { - Thread t = new Thread(arg0, "Quiesce Manager Thread"); - t.setDaemon(true); - return t; - } - }); + + public Thread newThread(Runnable arg0) { + Thread t = new Thread(arg0, "Quiesce Manager Thread"); + t.setDaemon(true); + return t; + } + }); /** The map of bundles that are currently being quiesced */ private static ConcurrentHashMap bundleMap = new ConcurrentHashMap(); public QuiesceManagerImpl(BundleContext bc) { - bundleContext = bc; + bundleContext = bc; } /** @@ -104,7 +107,7 @@ public class QuiesceManagerImpl implemen if (priorBundle == null) { bundlesToQuiesce.add(b); }else{ - LOGGER.warn("Already quiescing bundle "+ b.getSymbolicName()); + LOGGER.warn(MESSAGES.getMessage("already.quiescing.bundle", b.getSymbolicName() + '/' + b.getVersion())); } } Runnable command = new BundleQuiescer(bundlesToQuiesce, timeout, result, bundleMap); @@ -122,7 +125,7 @@ public class QuiesceManagerImpl implemen private CountDownLatch latch = new CountDownLatch(1); public boolean cancel(boolean mayInterruptIfRunning) { - throw new UnsupportedOperationException("Quiesce operations can be cancelled"); + throw new UnsupportedOperationException(MESSAGES.getMessage("quiesce.cannot.be.canceled")); } public Object get() throws InterruptedException, ExecutionException { @@ -161,7 +164,7 @@ public class QuiesceManagerImpl implemen * resulting stop events. */ public void quiesce(List bundlesToQuiesce) { - quiesce(defaultTimeout, bundlesToQuiesce); + quiesce(defaultTimeout, bundlesToQuiesce); } /** @@ -174,17 +177,17 @@ public class QuiesceManagerImpl implemen * @return */ private static boolean stopBundle(Bundle bundleToStop, Set bundlesToStop) { - try { - synchronized (bundlesToStop) { - if (bundlesToStop.remove(bundleToStop)) { - bundleToStop.stop(); - bundleMap.remove(bundleToStop); - } - } - } catch (BundleException be) { - return false; - } - return true; + try { + synchronized (bundlesToStop) { + if (bundlesToStop.remove(bundleToStop)) { + bundleToStop.stop(); + bundleMap.remove(bundleToStop); + } + } + } catch (BundleException be) { + return false; + } + return true; } private static boolean stillQuiescing(Bundle bundleToStop) { @@ -200,60 +203,58 @@ public class QuiesceManagerImpl implemen * and removes the bundles from the list of those that are being quiesced. */ private class BundleQuiescer implements Runnable { - - private final Set bundlesToQuiesce; - private final long timeout; - private final QuiesceFuture future; - - public BundleQuiescer(Set bundlesToQuiesce, long timeout, QuiesceFuture future, ConcurrentHashMap bundleMap) { - this.bundlesToQuiesce = new HashSet(bundlesToQuiesce); - this.timeout = timeout; - this.future = future; - } - - public void run() { - try { - if (bundleContext != null) { - ServiceReference[] serviceRefs = bundleContext.getServiceReferences(QuiesceParticipant.class.getName(), null); - if (serviceRefs != null) { - List participants = new ArrayList(); - final List callbacks = new ArrayList(); - List copyOfBundles = new ArrayList(bundlesToQuiesce); - - ScheduledFuture timeoutFuture = timeoutExecutor.schedule(new Runnable() { - public void run() { - try { - LOGGER.warn("Quiesce timed out"); - synchronized (bundlesToQuiesce) { - for (Bundle b : new ArrayList(bundlesToQuiesce)) { - LOGGER.warn("Could not quiesce within timeout, so stopping bundle "+ b.getSymbolicName()); - stopBundle(b, bundlesToQuiesce); - } - } - } finally { - future.registerDone(); - LOGGER.debug("Quiesce complete"); - } - } - }, timeout, TimeUnit.MILLISECONDS); - - - //Create callback objects for all participants - for( ServiceReference sr : serviceRefs ) { - QuiesceParticipant participant = (QuiesceParticipant) bundleContext.getService(sr); - participants.add(participant); - callbacks.add(new QuiesceCallbackImpl(bundlesToQuiesce, callbacks, future, timeoutFuture)); - } - - //Quiesce each participant and wait for an interrupt from a callback - //object when all are quiesced, or the timeout to be reached - for( int i=0; i bundlesToQuiesce; + private final long timeout; + private final QuiesceFuture future; + + public BundleQuiescer(Set bundlesToQuiesce, long timeout, QuiesceFuture future, ConcurrentHashMap bundleMap) { + this.bundlesToQuiesce = new HashSet(bundlesToQuiesce); + this.timeout = timeout; + this.future = future; + } + + public void run() { + try { + if (bundleContext != null) { + ServiceReference[] serviceRefs = bundleContext.getServiceReferences(QuiesceParticipant.class.getName(), null); + if (serviceRefs != null) { + List participants = new ArrayList(); + final List callbacks = new ArrayList(); + List copyOfBundles = new ArrayList(bundlesToQuiesce); + + ScheduledFuture timeoutFuture = timeoutExecutor.schedule(new Runnable() { + public void run() { + try { + synchronized (bundlesToQuiesce) { + for (Bundle b : new ArrayList(bundlesToQuiesce)) { + LOGGER.warn(MESSAGES.getMessage("quiesce.failed", b.getSymbolicName() + '/' + b.getVersion())); + stopBundle(b, bundlesToQuiesce); + } + } + } finally { + future.registerDone(); + LOGGER.debug("Quiesce complete"); + } + } + }, timeout, TimeUnit.MILLISECONDS); + + + //Create callback objects for all participants + for( ServiceReference sr : serviceRefs ) { + QuiesceParticipant participant = (QuiesceParticipant) bundleContext.getService(sr); + participants.add(participant); + callbacks.add(new QuiesceCallbackImpl(bundlesToQuiesce, callbacks, future, timeoutFuture)); + } + + //Quiesce each participant and wait for an interrupt from a callback + //object when all are quiesced, or the timeout to be reached + for( int i=0; i toQuiesce; - // Must not be a copy - private final Set toQuiesceShared; - //Must not be a copy - private final List allCallbacks; - //Timer so we can cancel the alarm if all done - private final QuiesceFuture future; - //The cleanup action that runs at timeout - private final ScheduledFuture timeoutFuture; - - public QuiesceCallbackImpl(Set toQuiesce, List allCallbacks, QuiesceFuture future, ScheduledFuture timeoutFuture) - { - this.toQuiesce = new HashSet(toQuiesce); - this.toQuiesceShared = toQuiesce; - this.allCallbacks = allCallbacks; - this.future = future; - this.timeoutFuture = timeoutFuture; - } - - /** - * Removes the bundles from the list of those to quiesce. - * If the list is now empty, this callback object is finished (i.e. - * the participant linked to this object has quiesced all the bundles - * requested). - * - * If all other participants have also completed, then the - * calling BundleQuieser thread is interrupted. - */ - public void bundleQuiesced(Bundle... bundlesQuiesced) { - + //Must be a copy + private final Set toQuiesce; + // Must not be a copy + private final Set toQuiesceShared; + //Must not be a copy + private final List allCallbacks; + //Timer so we can cancel the alarm if all done + private final QuiesceFuture future; + //The cleanup action that runs at timeout + private final ScheduledFuture timeoutFuture; + + public QuiesceCallbackImpl(Set toQuiesce, List allCallbacks, QuiesceFuture future, ScheduledFuture timeoutFuture) + { + this.toQuiesce = new HashSet(toQuiesce); + this.toQuiesceShared = toQuiesce; + this.allCallbacks = allCallbacks; + this.future = future; + this.timeoutFuture = timeoutFuture; + } + + /** + * Removes the bundles from the list of those to quiesce. + * If the list is now empty, this callback object is finished (i.e. + * the participant linked to this object has quiesced all the bundles + * requested). + * + * If all other participants have also completed, then the + * calling BundleQuieser thread is interrupted. + */ + public void bundleQuiesced(Bundle... bundlesQuiesced) { + boolean timeoutOccurred = false; synchronized (allCallbacks) { @@ -332,26 +333,26 @@ public class QuiesceManagerImpl implemen it.next().toQuiesce.clear(); } } - } - } + } + } - private boolean checkOthers(Bundle b) { - boolean allDone = true; - Iterator it = allCallbacks.iterator(); - while (allDone && it.hasNext()) { - allDone = !!!it.next().toQuiesce.contains(b); - } - return allDone; - } - - private boolean allCallbacksComplete() { - boolean allDone = true; - Iterator it = allCallbacks.iterator(); - while (allDone && it.hasNext()) { + private boolean checkOthers(Bundle b) { + boolean allDone = true; + Iterator it = allCallbacks.iterator(); + while (allDone && it.hasNext()) { + allDone = !!!it.next().toQuiesce.contains(b); + } + return allDone; + } + + private boolean allCallbacksComplete() { + boolean allDone = true; + Iterator it = allCallbacks.iterator(); + while (allDone && it.hasNext()) { QuiesceCallbackImpl next = it.next(); if (!!!next.toQuiesce.isEmpty()) allDone = false; - } - return allDone; - } + } + return allDone; + } } } \ No newline at end of file Added: aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/quiesceMessages.properties URL: http://svn.apache.org/viewvc/aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/quiesceMessages.properties?rev=1103435&view=auto ============================================================================== --- aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/quiesceMessages.properties (added) +++ aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/quiesceMessages.properties Sun May 15 15:50:42 2011 @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. +# + +# {0} Already queiscing the bundle +already.quiescing.bundle=The bundle {0} is already being quiesced. +quiesce.cannot.be.canceled=Quiesce operations cannot be cancelled. +# {0} The bundle identity +# {1} The timeout in milliseconds +quiesce.failed=Could not quiesce the bundle {0} within {1,number,integer} milliseconds. The bundle will be stopped. +null.is.invalid.filter=Unexpected error. The OSGi framework has decided null is no longer a valid filter. Propchange: aries/trunk/quiesce/quiesce-manager/src/main/resources/org/apache/aries/quiesce/manager/nls/quiesceMessages.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain