diff options
Diffstat (limited to 'sandbox/slaws')
8 files changed, 182 insertions, 80 deletions
diff --git a/sandbox/slaws/runtimecompat/1xlauncher/pom.xml b/sandbox/slaws/runtimecompat/1xlauncher/pom.xml index 4f7efb592f..1a6ec03230 100644 --- a/sandbox/slaws/runtimecompat/1xlauncher/pom.xml +++ b/sandbox/slaws/runtimecompat/1xlauncher/pom.xml @@ -58,7 +58,7 @@ </dependencies> <build> - <finalName>${artifactId}</finalName> + <!-- finalName>${artifactId}</finalName--> <plugins> <plugin> diff --git a/sandbox/slaws/runtimecompat/1xlauncher/src/main/java/calculator/CalculatorService.java b/sandbox/slaws/runtimecompat/1xlauncher/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/sandbox/slaws/runtimecompat/1xlauncher/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * 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. + */ +package calculator; + + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sandbox/slaws/runtimecompat/1xlauncher/src/main/resources/logging.properties b/sandbox/slaws/runtimecompat/1xlauncher/src/main/resources/logging.properties new file mode 100644 index 0000000000..750a9ff748 --- /dev/null +++ b/sandbox/slaws/runtimecompat/1xlauncher/src/main/resources/logging.properties @@ -0,0 +1,56 @@ +############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ + +############################################################ +# Global properties +############################################################ + +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the INFO and above levels. +handlers= java.util.logging.ConsoleHandler + +# To also add the FileHandler, use the following line instead. +#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler + +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overriden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +.level= INFO + +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +############################################################ + +# default file output is in user's home directory. +java.util.logging.FileHandler.pattern = %h/java%u.log +java.util.logging.FileHandler.limit = 50000 +java.util.logging.FileHandler.count = 1 +java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter + +# Limit the message that are printed on the console to INFO and above. +java.util.logging.ConsoleHandler.level = INFO +java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter + + +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ + +# For example, set the com.xyz.foo logger to only log SEVERE +# messages: +com.xyz.foo.level = SEVERE + +org.apache.tuscany.sca.level = FINE diff --git a/sandbox/slaws/runtimecompat/2xlauncher/pom.xml b/sandbox/slaws/runtimecompat/2xlauncher/pom.xml index e233ea16d4..c79f623674 100644 --- a/sandbox/slaws/runtimecompat/2xlauncher/pom.xml +++ b/sandbox/slaws/runtimecompat/2xlauncher/pom.xml @@ -27,6 +27,7 @@ <version>1.0-SNAPSHOT</version> <artifactId>2x-launcher</artifactId> <name>Apache Tuscany SCA 2.x Launcher</name> + <packaging>bundle</packaging> <dependencies> <dependency> @@ -58,6 +59,22 @@ </dependencies> <build> - <finalName>${artifactId}</finalName> + <!-- finalName>${artifactId}</finalName--> + <plugins> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Import-Package>org.apache.tuscany.sca.node;version="[2.0.0,2.0.0]"</Import-Package> + <Export-Package>launcher</Export-Package> + <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName> + </instructions> + </configuration> + </plugin> + + </plugins> </build> </project> diff --git a/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/calculator/CalculatorService.java b/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * 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. + */ +package calculator; + + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/launcher/TwoXLauncher.java b/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/launcher/TwoXLauncher.java index 128617cb32..aa086c3b83 100644 --- a/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/launcher/TwoXLauncher.java +++ b/sandbox/slaws/runtimecompat/2xlauncher/src/main/java/launcher/TwoXLauncher.java @@ -23,15 +23,32 @@ import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.NodeFactory; +import calculator.CalculatorService; + public class TwoXLauncher { public static void main(String[] args) throws Exception { + TwoXLauncher.launchNode(); + } + + public static void launchNode(){ Node node = NodeFactory.newInstance().createNode("Calculator.composite", new Contribution("calculator", "../2xcalculator.jar")); + System.out.println("2.x Node created"); + node.start(); - + + System.out.println("2.x Node started"); + + CalculatorService calculatorService = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); node.stop(); } diff --git a/sandbox/slaws/runtimecompat/combinedlauncher/src/main/java/launcher/CombinedLauncher.java b/sandbox/slaws/runtimecompat/combinedlauncher/src/main/java/launcher/CombinedLauncher.java index 44579125ff..40adc833e2 100644 --- a/sandbox/slaws/runtimecompat/combinedlauncher/src/main/java/launcher/CombinedLauncher.java +++ b/sandbox/slaws/runtimecompat/combinedlauncher/src/main/java/launcher/CombinedLauncher.java @@ -33,13 +33,8 @@ import org.osgi.framework.BundleContext; public class CombinedLauncher { - private static final String TWO_X_NODE_LAUNCHER_EQUINOX_BUNDLE = "org.apache.tuscany.sca.node.launcher.equinox"; - private static final String TWO_X_NODE_LAUNCHER_UTIL = "org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil"; - private static final String TWO_X_CONTRIBUTION = "org.apache.tuscany.sca.node.equinox.launcher.Contribution"; - - private static final String TWO_X_NODE_API_BUNDLE = "org.apache.tuscany.sca.node.api"; - private static final String TWO_X_NODE = "org.apache.tuscany.sca.node.Node"; + private static final String TWO_X_LAUNCHER = "launcher.TwoXLauncher"; private static final String ONE_X_LAUNCHER = "launcher.OneXLauncher"; public static void main(String[] args) throws Exception { @@ -55,89 +50,35 @@ public class CombinedLauncher { "../../../java-2.x/distribution/all/target/apache-tuscany-sca-all-2.0-SNAPSHOT-dir/tuscany-sca-2.0-SNAPSHOT"); // To get to the console run with -Dosgi.console=<port> + // If running in Eclipse specifying just -Dosgi.console will bring up osgi> in the eclipse console EquinoxHost equinoxHost = new EquinoxHost(); BundleContext bundleContext = equinoxHost.start(); - // need to add in the 1.x bundle(s) also - Bundle oneXbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xbundle/target/1.x-osgi-bundle-1.6-SNAPSHOT.jar"), "1xbundle"); - Bundle oneXLauncherbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xlauncher/target/1x-launcher.jar"), "1xlauncherbundle"); + // the 2.x equinoz host will have added all the Tuscany 2x bundles to the OSGi + // environment. Now add the 2.x launcher bundle + Bundle twoXLauncherbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/2xlauncher/target/2x-launcher-1.0-SNAPSHOT.jar"), "2xlauncherbundle"); + // add in the 1.x bundles also + Bundle oneXbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xbundle/target/1.x-osgi-bundle-1.6-SNAPSHOT.jar"), "1xbundle"); + Bundle oneXLauncherbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xlauncher/target/1x-launcher-1.0-SNAPSHOT.jar"), "1xlauncherbundle"); + System.out.println("Bundles loaded"); - // load 2xcalculator - // find the the 2.x node launcher util - // Get the node runtime bundle. -/* - Bundle twoXbundle = null; - for (Bundle b : bundleContext.getBundles()) { - if (TWO_X_NODE_LAUNCHER_EQUINOX_BUNDLE.equals(b.getSymbolicName())) { - twoXbundle = b; - break; - } - } - if (twoXbundle == null) { - throw new IllegalStateException("Bundle " + TWO_X_NODE_LAUNCHER_EQUINOX_BUNDLE + " is not installed"); - } - - // All this reflection not strictly needed given the current - // module dependencies. Just experimenting - Class<?> contributionClass = twoXbundle.loadClass(TWO_X_CONTRIBUTION); - Constructor<?> constructor = contributionClass.getConstructor(String.class, String.class); - - Class<?> bootstrapClass = twoXbundle.loadClass(TWO_X_NODE_LAUNCHER_UTIL); - Class<?> contributionArrayClass = Array.newInstance(contributionClass, 0).getClass(); - Method nodeMethod = bootstrapClass.getMethod("node", String.class, String.class, String.class, contributionArrayClass, BundleContext.class); - - twoXbundle = null; - for (Bundle b : bundleContext.getBundles()) { - if (TWO_X_NODE_API_BUNDLE.equals(b.getSymbolicName())) { - twoXbundle = b; - break; - } - } - if (twoXbundle == null) { - throw new IllegalStateException("Bundle " + TWO_X_NODE_API_BUNDLE + " is not installed"); - } - - Class<?> nodeClass = twoXbundle.loadClass(TWO_X_NODE); - Method startMethod = nodeClass.getMethod("start"); - - String configurationURI = null; - String compositeURI = null; - String compositeContent = null; - Object contribution = constructor.newInstance("calculator", "../2xcalculator.jar"); - Object[] contributions = (Object[])Array.newInstance(contributionClass, 1); - contributions[0] = contribution; - - Object node = nodeMethod.invoke(null, - configurationURI, - compositeURI, - compositeContent, - contributionArrayClass.cast(contributions), - bundleContext); - - startMethod.invoke(node); - - System.out.println("2.x Running"); -*/ + // find the the 2.x node launcher and get it to run the calculator app + Class<?> twoXLauncherClass = twoXLauncherbundle.loadClass(TWO_X_LAUNCHER); + Method twoXLaunchNodeMethod = twoXLauncherClass.getMethod("launchNode"); + twoXLaunchNodeMethod.invoke(null); + System.out.println("2.x run complete"); - // load 1xcalculator - // find the the 1.x node launcher + // find the the 1.x node launcher and get it to run the calculator app Class<?> oneXLauncherClass = oneXLauncherbundle.loadClass(ONE_X_LAUNCHER); - Method launchNodeMethod = oneXLauncherClass.getMethod("launchNode"); - launchNodeMethod.invoke(null); - - System.out.println("1.x Running"); + Method oneXLaunchNodeMethod = oneXLauncherClass.getMethod("launchNode"); + oneXLaunchNodeMethod.invoke(null); - try { - System.out.println("Press a key"); - System.in.read(); - } catch (Exception ex) { - } + System.out.println("1.x run complete"); equinoxHost.stop(); } - } diff --git a/sandbox/slaws/runtimecompat/pom.xml b/sandbox/slaws/runtimecompat/pom.xml index 6c781dffc5..d266f6f6be 100644 --- a/sandbox/slaws/runtimecompat/pom.xml +++ b/sandbox/slaws/runtimecompat/pom.xml @@ -54,6 +54,7 @@ <activeByDefault>true</activeByDefault> </activation> <modules> + <module>1xbundle</module> <module>1xlauncher</module> <module>2xlauncher</module> <module>combinedlauncher</module> |