summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/implementation-osgi-runtime/src
diff options
context:
space:
mode:
authorrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-05 23:53:06 +0000
committerrfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68>2009-05-05 23:53:06 +0000
commit5a64d330e22e261d3d6fe62cf74a1f158f20608b (patch)
tree76fc2c5ff37d59f962185b6e38fa7373108901d5 /java/sca/modules/implementation-osgi-runtime/src
parent3e47841070daa13c07af89469f4dbecdd0686e2b (diff)
Allow the SCA composite for bundles can be packaged in an external bundle and leave the original bundles as is
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@772014 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/implementation-osgi-runtime/src')
-rw-r--r--java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java31
1 files changed, 24 insertions, 7 deletions
diff --git a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
index ddcd49a235..ab139519c8 100644
--- a/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
+++ b/java/sca/modules/implementation-osgi-runtime/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiImplementationProvider.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.implementation.osgi.runtime;
@@ -38,13 +38,14 @@ import org.apache.tuscany.sca.runtime.RuntimeComponent;
import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
import org.apache.tuscany.sca.runtime.RuntimeComponentService;
import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.oasisopen.sca.ServiceRuntimeException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceRegistration;
/**
- *
+ *
*/
public class OSGiImplementationProvider implements ImplementationProvider {
private RuntimeComponent component;
@@ -66,6 +67,15 @@ public class OSGiImplementationProvider implements ImplementationProvider {
}
public void start() {
+ // First try to start the osgi bundle
+ try {
+ int state = osgiBundle.getState();
+ if ((state & Bundle.STARTING) == 0 && (state & Bundle.ACTIVE) == 0) {
+ osgiBundle.start();
+ }
+ } catch (BundleException e) {
+ throw new ServiceRuntimeException(e);
+ }
for (ComponentReference ref : component.getReferences()) {
RuntimeComponentReference reference = (RuntimeComponentReference)ref;
InterfaceContract interfaceContract = reference.getInterfaceContract();
@@ -88,9 +98,8 @@ public class OSGiImplementationProvider implements ImplementationProvider {
final Object proxy = proxyService.createProxy(interfaceClass, wire);
AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
public ServiceRegistration run() {
- return osgiBundle.getBundleContext().registerService(interfaceClass.getName(),
- proxy,
- osgiProps);
+ return osgiBundle.getBundleContext()
+ .registerService(interfaceClass.getName(), proxy, osgiProps);
}
});
}
@@ -100,6 +109,14 @@ public class OSGiImplementationProvider implements ImplementationProvider {
public void stop() {
// Do we have to unregister the services?
+ try {
+ int state = osgiBundle.getState();
+ if ((state & Bundle.STARTING) == 0) {
+ osgiBundle.stop();
+ }
+ } catch (BundleException e) {
+ throw new ServiceRuntimeException(e);
+ }
}
public boolean supportsOneWayInvocation() {