tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmar...@apache.org
Subject svn commit: r368501 - /incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/
Date Thu, 12 Jan 2006 22:45:46 GMT
Author: jmarino
Date: Thu Jan 12 14:45:45 2006
New Revision: 368501

URL: http://svn.apache.org/viewcvs?rev=368501&view=rev
Log:
initial work on revised bootstrap for Tomcat

Added:
    incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java
    incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java
Removed:
    incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/TomcatServerLifecycleListener.java
Modified:
    incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java

Added: incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java?rev=368501&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java
(added)
+++ incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/BootstrapConfigurationException.java
Thu Jan 12 14:45:45 2006
@@ -0,0 +1,41 @@
+/**
+ * 
+ * Copyright 2005 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.
+ */
+package org.apache.tuscany.tomcat.lifecycle.listener;
+
+import org.apache.tuscany.core.TuscanyException;
+
+/**
+ * Signals an exception booting the Tuscany runtime hosted in a Tomcat instance
+ * 
+ * @version $Rev$ $Date$
+ */
+public class BootstrapConfigurationException extends TuscanyException {
+
+    public BootstrapConfigurationException() {
+        super();
+    }
+
+    public BootstrapConfigurationException(String message) {
+        super(message);
+    }
+
+    public BootstrapConfigurationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public BootstrapConfigurationException(Throwable cause) {
+        super(cause);
+    }
+
+}

Added: incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java?rev=368501&view=auto
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java
(added)
+++ incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/RuntimeBootstrap.java
Thu Jan 12 14:45:45 2006
@@ -0,0 +1,113 @@
+/**
+ * 
+ * Copyright 2005 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.
+ */
+package org.apache.tuscany.tomcat.lifecycle.listener;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.RefAddr;
+import javax.naming.Reference;
+import javax.naming.spi.ObjectFactory;
+
+import org.apache.tuscany.common.monitor.MonitorFactory;
+import org.apache.tuscany.core.builder.RuntimeConfigurationBuilder;
+import org.apache.tuscany.core.config.ConfigurationLoader;
+import org.apache.tuscany.core.config.JavaIntrospectionHelper;
+import org.apache.tuscany.core.system.builder.SystemComponentContextBuilder;
+import org.apache.tuscany.core.system.builder.SystemEntryPointBuilder;
+import org.apache.tuscany.core.system.builder.SystemExternalServiceBuilder;
+import org.apache.tuscany.core.system.context.RuntimeContext;
+import org.apache.tuscany.core.system.context.RuntimeContextImpl;
+
+/**
+ * Bootstraps an SCA runtime hosted by a Tomcat instance. The runtime will be bound to JNDI
and accessed by
+ * {@link org.apache.tuscany.tomcat.lifecycle.listener.WebAppLifecycleListener}s that deploy
web archives as module
+ * components.
+ * <p>
+ * Tomcat is configured by adding the following to <code>server.xml</code> under
the
+ * <code>GlobalNamingResources</code> element:
+ * 
+ * <pre>
+ *   &lt;Resource name=&quot;TuscanyRuntime&quot; auth=&quot;Container&quot;
type=&quot;org.apache.tuscany.core.system.context.RuntimeContext&quot;
+ *          description=&quot;Tuscany Runtime&quot;
+ *          factory=&quot; org.apache.tuscany.tomcat.lifecycle.listener.RuntimeBootstrap&quot;
+ *          monitor=&quot;[monitor factory]&quot; loader=&quot;[configuration
loader]&quot;/&gt;
+ * </pre>
+ * 
+ * @version $Rev$ $Date$
+ */
+public class RuntimeBootstrap implements ObjectFactory {
+
+    public static final String RUNTIME_NAME = "TuscanyRuntime";
+
+    public RuntimeBootstrap() {
+    }
+
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,
?> environment)
+            throws BootstrapConfigurationException {
+        if (!RUNTIME_NAME.equals(name)) {
+            throw new BootstrapConfigurationException("Tuscany Runtime must be configured
with JNDI address of " + RUNTIME_NAME);
+        }
+        MonitorFactory monitorFactory = null;
+        ConfigurationLoader configurationLoader = null;
+
+        Reference ref = (Reference) obj;
+        if (!RuntimeContext.class.getName().equals(ref.getClassName())) {
+            throw new BootstrapConfigurationException("Invalid runtime configuration");
+        }
+        RefAddr monitorAddr = ref.get("monitor");
+        RefAddr loaderAddr = ref.get("loader");
+        if (loaderAddr == null) {
+            throw new BootstrapConfigurationException("No configuration laoder specified
in Tomcat configuration");
+        }
+        if (monitorAddr != null) {
+            try {
+                Class monitorFactoryClass = JavaIntrospectionHelper.loadClass(monitorAddr.getContent().toString());
+                monitorFactory = (MonitorFactory) monitorFactoryClass.newInstance();
+            } catch (ClassNotFoundException e) {
+                throw new BootstrapConfigurationException("Unable to find monitor factory
class specified in Tomcat configuration", e);
+            } catch (InstantiationException e) {
+                throw new BootstrapConfigurationException("Error initializing monitor factory
in Tomcat configuration", e);
+            } catch (IllegalAccessException e) {
+                throw new BootstrapConfigurationException("Error initializing monitor factory
in Tomcat configuration", e);
+            }
+        }
+        try {
+            Class configurationLoaderClass = JavaIntrospectionHelper.loadClass(loaderAddr.getContent().toString());
+            configurationLoader = (ConfigurationLoader) configurationLoaderClass.newInstance();
+        } catch (ClassNotFoundException e) {
+            throw new BootstrapConfigurationException("Unable to find configuration loader
class specified in Tomcat configuration", e);
+        } catch (InstantiationException e) {
+            throw new BootstrapConfigurationException("Error initializing configuration loader
in Tomcat configuration", e);
+        } catch (IllegalAccessException e) {
+            throw new BootstrapConfigurationException("Error initializing configuration loader
in Tomcat configuration", e);
+        }
+        // create the SCA Runtime and have it bound in the global JNDI context
+        return new RuntimeContextImpl(monitorFactory, createBuilders(), configurationLoader);
+    }
+
+    /**
+     * Creates a collection of bootstrap builders
+     */
+    private List<RuntimeConfigurationBuilder> createBuilders() {
+        List<RuntimeConfigurationBuilder> builders = new ArrayList();
+        builders.add((new SystemComponentContextBuilder()));
+        builders.add(new SystemEntryPointBuilder());
+        builders.add(new SystemExternalServiceBuilder());
+        return builders;
+    }
+}

Modified: incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java?rev=368501&r1=368500&r2=368501&view=diff
==============================================================================
--- incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java
(original)
+++ incubator/tuscany/contrib/java/trunk/runtime/tomcat/src/main/java/org/apache/tuscany/tomcat/lifecycle/listener/WebAppLifecycleListener.java
Thu Jan 12 14:45:45 2006
@@ -16,6 +16,9 @@
  */
 package org.apache.tuscany.tomcat.lifecycle.listener;
 
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
 import org.apache.catalina.Context;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleEvent;
@@ -24,7 +27,6 @@
 import org.apache.catalina.deploy.FilterMap;
 import org.apache.tuscany.core.TuscanyRuntimeException;
 import org.apache.tuscany.core.config.ConfigurationException;
-import org.apache.tuscany.core.context.AggregateContext;
 import org.apache.tuscany.core.context.EventContext;
 import org.apache.tuscany.core.context.TuscanyModuleComponentContext;
 import org.apache.tuscany.core.context.webapp.HTTPSessionExpirationListener;
@@ -48,15 +50,21 @@
 
     private RuntimeMonitor monitor;
 
-    private AggregateContext rootContext;
-
     // ----------------------------------
     // Constructors
     // ----------------------------------
 
     public WebAppLifecycleListener() {
-        monitor = runtime.getMonitorFactory().getMonitor(RuntimeMonitor.class);
-        rootContext = runtime.getRootContext();
+        // locate runtime in the global naming context
+        javax.naming.Context context = null;
+        try {
+            context = (javax.naming.Context) (new InitialContext()).lookup("java:/");
+            runtime = (RuntimeContext) context.lookup(RuntimeBootstrap.RUNTIME_NAME);
+            monitor = runtime.getMonitorFactory().getMonitor(RuntimeMonitor.class);
+        } catch (NamingException e) {
+            // FIXME need bootstrap logging;
+            return;
+        }
     }
 
     /**
@@ -73,14 +81,13 @@
             Context context = (Context) lifecycleEventSource;
             String name = context.getPath().substring(1);
             try {
-                // FIXME this will not work
                 ModuleComponent moduleComponent = runtime.loadModuleComponent(name, "sca.module");
                 if (moduleComponent == null) {
                     return; // not an SCA module component
                 }
                 // create the module component
                 runtime.registerModelObject(moduleComponent);
-                TuscanyModuleComponentContext moduleComponentContext = (TuscanyModuleComponentContext)
rootContext
+                TuscanyModuleComponentContext moduleComponentContext = (TuscanyModuleComponentContext)
runtime
                         .getContext(moduleComponent.getName());
                 TuscanyWebAppRuntime tuscanyRuntime = new TuscanyWebAppRuntime(moduleComponentContext);
                 context.getServletContext().setAttribute(TuscanyWebAppRuntime.class.getName(),
tuscanyRuntime);



Mime
View raw message