diff options
| author | Thomas Watson | 2020-04-02 16:05:24 +0000 |
|---|---|---|
| committer | Thomas Watson | 2020-04-02 16:05:58 +0000 |
| commit | 0178a9353afbe4a71f9800036f889bf3073bfa72 (patch) | |
| tree | 0919a9943ab53e1e44f8188da0e1872f02e87f3f | |
| parent | 7ef2285a5dadfa932f56687aaac80f0925431aa2 (diff) | |
| download | rt.equinox.framework-0178a9353afbe4a71f9800036f889bf3073bfa72.tar.gz rt.equinox.framework-0178a9353afbe4a71f9800036f889bf3073bfa72.tar.xz rt.equinox.framework-0178a9353afbe4a71f9800036f889bf3073bfa72.zip | |
Bug 558514 - [OSGi R8] Core changes for Condition Service RFC 242
Change-Id: I7d27c1fe21d0bfcb4a621f5f5838b1cb029a82c3
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
6 files changed, 168 insertions, 8 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java index 2fef34ec0..75254b1d6 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ConnectTests.java @@ -74,6 +74,7 @@ import org.osgi.framework.wiring.BundleRevision; import org.osgi.framework.wiring.BundleWiring; import org.osgi.framework.wiring.FrameworkWiring; import org.osgi.resource.Namespace; +import org.osgi.service.condition.Condition; public class ConnectTests extends AbstractBundleTests { @@ -390,6 +391,54 @@ public class ConnectTests extends AbstractBundleTests { assertEquals("Wrong number of stop called.", 2, bundleActvatorStopCalled.get()); } + public void testTrueCondition() { + final AtomicReference<ServiceReference<Condition>> trueConditionStart = new AtomicReference<>(); + final AtomicReference<ServiceReference<Condition>> trueConditionStop = new AtomicReference<>(); + + ModuleConnector activatorModuleConnector = new TestCountingModuleConnector() { + @Override + public Optional<BundleActivator> createBundleActivator() { + super.createBundleActivator(); + return Optional.of(new BundleActivator() { + + @Override + public void start(BundleContext context) throws Exception { + trueConditionStart.set(context + .getServiceReferences(Condition.class, + '(' + Condition.CONDITION_ID + '=' + Condition.CONDITION_ID_TRUE + ')') + .iterator().next()); + } + + @Override + public void stop(BundleContext context) throws Exception { + trueConditionStop.set(context + .getServiceReferences(Condition.class, + '(' + Condition.CONDITION_ID + '=' + Condition.CONDITION_ID_TRUE + ')') + .iterator().next()); + } + }); + } + }; + + doTestConnect(activatorModuleConnector, new HashMap<>(), (f) -> { + try { + f.start(); + ServiceReference<Condition> trueCondition = trueConditionStart.get(); + assertNotNull("No true condition found.", trueCondition); + assertEquals("Wrong bundle.", f.getBundleContext().getBundle(), trueCondition.getBundle()); + f.stop(); + f.waitForStop(5000); + + assertEquals("Different true condition found on start and stop.", trueCondition, + trueConditionStop.get()); + assertNull("True condition should be unregistered on stop.", trueCondition.getBundle()); + + } catch (Exception e) { + sneakyThrow(e); + } + }); + } + public void testConnectInit() { final AtomicReference<File> initFile = new AtomicReference<>(); final AtomicReference<File> storeFile = new AtomicReference<>(); diff --git a/bundles/org.eclipse.osgi/.settings/.api_filters b/bundles/org.eclipse.osgi/.settings/.api_filters index e76dc4211..f1f547e91 100644 --- a/bundles/org.eclipse.osgi/.settings/.api_filters +++ b/bundles/org.eclipse.osgi/.settings/.api_filters @@ -52,13 +52,6 @@ </message_arguments> </filter> </resource> - <resource path="osgi/src/org/osgi/framework/connect/ConnectFramework.java" type="org.osgi.framework.connect.ConnectFramework"> - <filter comment="Not for OSGi API" id="1110441988"> - <message_arguments> - <message_argument value="org.osgi.framework.connect.ConnectFramework"/> - </message_arguments> - </filter> - </resource> <resource path="osgi/src/org/osgi/framework/connect/ConnectFrameworkFactory.java" type="org.osgi.framework.connect.ConnectFrameworkFactory"> <filter comment="Not for OSGi API" id="1110441988"> <message_arguments> @@ -116,4 +109,11 @@ </message_arguments> </filter> </resource> + <resource path="osgi/src/org/osgi/service/condition/Condition.java" type="org.osgi.service.condition.Condition"> + <filter comment="Not for OSGi API" id="1110441988"> + <message_arguments> + <message_argument value="org.osgi.service.condition.Condition"/> + </message_arguments> + </filter> + </resource> </component> diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF index 30f45f660..5bac1a7ab 100644 --- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF @@ -68,6 +68,7 @@ Export-Package: org.eclipse.core.runtime.adaptor;x-friends:="org.eclipse.core.ru org.osgi.framework.wiring.dto;version="1.3";uses:="org.osgi.dto,org.osgi.resource.dto", org.osgi.resource;version="1.0", org.osgi.resource.dto;version="1.0";uses:="org.osgi.dto", + org.osgi.service.condition;version="1.0", org.osgi.service.condpermadmin;version="1.1.1";uses:="org.osgi.framework", org.osgi.service.log;version="1.4";uses:="org.osgi.framework", org.osgi.service.log.admin;version="1.0";uses:="org.osgi.service.log", diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java index b1917a102..44e488c18 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/SystemBundleActivator.java @@ -40,6 +40,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.Constants; import org.osgi.framework.ServiceRegistration; +import org.osgi.service.condition.Condition; import org.osgi.service.condpermadmin.ConditionalPermissionAdmin; import org.osgi.service.packageadmin.PackageAdmin; import org.osgi.service.permissionadmin.PermissionAdmin; @@ -72,6 +73,11 @@ public class SystemBundleActivator implements BundleActivator { FrameworkDebugOptions dbgOptions = (FrameworkDebugOptions) configuration.getDebugOptions(); dbgOptions.start(bc); + Hashtable<String, Object> props = new Hashtable<>(7); + props.clear(); + + props.put(Condition.CONDITION_ID, Condition.CONDITION_ID_TRUE); + register(bc, Condition.class, Condition.INSTANCE, false, props); SecurityAdmin sa = bundle.getEquinoxContainer().getStorage().getSecurityAdmin(); ClassLoader tccl = bundle.getEquinoxContainer().getContextFinder(); @@ -84,7 +90,7 @@ public class SystemBundleActivator implements BundleActivator { register(bc, PermissionAdmin.class, sa, null); register(bc, ConditionalPermissionAdmin.class, sa, null); - Hashtable<String, Object> props = new Hashtable<>(7); + props.clear(); props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE); register(bc, Resolver.class, new ResolverImpl(new Logger(0), null), false, props); diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condition/Condition.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condition/Condition.java new file mode 100644 index 000000000..34980301c --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condition/Condition.java @@ -0,0 +1,65 @@ +/* + * Copyright (c) OSGi Alliance (2020). All Rights Reserved. + * + * Licensed 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. + */ + +package org.osgi.service.condition; + +import org.osgi.annotation.versioning.ConsumerType; + +/** + * OSGi due to its modular nature provides <code>Requirements</code> and + * <code>Capabilities</code> to declare what a Bundle needs in order to run + * properly. This is honored by the resolver and enforced by the Framework at + * runtime. The dynamic nature however can provide some impediments at runtime. + * That there is a Bundle that might provide a certain service or capability + * does not mean, that it will be available when and a component expects it be. + * <p> + * Conditions are to the Service Layer what Requirements and Capabilities are to + * the module Layer + * <p> + * The <code>Condition</code> interface is designed to address this issue. Its + * task is to provide a marker that can be tracked if a some Condition is meet + * and for example a Requirement is meet at Runtime. + * <p> + * A Condition must be registered with the {@link Condition#CONDITION_ID} as + * property. + * + * @ThreadSafe + * @author $Id$ + */ +@ConsumerType +public interface Condition { + /** + * Service property identifying a condition's unique identifier. The type of + * this service property is {@code String+} + */ + public static final String CONDITION_ID = "osgi.condition.id"; + + /** + * The unique identifier for the TRUE Condition. The TRUE condition is + * registered by the framework and therefore can always be relied upon. + * + * @see Condition#CONDITION_ID + */ + public static final String CONDITION_ID_TRUE = "true"; + + /** + * A singleton condition instance that can be used to register condition + * services. + */ + public static final Condition INSTANCE = new Condition() { + /* Nothing to do */}; + +} diff --git a/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condition/package-info.java b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condition/package-info.java new file mode 100644 index 000000000..5bcd82de3 --- /dev/null +++ b/bundles/org.eclipse.osgi/osgi/src/org/osgi/service/condition/package-info.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) OSGi Alliance (2013, 2016). All Rights Reserved. + * + * Licensed 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. + */ + +/** + * Condition Service Package Version 1.0. + * <p> + * Bundles wishing to use this package must list the package in the + * Import-Package header of the bundle's manifest. This package has two types of + * users: the consumers that use the API in this package and the providers that + * implement the API in this package. + * <p> + * Example import for consumers using the API in this package: + * <p> + * {@code Import-Package: org.osgi.service.condition; version="[1.0,2.0)"} + * <p> + * Example import for providers implementing the API in this package: + * <p> + * {@code Import-Package: org.osgi.service.condition; version="[1.0,1.1)"} + * + * @author $Id$ + */ + +@Version("1.0") +package org.osgi.service.condition; + +import org.osgi.annotation.versioning.Version; |
