tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r419979 - in /incubator/tuscany/sandbox/jboynes/sca: commands/launcher/src/main/java/org/apache/tuscany/launcher/ commands/launcher/src/main/java/org/osoa/ commands/launcher/src/main/resources/META-INF/ commands/launcher/src/main/resources/...
Date Fri, 07 Jul 2006 20:48:19 GMT
Author: jboynes
Date: Fri Jul  7 13:48:18 2006
New Revision: 419979

URL: http://svn.apache.org/viewvc?rev=419979&view=rev
Log:
have launcher boot both system and application modules

Added:
    incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/
    incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/
    incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
  (with props)
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
      - copied, changed from r419647, incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/osoa/sca/CompositeContextImpl.java
    incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/META-INF/
    incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/META-INF/sca/
    incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/META-INF/sca/default.scdl
      - copied, changed from r419647, incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/eagerinit.composite
Removed:
    incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/java/org/osoa/
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/osoa/
    incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/eagerinit.composite
Modified:
    incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
    incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
    incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/pom.xml

Modified: incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java?rev=419979&r1=419978&r2=419979&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/java/org/apache/tuscany/launcher/MainLauncherBooter.java
Fri Jul  7 13:48:18 2006
@@ -64,7 +64,7 @@
 
         try {
             Object launcher = launcherClass.newInstance();
-            mainMethod.invoke(launcher, args);
+            mainMethod.invoke(launcher, new Object[] {args});
         } catch (InstantiationException e) {
             throw new AssertionError(e);
         } catch (IllegalAccessException e) {

Added: incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl?rev=419979&view=auto
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
(added)
+++ incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
Fri Jul  7 13:48:18 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ *  Copyright (c) 2006 The Apache Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed 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 more complex example closer to a typical bootstrap configuration
+    $Rev$ $Date$
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/0.9"
+           xmlns:system="http://tuscany.apache.org/xmlns/system/0.9"
+           name="org.apache.tuscany.launcher.Runtime">
+</composite>
\ No newline at end of file

Propchange: incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/sandbox/jboynes/sca/commands/launcher/src/main/resources/META-INF/tuscany/system.scdl
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
(from r419647, incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/osoa/sca/CompositeContextImpl.java)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java?p2=incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java&p1=incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/osoa/sca/CompositeContextImpl.java&r1=419647&r2=419979&rev=419979&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/osoa/sca/CompositeContextImpl.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/CompositeContextImpl.java
Fri Jul  7 13:48:18 2006
@@ -1,42 +1,26 @@
-package org.osoa.sca;
+package org.apache.tuscany.core.launcher;
 
-import java.lang.reflect.Method;
-import java.lang.reflect.InvocationTargetException;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.SCA;
 
 import org.apache.tuscany.spi.component.CompositeComponent;
 
 
-public class CompositeContextImpl implements CompositeContext {
+public class CompositeContextImpl extends SCA implements CompositeContext {
     protected final CompositeComponent<?> composite;
 
-    public CompositeContextImpl(final CompositeComponent<?> composite, final ClassLoader
appclass) {
+    public CompositeContextImpl(final CompositeComponent<?> composite) {
         this.composite = composite;
-        Class<?> compClass;
-        try {
-            compClass = appclass.loadClass("org.osoa.sca.LauncherCurrentCompositeContext");
-        } catch (ClassNotFoundException e) {
-            throw new AssertionError(e);
-        }
-
-        try {
-            Method method = compClass.getDeclaredMethod("setContext", new Class[]{CompositeContext.class});
-            method.invoke(null, new Object[]{this});
-        } catch (NoSuchMethodException e) {
-            throw new AssertionError();
-        } catch (IllegalAccessException e) {
-            throw new UnsupportedOperationException();
-        } catch (InvocationTargetException e) {
-            // rethrow unchecked exceptions
-            Throwable cause = e.getCause();
-            if (cause instanceof RuntimeException) {
-                throw (RuntimeException) cause;
-            } else if (cause instanceof Error) {
-                throw (Error) cause;
-            } else {
-                // assertion because setContext() does not declare any checked exceptions
-                throw new AssertionError(cause);
-            }
-        }
+    }
+
+    public void start() {
+        setCompositeContext(this);
+    }
+
+    public void stop() {
+        setCompositeContext(null);
     }
 
     public ServiceReference createServiceReferenceForSession(Object arg0) {
@@ -59,8 +43,8 @@
         return null;
     }
 
-    public <T> T locateService(Class<T> arg0, String arg1) {
-        return arg0.cast(composite.getChild(arg1).getServiceInstance());
+    public <T> T locateService(Class<T> serviceInterface, String serviceName)
{
+        return serviceInterface.cast(composite.getChild(serviceName).getServiceInstance());
     }
 
     public ServiceReference newSession(String arg0) {

Modified: incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java?rev=419979&r1=419978&r2=419979&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
(original)
+++ incubator/tuscany/sandbox/jboynes/sca/core2/src/main/java/org/apache/tuscany/core/launcher/MainLauncher.java
Fri Jul  7 13:48:18 2006
@@ -31,6 +31,7 @@
 import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
 import org.apache.tuscany.core.monitor.NullMonitorFactory;
 import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
+import org.apache.tuscany.spi.bootstrap.ComponentNames;
 import org.apache.tuscany.spi.component.CompositeComponent;
 import org.apache.tuscany.spi.deployer.Deployer;
 import org.apache.tuscany.spi.loader.LoaderException;
@@ -43,6 +44,9 @@
  * @version $Rev: 412898 $ $Date: 2006-06-08 21:31:50 -0400 (Thu, 08 Jun 2006) $
  */
 public class MainLauncher extends LauncherSupport {
+    private RuntimeComponent runtime;
+    private Deployer deployer;
+
     /**
      * Set the application classpath from a string delimited by path separators.
      * If the application classname is not defined, any jars on the path are examined
@@ -93,9 +97,14 @@
      * @throws InvalidMainException      if the main method does not exist or is invalid
      * @throws InvocationTargetException if the main method throws an exception
      */
-    public void callApplication() throws InvalidMainException, ClassNotFoundException, InvocationTargetException
{
+    public void callApplication(CompositeComponent<?> application)
+        throws InvalidMainException, ClassNotFoundException, InvocationTargetException {
+
         final ClassLoader cl = Thread.currentThread().getContextClassLoader();
+        final CompositeContextImpl context = new CompositeContextImpl(application);
+
         Thread.currentThread().setContextClassLoader(getApplicationLoader());
+        context.start();
         try {
             if (getClassName() == null) {
                 throw new InvalidMainException("Main-Class not specified");
@@ -111,42 +120,73 @@
                 throw new InvalidMainException(main.toString());
             }
             try {
-                main.invoke(null, getArgs());
+                main.invoke(null, new Object[]{getArgs()});
             } catch (IllegalAccessException e) {
                 // assertion as getMethod() should not have returned a method that is not
accessible
                 throw new AssertionError();
             }
         } finally {
+            context.stop();
             Thread.currentThread().setContextClassLoader(cl);
         }
     }
 
     private CompositeComponent<?> bootRuntime() throws LoaderException {
-        XMLInputFactory xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory",
-                                                                 getClass().getClassLoader());
+        ClassLoader systemClassLoader = getClass().getClassLoader();
+        XMLInputFactory xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory",
systemClassLoader);
         Bootstrapper bootstrapper = new DefaultBootstrapper(new NullMonitorFactory(), xmlFactory);
-        Deployer deployer = bootstrapper.createDeployer();
+        Deployer bootDeployer = bootstrapper.createDeployer();
 
         // create and start the core runtime
-        RuntimeComponent runtime = bootstrapper.createRuntime();
+        runtime = bootstrapper.createRuntime();
         runtime.start();
 
         // create a ComponentDefinition to represent the component we are going to deploy
         SystemCompositeImplementation moduleImplementation = new SystemCompositeImplementation();
-        URL scdl = getApplicationLoader().getResource("eagerinit.composite");
+        URL scdl = getClass().getResource("/META-INF/tuscany/system.scdl");
+        if (scdl == null) {
+            throw new LoaderException("No system scdl found");
+        }
         moduleImplementation.setScdlLocation(scdl);
-        moduleImplementation.setClassLoader(getApplicationLoader());
+        moduleImplementation.setClassLoader(systemClassLoader);
         ComponentDefinition<SystemCompositeImplementation> moduleDefinition =
-                new ComponentDefinition<SystemCompositeImplementation>("eagerinit",
moduleImplementation);
+                new ComponentDefinition<SystemCompositeImplementation>(ComponentNames.TUSCANY_SYSTEM,
+                                                                       moduleImplementation);
 
-        // deploy the component into the system under the application root
-        System.out.println("Deploying composite component");
-        CompositeComponent root = runtime.getRootComponent();
-        CompositeComponent<?> composite = (CompositeComponent<?>) deployer.deploy(root,
moduleDefinition);
+        // deploy the component into the runtime under the system parent
+        System.out.println("Deploying system component");
+        CompositeComponent parent = runtime.getSystemComponent();
+        CompositeComponent<?> composite = (CompositeComponent<?>) bootDeployer.deploy(parent,
moduleDefinition);
 
-        // start the composite (which will fire the init method)
-        System.out.println("Starting composite component");
+        // start the system
+        System.out.println("Starting system component");
         composite.start();
+
+        // todo get the deployer from the system component
+        deployer = bootDeployer;
+        return composite;
+    }
+
+    private CompositeComponent<?> bootApplication() throws LoaderException {
+        ClassLoader applicationLoader = getApplicationLoader();
+
+        // create a ComponentDefinition to represent the component we are going to deploy
+        SystemCompositeImplementation moduleImplementation = new SystemCompositeImplementation();
+        URL scdl = applicationLoader.getResource("META-INF/sca/default.scdl");
+        if (scdl == null) {
+            throw new LoaderException("No application scdl found");
+        }
+        moduleImplementation.setScdlLocation(scdl);
+        moduleImplementation.setClassLoader(applicationLoader);
+        ComponentDefinition<SystemCompositeImplementation> moduleDefinition =
+                new ComponentDefinition<SystemCompositeImplementation>(ComponentNames.TUSCANY_SYSTEM,
+                                                                       moduleImplementation);
+
+        // deploy the component into the runtime under the system parent
+        System.out.println("Deploying application component");
+        CompositeComponent parent = runtime.getRootComponent();
+        CompositeComponent<?> composite = (CompositeComponent<?>) deployer.deploy(parent,
moduleDefinition);
+
         return composite;
     }
 
@@ -160,7 +200,13 @@
         try {
             parseArguments(args);
             bootRuntime();
-            callApplication();
+            CompositeComponent application = bootApplication();
+            application.start();
+            try {
+                callApplication(application);
+            } finally {
+                application.stop();
+            }
         } catch (ClassNotFoundException e) {
             e.printStackTrace();
             System.err.println("Main-Class not found: " + e.getMessage());

Modified: incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/pom.xml?rev=419979&r1=419978&r2=419979&view=diff
==============================================================================
--- incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/pom.xml (original)
+++ incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/pom.xml Fri Jul  7 13:48:18 2006
@@ -41,4 +41,20 @@
             <scope>provided</scope>
         </dependency>
     </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <mainClass>eagerinit.EagerInitClient</mainClass>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 </project>

Copied: incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/META-INF/sca/default.scdl
(from r419647, incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/eagerinit.composite)
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/META-INF/sca/default.scdl?p2=incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/META-INF/sca/default.scdl&p1=incubator/tuscany/sandbox/jboynes/sca/samples/eagerinit/src/main/resources/eagerinit.composite&r1=419647&r2=419979&rev=419979&view=diff
==============================================================================
    (empty)



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org


Mime
View raw message