[09/12] incubator-tamaya git commit: TAMAYA-274: Fixed basic service loading in OSGI. Added missing requirements.
TAMAYA-274: Fixed basic service loading in OSGI. Added missing requirements. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/ec4079dc Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/ec4079dc Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/ec4079dc Branch: refs/heads/master Commit: ec4079dc3205c3825e6287be8d17013b91ade8e0 Parents: 48af147 Author: anatoleAuthored: Sun Sep 17 01:51:20 2017 +0200 Committer: Anatole Tresch Committed: Thu Sep 28 22:01:27 2017 +0200 -- .../tamaya/core/internal/OSGIServiceLoader.java | 96 +--- .../examples/minimal/TestConfigProvider.java| 49 ++ 2 files changed, 110 insertions(+), 35 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/ec4079dc/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java -- diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java index 4c12df9..0854b0d 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java +++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java @@ -48,6 +48,13 @@ public class OSGIServiceLoader implements BundleListener { public OSGIServiceLoader(BundleContext context){ this.context = Objects.requireNonNull(context); +// Check for matching bundles already installed... +for(Bundle bundle:context.getBundles()){ +switch(bundle.getState()){ +case Bundle.ACTIVE: +checkAndLoadBundle(bundle); +} +} } public BundleContext getBundleContext(){ @@ -62,38 +69,46 @@ public class OSGIServiceLoader implements BundleListener { @Override public void bundleChanged(BundleEvent bundleEvent) { -// Parse and create metadata on STARTING -if (bundleEvent.getType() == BundleEvent.STARTING) { +// Parse and create metadata when installed +if (bundleEvent.getType() == BundleEvent.STARTED) { Bundle bundle = bundleEvent.getBundle(); -if (bundle.getEntry(META_INF_SERVICES) == null) { -return; -} -synchronized (resourceBundles){ -resourceBundles.add(bundle); -log.info("Registered ServiceLoader bundle: " + bundle.getSymbolicName()); -} -Enumeration entryPaths = bundle.getEntryPaths("META-INF/services/"); -while (entryPaths.hasMoreElements()) { -String entryPath = entryPaths.nextElement(); -if(!entryPath.endsWith("/")) { -processEntryPath(bundle, entryPath); -} -} -} else if (bundleEvent.getType() == BundleEvent.STOPPING) { +checkAndLoadBundle(bundle); +} else if (bundleEvent.getType() == BundleEvent.STOPPED) { Bundle bundle = bundleEvent.getBundle(); -if (bundle.getEntry(META_INF_SERVICES) == null) { -return; -} -synchronized (resourceBundles) { -resourceBundles.remove(bundle); -log.finest("Unregistered ServiceLoader bundle: " + bundle.getSymbolicName()); +checkAndUnloadBundle(bundle); +} +} + +private void checkAndUnloadBundle(Bundle bundle) { +if (bundle.getEntry(META_INF_SERVICES) == null) { +return; +} +synchronized (resourceBundles) { +resourceBundles.remove(bundle); +log.fine("Unregistered ServiceLoader bundle: " + bundle.getSymbolicName()); +} +Enumeration entryPaths = bundle.getEntryPaths("META-INF/services/"); +while (entryPaths.hasMoreElements()) { +String entryPath = entryPaths.nextElement(); +if(!entryPath.endsWith("/")) { +removeEntryPath(bundle, entryPath); } -Enumeration entryPaths = bundle.getEntryPaths("META-INF/services/"); -while (entryPaths.hasMoreElements()) { -String entryPath = entryPaths.nextElement(); -if(!entryPath.endsWith("/")) { -removeEntryPath(bundle, entryPath); -} +} +} + +private void checkAndLoadBundle(Bundle bundle) { +if (bundle.getEntry(META_INF_SERVICES) == null) { +return; +} +synchronized (resourceBundles){ +resourceBundles.add(bundle); +log.info("Registered ServiceLoader
incubator-tamaya git commit: TAMAYA-274: Fixed basic service loading in OSGI. Added missing requirements.
Repository: incubator-tamaya Updated Branches: refs/heads/java8 23123bb72 -> 6010c606c TAMAYA-274: Fixed basic service loading in OSGI. Added missing requirements. Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/6010c606 Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/6010c606 Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/6010c606 Branch: refs/heads/java8 Commit: 6010c606cdccd0121c064b7ba6a32a7ed71c9ab5 Parents: 23123bb Author: anatoleAuthored: Sun Sep 17 01:51:20 2017 +0200 Committer: anatole Committed: Sun Sep 17 01:51:20 2017 +0200 -- .../tamaya/core/internal/OSGIServiceLoader.java | 96 +--- .../examples/minimal/TestConfigProvider.java| 49 ++ 2 files changed, 110 insertions(+), 35 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/6010c606/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java -- diff --git a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java index 4c12df9..0854b0d 100644 --- a/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java +++ b/code/core/src/main/java/org/apache/tamaya/core/internal/OSGIServiceLoader.java @@ -48,6 +48,13 @@ public class OSGIServiceLoader implements BundleListener { public OSGIServiceLoader(BundleContext context){ this.context = Objects.requireNonNull(context); +// Check for matching bundles already installed... +for(Bundle bundle:context.getBundles()){ +switch(bundle.getState()){ +case Bundle.ACTIVE: +checkAndLoadBundle(bundle); +} +} } public BundleContext getBundleContext(){ @@ -62,38 +69,46 @@ public class OSGIServiceLoader implements BundleListener { @Override public void bundleChanged(BundleEvent bundleEvent) { -// Parse and create metadata on STARTING -if (bundleEvent.getType() == BundleEvent.STARTING) { +// Parse and create metadata when installed +if (bundleEvent.getType() == BundleEvent.STARTED) { Bundle bundle = bundleEvent.getBundle(); -if (bundle.getEntry(META_INF_SERVICES) == null) { -return; -} -synchronized (resourceBundles){ -resourceBundles.add(bundle); -log.info("Registered ServiceLoader bundle: " + bundle.getSymbolicName()); -} -Enumeration entryPaths = bundle.getEntryPaths("META-INF/services/"); -while (entryPaths.hasMoreElements()) { -String entryPath = entryPaths.nextElement(); -if(!entryPath.endsWith("/")) { -processEntryPath(bundle, entryPath); -} -} -} else if (bundleEvent.getType() == BundleEvent.STOPPING) { +checkAndLoadBundle(bundle); +} else if (bundleEvent.getType() == BundleEvent.STOPPED) { Bundle bundle = bundleEvent.getBundle(); -if (bundle.getEntry(META_INF_SERVICES) == null) { -return; -} -synchronized (resourceBundles) { -resourceBundles.remove(bundle); -log.finest("Unregistered ServiceLoader bundle: " + bundle.getSymbolicName()); +checkAndUnloadBundle(bundle); +} +} + +private void checkAndUnloadBundle(Bundle bundle) { +if (bundle.getEntry(META_INF_SERVICES) == null) { +return; +} +synchronized (resourceBundles) { +resourceBundles.remove(bundle); +log.fine("Unregistered ServiceLoader bundle: " + bundle.getSymbolicName()); +} +Enumeration entryPaths = bundle.getEntryPaths("META-INF/services/"); +while (entryPaths.hasMoreElements()) { +String entryPath = entryPaths.nextElement(); +if(!entryPath.endsWith("/")) { +removeEntryPath(bundle, entryPath); } -Enumeration entryPaths = bundle.getEntryPaths("META-INF/services/"); -while (entryPaths.hasMoreElements()) { -String entryPath = entryPaths.nextElement(); -if(!entryPath.endsWith("/")) { -removeEntryPath(bundle, entryPath); -} +} +} + +private void checkAndLoadBundle(Bundle bundle) { +if (bundle.getEntry(META_INF_SERVICES) == null) { +return; +} +synchronized (resourceBundles){ +