summaryrefslogtreecommitdiffstats
path: root/java/sca/samples/dosgi-calculator
diff options
context:
space:
mode:
Diffstat (limited to 'java/sca/samples/dosgi-calculator')
-rw-r--r--java/sca/samples/dosgi-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml67
-rw-r--r--java/sca/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite11
-rw-r--r--java/sca/samples/dosgi-calculator/OSGI-INF/sca/calculator-service.bindings2
-rw-r--r--java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java4
-rw-r--r--java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java9
5 files changed, 10 insertions, 83 deletions
diff --git a/java/sca/samples/dosgi-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml b/java/sca/samples/dosgi-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml
deleted file mode 100644
index da76d00024..0000000000
--- a/java/sca/samples/dosgi-calculator/OSGI-INF/remote-service/calculator-service-descriptions.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-* Licensed to the Apache Software Foundation (ASF) under one
-* or more contributor license agreements. See the NOTICE file
-* distributed with this work for additional information
-* regarding copyright ownership. The ASF licenses this file
-* 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.
--->
-<!-- A consumer-side service description file for RFC 119 -->
-<service-descriptions xmlns="http://www.osgi.org/xmlns/sd/v1.0.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
- <!-- Describe a remote OSGi service -->
- <service-description>
- <provide interface="calculator.dosgi.operations.AddService" />
- <property name="service.intents">sca:SOAP sca:HTTP</property>
- <property name="osgi.remote.configuration.type">sca</property>
- <property name="osgi.remote.configuration.sca.componentType">
- OSGI-INF/sca/bundle.componentType
- </property>
- <property name="osgi.remote.configuration.sca.reference">
- addService
- </property>
- </service-description>
- <service-description>
- <provide interface="calculator.dosgi.operations.SubtractService" />
- <property name="service.intents">sca:SOAP sca:HTTP</property>
- <property name="osgi.remote.configuration.type">sca</property>
- <property name="osgi.remote.configuration.sca.componentType">
- OSGI-INF/sca/bundle.componentType
- </property>
- <property name="osgi.remote.configuration.sca.reference">
- subtractService
- </property>
- </service-description>
- <service-description>
- <provide interface="calculator.dosgi.operations.MultiplyService" />
- <property name="service.intents">sca:SOAP sca:HTTP</property>
- <property name="osgi.remote.configuration.type">sca</property>
- <property name="osgi.remote.configuration.sca.componentType">
- OSGI-INF/sca/bundle.componentType
- </property>
- <property name="osgi.remote.configuration.sca.reference">
- multiplyService
- </property>
- </service-description>
- <service-description>
- <provide interface="calculator.dosgi.operations.DivideService" />
- <property name="service.intents">sca:SOAP sca:HTTP</property>
- <property name="osgi.remote.configuration.type">sca</property>
- <property name="osgi.remote.configuration.sca.componentType">
- OSGI-INF/sca/bundle.componentType
- </property>
- <property name="osgi.remote.configuration.sca.reference">
- divideService
- </property>
- </service-description>
-</service-descriptions> \ No newline at end of file
diff --git a/java/sca/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite b/java/sca/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite
index 2bcd44e970..481fd67e09 100644
--- a/java/sca/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite
+++ b/java/sca/samples/dosgi-calculator/OSGI-INF/sca/bundle.composite
@@ -40,17 +40,6 @@
<reference name="divideService">
<tuscany:binding.rmi uri="rmi://localhost:8085/DivideService"/>
</reference>
-
- <!--
- <reference name="addService" target="OperationsComponent/AddService">
- </reference>
- <reference name="subtractService" target="OperationsComponent/SubtractService">
- </reference>
- <reference name="multiplyService" target="OperationsComponent/MultiplyService">
- </reference>
- <reference name="divideService" target="OperationsComponent/DivideService">
- </reference>
- -->
</component>
</composite>
diff --git a/java/sca/samples/dosgi-calculator/OSGI-INF/sca/calculator-service.bindings b/java/sca/samples/dosgi-calculator/OSGI-INF/sca/calculator-service.bindings
index 65a5a76194..90e55f7377 100644
--- a/java/sca/samples/dosgi-calculator/OSGI-INF/sca/calculator-service.bindings
+++ b/java/sca/samples/dosgi-calculator/OSGI-INF/sca/calculator-service.bindings
@@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
-->
-<!-- A consumer-side service description file for RFC 119 -->
+<!-- SCA bindings for calculator service -->
<bindings xmlns="http://www.osgi.org/xmlns/sd/v1.0.0"
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200903">
<sca:binding.ws uri="http://localhost:8086/CalculatorService"/>
diff --git a/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java b/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java
index 40388144ee..6b42645f69 100644
--- a/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java
+++ b/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorActivator.java
@@ -59,9 +59,7 @@ public class CalculatorActivator implements BundleActivator {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("sca.service", "CalculatorComponent#service-name(Calculator)");
props.put("calculator", "Calculator");
- props.put("service.exported.configs", new String[] {"sca"});
- props.put("sca.bindings", new String[] {"OSGI-INF/sca/calculator-service.bindings"});
- props.put("service.exported.interfaces", new String[] {"*"});
+
logger.info("Registering " + CalculatorService.class.getName());
CalculatorService calculator = new CalculatorServiceImpl(context);
context.registerService(CalculatorService.class.getName(), calculator, props);
diff --git a/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java b/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java
index 932c5fcf15..a9ea37585a 100644
--- a/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java
+++ b/java/sca/samples/dosgi-calculator/src/main/java/calculator/dosgi/impl/CalculatorServiceImpl.java
@@ -60,6 +60,12 @@ public class CalculatorServiceImpl implements CalculatorService {
}
private <T> T getService(Class<T> cls) {
+ try {
+ // Wait for 10 seconds until the remote services are imported
+ remoteServices.waitForService(10000);
+ } catch (InterruptedException e) {
+ throw new IllegalStateException(cls.getSimpleName() + " is not available");
+ }
Object[] remoteObjects = remoteServices.getServices();
if (remoteObjects != null) {
for (Object s : remoteObjects) {
@@ -70,13 +76,14 @@ public class CalculatorServiceImpl implements CalculatorService {
}
}
Object[] localObjects = localServices.getServices();
- if (localObjects != null)
+ if (localObjects != null) {
for (Object s : localObjects) {
if (cls.isInstance(s)) {
System.out.println("Local service: " + s);
return cls.cast(s);
}
}
+ }
throw new IllegalStateException(cls.getSimpleName() + " is not available");
}