Bring up 1.x and 2.x together.

git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@882529 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
slaws 2009-11-20 12:10:03 +00:00
parent 2335e867fb
commit 558e99c8ae
8 changed files with 182 additions and 80 deletions

View file

@ -58,7 +58,7 @@
</dependencies> </dependencies>
<build> <build>
<finalName>${artifactId}</finalName> <!-- finalName>${artifactId}</finalName-->
<plugins> <plugins>
<plugin> <plugin>

View file

@ -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);
}

View file

@ -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

View file

@ -27,6 +27,7 @@
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<artifactId>2x-launcher</artifactId> <artifactId>2x-launcher</artifactId>
<name>Apache Tuscany SCA 2.x Launcher</name> <name>Apache Tuscany SCA 2.x Launcher</name>
<packaging>bundle</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
@ -58,6 +59,22 @@
</dependencies> </dependencies>
<build> <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> </build>
</project> </project>

View file

@ -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);
}

View file

@ -23,15 +23,32 @@ import org.apache.tuscany.sca.node.Contribution;
import org.apache.tuscany.sca.node.Node; import org.apache.tuscany.sca.node.Node;
import org.apache.tuscany.sca.node.NodeFactory; import org.apache.tuscany.sca.node.NodeFactory;
import calculator.CalculatorService;
public class TwoXLauncher { public class TwoXLauncher {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
TwoXLauncher.launchNode();
}
public static void launchNode(){
Node node = NodeFactory.newInstance().createNode("Calculator.composite", Node node = NodeFactory.newInstance().createNode("Calculator.composite",
new Contribution("calculator", "../2xcalculator.jar")); new Contribution("calculator", "../2xcalculator.jar"));
System.out.println("2.x Node created");
node.start(); 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(); node.stop();
} }

View file

@ -33,13 +33,8 @@ import org.osgi.framework.BundleContext;
public class CombinedLauncher { 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"; private static final String ONE_X_LAUNCHER = "launcher.OneXLauncher";
public static void main(String[] args) throws Exception { 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"); "../../../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> // 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(); EquinoxHost equinoxHost = new EquinoxHost();
BundleContext bundleContext = equinoxHost.start(); BundleContext bundleContext = equinoxHost.start();
// need to add in the 1.x bundle(s) also // the 2.x equinoz host will have added all the Tuscany 2x bundles to the OSGi
Bundle oneXbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xbundle/target/1.x-osgi-bundle-1.6-SNAPSHOT.jar"), "1xbundle"); // environment. Now add the 2.x launcher bundle
Bundle oneXLauncherbundle = equinoxHost.installBundle(new URL("file:///C:/simon/tuscany/sandbox/runtimecompat/1xlauncher/target/1x-launcher.jar"), "1xlauncherbundle"); 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"); System.out.println("Bundles loaded");
// load 2xcalculator // find the the 2.x node launcher and get it to run the calculator app
// find the the 2.x node launcher util Class<?> twoXLauncherClass = twoXLauncherbundle.loadClass(TWO_X_LAUNCHER);
// Get the node runtime bundle. Method twoXLaunchNodeMethod = twoXLauncherClass.getMethod("launchNode");
/* twoXLaunchNodeMethod.invoke(null);
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");
*/
System.out.println("2.x run complete");
// load 1xcalculator // find the the 1.x node launcher and get it to run the calculator app
// find the the 1.x node launcher
Class<?> oneXLauncherClass = oneXLauncherbundle.loadClass(ONE_X_LAUNCHER); Class<?> oneXLauncherClass = oneXLauncherbundle.loadClass(ONE_X_LAUNCHER);
Method launchNodeMethod = oneXLauncherClass.getMethod("launchNode"); Method oneXLaunchNodeMethod = oneXLauncherClass.getMethod("launchNode");
launchNodeMethod.invoke(null); oneXLaunchNodeMethod.invoke(null);
System.out.println("1.x Running"); System.out.println("1.x run complete");
try {
System.out.println("Press a key");
System.in.read();
} catch (Exception ex) {
}
equinoxHost.stop(); equinoxHost.stop();
} }
} }

View file

@ -54,6 +54,7 @@
<activeByDefault>true</activeByDefault> <activeByDefault>true</activeByDefault>
</activation> </activation>
<modules> <modules>
<module>1xbundle</module>
<module>1xlauncher</module> <module>1xlauncher</module>
<module>2xlauncher</module> <module>2xlauncher</module>
<module>combinedlauncher</module> <module>combinedlauncher</module>