Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-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 A2C50108F0 for ; Fri, 6 Dec 2013 09:23:52 +0000 (UTC) Received: (qmail 50459 invoked by uid 500); 6 Dec 2013 09:22:43 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 50149 invoked by uid 500); 6 Dec 2013 09:22:38 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 49946 invoked by uid 99); 6 Dec 2013 09:22:31 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 06 Dec 2013 09:22:31 +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; Fri, 06 Dec 2013 09:22:30 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9470523889ED; Fri, 6 Dec 2013 09:22:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1548460 - /felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java Date: Fri, 06 Dec 2013 09:22:10 -0000 To: commits@felix.apache.org From: gnodet@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131206092210.9470523889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gnodet Date: Fri Dec 6 09:22:10 2013 New Revision: 1548460 URL: http://svn.apache.org/r1548460 Log: [FELIX-4328] Provide a scoping mechanism to limit bundles to be refreshed Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java Modified: felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java URL: http://svn.apache.org/viewvc/felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java?rev=1548460&r1=1548459&r2=1548460&view=diff ============================================================================== --- felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java (original) +++ felix/trunk/fileinstall/src/main/java/org/apache/felix/fileinstall/internal/DirectoryWatcher.java Fri Dec 6 09:22:10 2013 @@ -103,6 +103,12 @@ public class DirectoryWatcher extends Th public final static String START_LEVEL = "felix.fileinstall.start.level"; public final static String ACTIVE_LEVEL = "felix.fileinstall.active.level"; public final static String UPDATE_WITH_LISTENERS = "felix.fileinstall.bundles.updateWithListeners"; + public final static String OPTIONAL_SCOPE = "felix.fileinstall.optionalImportRefreshScope"; + public final static String FRAGMENT_SCOPE = "felix.fileinstall.fragmentRefreshScope"; + + public final static String SCOPE_NONE = "none"; + public final static String SCOPE_MANAGED = "managed"; + public final static String SCOPE_ALL = "all"; static final SecureRandom random = new SecureRandom(); @@ -123,6 +129,8 @@ public class DirectoryWatcher extends Th int startLevel; int activeLevel; boolean updateWithListeners; + String fragmentScope; + String optionalScope; // Map of all installed artifacts Map/* */ currentManagedArtifacts = new HashMap/* */(); @@ -159,6 +167,8 @@ public class DirectoryWatcher extends Th startLevel = getInt(properties, START_LEVEL, 0); // by default, do not touch start level activeLevel = getInt(properties, ACTIVE_LEVEL, 0); // by default, always scan updateWithListeners = getBoolean(properties, UPDATE_WITH_LISTENERS, false); // Do not update bundles when listeners are updated + fragmentScope = (String) properties.get(FRAGMENT_SCOPE); + optionalScope = (String) properties.get(OPTIONAL_SCOPE); this.context.addBundleListener(this); FilenameFilter flt; @@ -1257,8 +1267,33 @@ public class DirectoryWatcher extends Th return false; } + protected Set getScopedBundles(String scope) { + // No bundles to check + if (SCOPE_NONE.equals(scope)) { + return new HashSet(); + } + // Go through managed bundles + else if (SCOPE_MANAGED.equals(scope)) { + Set bundles = new HashSet(); + for (Iterator it = currentManagedArtifacts.values().iterator(); it.hasNext();) { + Artifact artifact = (Artifact) it.next(); + if (artifact.getBundleId() > 0) { + Bundle bundle = context.getBundle(artifact.getBundleId()); + if (bundle != null) { + bundles.add(bundle); + } + } + } + return bundles; + // Go through all bundles + } else { + return new HashSet(Arrays.asList(context.getBundles())); + } + } + protected void findBundlesWithFragmentsToRefresh(Set toRefresh) { Set fragments = new HashSet(); + Set bundles = getScopedBundles(fragmentScope); for (Iterator iterator = toRefresh.iterator(); iterator.hasNext();) { Bundle b = (Bundle) iterator.next(); if (b.getState() != Bundle.UNINSTALLED) { @@ -1267,9 +1302,8 @@ public class DirectoryWatcher extends Th Clause[] clauses = Parser.parseHeader(hostHeader); if (clauses != null && clauses.length > 0) { Clause path = clauses[0]; - Bundle[] bundles = context.getBundles(); - for (int i = 0; i < bundles.length; i++) { - Bundle hostBundle = bundles[i]; + for (Iterator it = bundles.iterator(); it.hasNext();) { + Bundle hostBundle = (Bundle) it.next(); if (hostBundle.getSymbolicName().equals(path.getName())) { String ver = path.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE); if (ver != null) { @@ -1290,8 +1324,8 @@ public class DirectoryWatcher extends Th } protected void findBundlesWithOptionalPackagesToRefresh(Set toRefresh) { + Set bundles = getScopedBundles(optionalScope); // First pass: include all bundles contained in these features - Set bundles = new HashSet(Arrays.asList(context.getBundles())); bundles.removeAll(toRefresh); if (bundles.isEmpty()) { return;