diff options
author | S.W <wimmesberger@gmail.com> | 2019-06-27 09:58:37 +0200 |
---|---|---|
committer | Zhe Sun <31067185+ZheSun88@users.noreply.github.com> | 2019-06-27 10:58:36 +0300 |
commit | 583920f327c338a020d4e09e420548f44127cb7f (patch) | |
tree | 4319908dd2887bd780fb89a64d79c7690721c252 /shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java | |
parent | 4c4d0375c1efdf5d943ee2112bdd2160e0045af7 (diff) | |
download | vaadin-framework-583920f327c338a020d4e09e420548f44127cb7f.tar.gz vaadin-framework-583920f327c338a020d4e09e420548f44127cb7f.zip |
OSGi: Removed static VaadinResourceService access in liferay-integration, osgi-integration (#11335)
* Made VaadinResourceService a OSGi component, removed static access of OsgiVaadinResources
Diffstat (limited to 'shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java')
-rw-r--r-- | shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java index 6f2842d47e..675c33db3f 100644 --- a/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java +++ b/shared/src/main/java/com/vaadin/osgi/resources/OsgiVaadinResources.java @@ -17,9 +17,8 @@ package com.vaadin.osgi.resources; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.Version; - -import com.vaadin.osgi.resources.impl.VaadinResourceServiceImpl; +import org.osgi.framework.ServiceReference; +import org.osgi.util.tracker.ServiceTracker; /** * {@link BundleActivator} used to provide access to the @@ -29,6 +28,8 @@ import com.vaadin.osgi.resources.impl.VaadinResourceServiceImpl; * @author Vaadin Ltd. * * @since 8.1 + * @deprecated use OSGi DS services to bind a instance of + * {@link VaadinResourceService} */ public class OsgiVaadinResources implements BundleActivator { @@ -48,8 +49,8 @@ public class OsgiVaadinResources implements BundleActivator { private static OsgiVaadinResources instance; - private VaadinResourceServiceImpl service; - private Version version; + private ServiceTracker<VaadinResourceService, VaadinResourceService> vaadinResourceTracker; + private VaadinResourceService service; /** * Returns the {@link VaadinResourceService} instance. Always returns @@ -71,16 +72,38 @@ public class OsgiVaadinResources implements BundleActivator { @Override public void start(BundleContext context) throws Exception { - version = context.getBundle().getVersion(); - service = new VaadinResourceServiceImpl(); - service.setBundleVersion(version.toString()); + vaadinResourceTracker = new ServiceTracker<VaadinResourceService, VaadinResourceService>( + context, VaadinResourceService.class, null) { + @Override + public VaadinResourceService addingService( + ServiceReference<VaadinResourceService> reference) { + VaadinResourceService vaadinService = super.addingService( + reference); + service = vaadinService; + return vaadinService; + } + + @Override + public void removedService( + ServiceReference<VaadinResourceService> reference, + VaadinResourceService service) { + super.removedService(reference, service); + if (OsgiVaadinResources.this.service == service) { + OsgiVaadinResources.this.service = null; + } + } + }; + vaadinResourceTracker.open(); instance = this; } @Override public void stop(BundleContext context) throws Exception { + if (vaadinResourceTracker != null) { + vaadinResourceTracker.close(); + } + vaadinResourceTracker = null; instance = null; service = null; - version = null; } } |