You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/08/28 02:17:03 UTC
svn commit: r689677 [2/2] - in
/tuscany/java/sca/modules/node-launcher-equinox: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/
src/main/java/org/apac...
Added: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,186 @@
+/*
+ * 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 org.apache.tuscany.sca.node.equinox.launcher;
+
+import java.lang.reflect.Constructor;
+import java.util.logging.Level;
+
+/**
+ * Common functions and constants used by the admin components.
+ *
+ * @version $Rev$ $Date$
+ */
+final class NodeLauncherUtil {
+ // private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
+
+ private static final String DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP =
+ "org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap";
+
+ private static final String NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP =
+ "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap";
+
+ private static final String NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP =
+ "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap";
+
+ /**
+ * Collect JAR files under the given directory.
+ *
+ * @p @param contributions
+ * @throws LauncherException
+ */
+ static Object node(String configurationURI,
+ String compositeURI,
+ String compositeContent,
+ Contribution[] contributions,
+ ClassLoader contributionClassLoader) throws LauncherException {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+
+ // Use Java reflection to create the node as only the runtime class
+ // loader knows the runtime classes required by the node
+ String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP;
+ Class<?> bootstrapClass;
+ bootstrapClass = Class.forName(className, false, tccl);
+
+ Object bootstrap;
+ if (configurationURI != null) {
+
+ // Construct the node with a configuration URI
+ bootstrap = bootstrapClass.getConstructor(String.class).newInstance(configurationURI);
+
+ } else if (contributionClassLoader != null) {
+
+ // Construct the node with a compositeURI and a classloader
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class, ClassLoader.class);
+ bootstrap = constructor.newInstance(compositeURI, contributionClassLoader);
+
+ } else if (compositeContent != null) {
+
+ // Construct the node with a composite URI, the composite content and
+ // the URIs and locations of a list of contributions
+ Constructor<?> constructor =
+ bootstrapClass.getConstructor(String.class, String.class, String[].class, String[].class);
+ String[] uris = new String[contributions.length];
+ String[] locations = new String[contributions.length];
+ for (int i = 0; i < contributions.length; i++) {
+ uris[i] = contributions[i].getURI();
+ locations[i] = contributions[i].getLocation();
+ }
+ bootstrap = constructor.newInstance(compositeURI, compositeContent, uris, locations);
+
+ } else {
+
+ // Construct the node with a composite URI and the URIs and
+ // locations of a list of contributions
+ Constructor<?> constructor =
+ bootstrapClass.getConstructor(String.class, String[].class, String[].class);
+ String[] uris = new String[contributions.length];
+ String[] locations = new String[contributions.length];
+ for (int i = 0; i < contributions.length; i++) {
+ uris[i] = contributions[i].getURI();
+ locations[i] = contributions[i].getLocation();
+ }
+ bootstrap = constructor.newInstance(compositeURI, uris, locations);
+ }
+
+ Object node = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+ try {
+ Class<?> type = Class.forName("org.apache.tuscany.sca.node.SCANodeFactory");
+ type = type.getDeclaredClasses()[0];
+ return type.getMethod("createProxy", Class.class, Object.class).invoke(null, type, node);
+ } catch (ClassNotFoundException e) {
+ // Ignore
+ }
+ return node;
+
+ } catch (Exception e) {
+ NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e);
+ throw new LauncherException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ /**
+ * Creates a new node daemon.
+ *
+ * @throws LauncherException
+ */
+ static Object nodeDaemon() throws LauncherException {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+
+ // Use Java reflection to create the node daemon as only the runtime class
+ // loader knows the runtime classes required by the node
+ String className = NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP;
+ Class<?> bootstrapClass;
+ bootstrapClass = Class.forName(className, false, tccl);
+ Object bootstrap = bootstrapClass.getConstructor().newInstance();
+
+ Object nodeDaemon = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+ return nodeDaemon;
+
+ } catch (Exception e) {
+ NodeLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created", e);
+ throw new LauncherException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ /**
+ * Creates a new domain manager.
+ *
+ * @throws LauncherException
+ */
+ static Object domainManager(String rootDirectory) throws LauncherException {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+
+ // Use Java reflection to create the node daemon as only the runtime class
+ // loader knows the runtime classes required by the node
+ String className = DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP;
+ Class<?> bootstrapClass;
+ bootstrapClass = Class.forName(className, false, tccl);
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class);
+ Object bootstrap = constructor.newInstance(rootDirectory);
+
+ Object domainManager = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+ return domainManager;
+
+ } catch (Exception e) {
+ NodeLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e);
+ throw new LauncherException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ static OSGiHost startOSGi() {
+ OSGiHost host = new EquinoxOSGiHost();
+ host.start();
+ return host;
+ }
+
+ static void stopOSGi(OSGiHost host) {
+ host.stop();
+ }
+
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherUtil.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.tuscany.sca.node.equinox.launcher;
+
+
+/**
+ * Main class for this JAR.
+ * With no arguments this class launches the SCA Node Daemon.
+ * With a "domain" argument it launches the SCA domain admin node.
+ * With any other argument it launches an SCA Node.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeMain {
+
+ public static void main(String[] args) throws Exception {
+ if (args.length != 0) {
+ if (args[0].equals("domain")) {
+ DomainManagerLauncher.main(args);
+ } else {
+ NodeLauncher.main(args);
+ }
+ } else {
+ NodeDaemonLauncher.main(args);
+ }
+ }
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeMain.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,127 @@
+/*
+ * 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 org.apache.tuscany.sca.node.equinox.launcher;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * A Servlet filter that forwards service requests to the Servlets registered with
+ * the Tuscany ServletHost.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeServletFilter implements Filter {
+ private static final String NODE_WEB_APP_SERVLET_HOST = "org.apache.tuscany.sca.implementation.node.osgi.webapp.NodeWebAppServletHost";
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = Logger.getLogger(NodeServletFilter.class.getName());
+
+ private ClassLoader runtimeClassLoader;
+ private Class<?> servletHostClass;
+ private Object servletHost;
+ private Filter filter;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ logger.info("Apache Tuscany SCA WebApp Node starting...");
+
+ try {
+ // Get the Tuscany runtime ClassLoader
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ // Load the Tuscany WebApp Servlet host and get the host instance
+ // for the current webapp
+ String className = NODE_WEB_APP_SERVLET_HOST;
+ if (runtimeClassLoader != null) {
+ servletHostClass = Class.forName(className, true, runtimeClassLoader);
+ } else {
+ servletHostClass = Class.forName(className);
+ }
+ servletHost = servletHostClass.getMethod("servletHost").invoke(null);
+
+ // Initialize the Servlet host
+ servletHostClass.getMethod("init", FilterConfig.class).invoke(servletHost, filterConfig);
+
+ // The Servlet host also implements the filter interface
+ filter = (Filter)servletHost;
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Error Starting SCA WebApp Node", e);
+ throw new ServletException(e);
+ }
+
+ logger.info("SCA WebApp Node started.");
+ }
+
+ public void destroy() {
+ logger.info("Apache Tuscany WebApp Node stopping...");
+ if (servletHost != null) {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ servletHostClass.getMethod("destroy").invoke(servletHost);
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Error Stopping SCA WebApp Node", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+ logger.info("SCA WebApp Node stopped.");
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
+ throws IOException, ServletException {
+
+ // Delegate to the Servlet host filter
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ filter.doFilter(request, response, chain);
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/NodeServletFilter.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/OSGiHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/OSGiHost.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/OSGiHost.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/OSGiHost.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,30 @@
+/*
+ * 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 org.apache.tuscany.sca.node.equinox.launcher;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * SPI to plug in OSGi implementations such as Equinox or Felix
+ */
+public interface OSGiHost {
+ BundleContext start();
+ void stop();
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/OSGiHost.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/main/java/org/apache/tuscany/sca/node/equinox/launcher/OSGiHost.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorld.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorld.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorld.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorld.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,30 @@
+/*
+ * 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 hello;
+
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * HelloWorld interface
+ */
+@Remotable
+public interface HelloWorld {
+ String hello(String name);
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorld.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorld.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorldImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorldImpl.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorldImpl.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorldImpl.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,30 @@
+/*
+ * 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 hello;
+
+/**
+ * HelloWorldImpl
+ */
+public class HelloWorldImpl implements HelloWorld {
+ public String hello(String name) {
+ System.out.println("Hello: " + name);
+ return "Hello, " + name;
+ }
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorldImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/hello/HelloWorldImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.tuscany.sca.node.equinox.launcher;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ *
+ */
+public class EquinoxOSGiHostTestCase {
+ @Test
+ public void testStartThenStop() {
+ EquinoxOSGiHost host = new EquinoxOSGiHost();
+ BundleContext context = host.start();
+ Assert.assertNotNull(context);
+ for (Bundle b : context.getBundles()) {
+ System.out.println(toString(b, false));
+ }
+ host.stop();
+ }
+
+ @Test
+ public void testStartTwice() {
+ EquinoxOSGiHost host = new EquinoxOSGiHost();
+ host.start();
+ try {
+ host.start();
+ Assert.fail();
+ } catch (IllegalStateException e) {
+ Assert.assertTrue(IllegalStateException.class.isInstance(e.getCause()));
+ } finally {
+ host.stop();
+ }
+ }
+
+ public static String toString(Bundle b, boolean verbose) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
+ int s = b.getState();
+ if ((s & Bundle.UNINSTALLED) != 0) {
+ sb.append(" UNINSTALLED");
+ }
+ if ((s & Bundle.INSTALLED) != 0) {
+ sb.append(" INSTALLED");
+ }
+ if ((s & Bundle.RESOLVED) != 0) {
+ sb.append(" RESOLVED");
+ }
+ if ((s & Bundle.STARTING) != 0) {
+ sb.append(" STARTING");
+ }
+ if ((s & Bundle.STOPPING) != 0) {
+ sb.append(" STOPPING");
+ }
+ if ((s & Bundle.ACTIVE) != 0) {
+ sb.append(" ACTIVE");
+ }
+
+ sb.append(" ").append(b.getLocation());
+ if (verbose) {
+ Dictionary<Object, Object> dict = b.getHeaders();
+ Enumeration<Object> keys = dict.keys();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ sb.append(" ").append(key).append("=").append(dict.get(key));
+ }
+ }
+ return sb.toString();
+ }
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/EquinoxOSGiHostTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java Wed Aug 27 17:17:02 2008
@@ -0,0 +1,73 @@
+/*
+ * 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 org.apache.tuscany.sca.node.equinox.launcher;
+
+import hello.HelloWorld;
+
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.equinox.launcher.DomainManagerLauncher;
+import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher;
+import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncherUtil;
+import org.apache.tuscany.sca.node.equinox.launcher.OSGiHost;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class NodeLauncherTestCase {
+ private static OSGiHost host;
+
+ @BeforeClass
+ public static void setUp() {
+ System.setProperty("TUSCANY_HOME", "target/tuscany");
+ host = NodeLauncherUtil.startOSGi();
+ }
+
+ @AfterClass
+ public static void tearDown() {
+ if (host != null) {
+ NodeLauncherUtil.stopOSGi(host);
+ }
+
+ }
+
+ @Test
+ public void testLaunch() throws Exception {
+ NodeLauncher launcher = NodeLauncher.newInstance();
+ SCANode node = launcher.createNodeFromClassLoader("HelloWorld.composite", getClass().getClassLoader());
+ node.start();
+
+ HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
+ hw.hello("OSGi");
+
+ node.stop();
+ }
+
+ @Test
+ @Ignore("contribution-osgi issue")
+ public void testLaunchDomain() throws Exception {
+ DomainManagerLauncher.main(new String[] {});
+ }
+
+}
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tuscany/java/sca/modules/node-launcher-equinox/src/test/java/org/apache/tuscany/sca/node/equinox/launcher/NodeLauncherTestCase.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: tuscany/java/sca/modules/node-launcher-equinox/src/test/resources/HelloWorld.composite
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node-launcher-equinox/src/test/resources/HelloWorld.composite?rev=689677&view=auto
==============================================================================
--- tuscany/java/sca/modules/node-launcher-equinox/src/test/resources/HelloWorld.composite (added)
+++ tuscany/java/sca/modules/node-launcher-equinox/src/test/resources/HelloWorld.composite Wed Aug 27 17:17:02 2008
@@ -0,0 +1,30 @@
+<?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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://sample/composite"
+ xmlns:sc="http://sample/composite"
+ name="HelloWorld">
+
+ <component name="HelloWorld">
+ <implementation.java class="hello.HelloWorldImpl"/>
+ </component>
+
+</composite>