Skip to Content.
Sympa Menu

notify-dpml - r985 - in trunk/main: metro/model/src/main/net/dpml/metro metro/runtime/src/main/net/dpml/metro/runtime planet/http planet/http/demo/src/main/net/dpml/http/demo planet/http/demo/src/test/net/dpml/http planet/http/parts planet/http/parts/context

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r985 - in trunk/main: metro/model/src/main/net/dpml/metro metro/runtime/src/main/net/dpml/metro/runtime planet/http planet/http/demo/src/main/net/dpml/http/demo planet/http/demo/src/test/net/dpml/http planet/http/parts planet/http/parts/context
  • Date: Fri, 27 Jan 2006 23:00:26 +0100

Author: mcconnell
Date: 2006-01-27 23:00:24 +0100 (Fri, 27 Jan 2006)
New Revision: 985

Added:
trunk/main/metro/model/src/main/net/dpml/metro/ComponentContext.java
trunk/main/planet/http/parts/
trunk/main/planet/http/parts/context/
trunk/main/planet/http/parts/context/build.xml
Modified:
trunk/main/metro/model/src/main/net/dpml/metro/ComponentHandler.java
trunk/main/metro/model/src/main/net/dpml/metro/PartsManager.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ContextInvocationHandler.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
trunk/main/planet/http/demo/src/main/net/dpml/http/demo/Demo.java

trunk/main/planet/http/demo/src/main/net/dpml/http/demo/ManagementOperations.java
trunk/main/planet/http/demo/src/test/net/dpml/http/HttpTestCase.java
trunk/main/planet/http/module.xml
Log:
add implementation of dynamic http context loading in the http demo - in
doing this I've added a ComponentContext interface that a component
implementation can use to access controller-based component loading - demo
implementation is minimal but sufficient to validate things and move to the
next step of dynamically loading a content handler into a dynamically loaded
http context

Added: trunk/main/metro/model/src/main/net/dpml/metro/ComponentContext.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/ComponentContext.java
2006-01-27 17:19:29 UTC (rev 984)
+++ trunk/main/metro/model/src/main/net/dpml/metro/ComponentContext.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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 net.dpml.metro;
+
+import java.net.URI;
+
+import net.dpml.part.Controller;
+
+/**
+ * The ComponentContext interface may be referenced by a component
+ * context inner interface to expose container related services to
+ * a component implementation.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public interface ComponentContext
+{
+ /**
+ * Return the current controller.
+ * @return the root system controller
+ */
+ Controller getController();
+
+ /**
+ * Create a nested component handler.
+ * @param anchor the anchor classloader
+ * @param uri the component part definition
+ * @return the component handler
+ * @exception Exception if an error occurs during component loading or
establishment
+ */
+ ComponentHandler createComponentHandler( ClassLoader anchor, URI uri )
throws Exception;
+}
+

Modified: trunk/main/metro/model/src/main/net/dpml/metro/ComponentHandler.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/ComponentHandler.java
2006-01-27 17:19:29 UTC (rev 984)
+++ trunk/main/metro/model/src/main/net/dpml/metro/ComponentHandler.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -29,10 +29,10 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public interface ComponentHandler extends ComponentOperations
+public interface ComponentHandler extends ComponentOperations,
ComponentContext
{
/**
- * Return a mutible context map. The map may be used by component
+ * Return a mutable context map. The map may be used by component
* implementations to override context entries in the associated
* component instance.
*
@@ -41,7 +41,7 @@
Map getContextMap();

/**
- * Return the component model manager.
+ * Return the manager for the assigned component model.
* @return the component model manager
*/
ComponentManager getComponentManager();

Modified: trunk/main/metro/model/src/main/net/dpml/metro/PartsManager.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/PartsManager.java
2006-01-27 17:19:29 UTC (rev 984)
+++ trunk/main/metro/model/src/main/net/dpml/metro/PartsManager.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -32,7 +32,7 @@
public interface PartsManager
{
/**
- * Return the array of keys used to idenetity internal parts.
+ * Return the array of keys used to identify internal parts.
* @return the part key array
*/
String[] getKeys();

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
2006-01-27 17:19:29 UTC (rev 984)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -86,6 +86,11 @@

//--------------------------------------------------------------------------
// ComponentController

//--------------------------------------------------------------------------
+
+ CompositionController getCompositionController()
+ {
+ return m_controller;
+ }

/**
* Create a new remotely manageable component model.

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-01-27 17:19:29 UTC (rev 984)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -275,15 +275,6 @@
Controller controller = getPrimaryController( controllerURI
);
return controller.loadDirective( uri );
}
-
- /*
- ClassLoader loader = ComponentDirective.class.getClassLoader();
- Thread.currentThread().setContextClassLoader( loader );
- URL url = uri.toURL();
- InputStream input = url.openStream();
- XMLDecoder decoder = new XMLDecoder( new BufferedInputStream(
input ) );
- return (Directive) decoder.readObject();
- */
}
catch( Exception e )
{

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ContextInvocationHandler.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ContextInvocationHandler.java
2006-01-27 17:19:29 UTC (rev 984)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ContextInvocationHandler.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -22,6 +22,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

+import net.dpml.metro.ComponentContext;
import net.dpml.metro.info.EntryDescriptor;

/**
@@ -89,6 +90,10 @@
{
return method.invoke( this, args );
}
+ else if( ComponentContext.class == source )
+ {
+ return method.invoke( m_handler, args );
+ }
else
{
DefaultComponentHandler handler = getDefaultComponentHandler();

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-01-27 17:19:29 UTC (rev 984)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -38,6 +38,7 @@
import net.dpml.metro.info.CollectionPolicy;
import net.dpml.metro.info.Priority;
import net.dpml.metro.data.CategoryDirective;
+import net.dpml.metro.data.ComponentDirective;
import net.dpml.metro.ComponentModel;
import net.dpml.metro.ComponentHandler;
import net.dpml.metro.PartsManager;
@@ -45,6 +46,8 @@

import net.dpml.logging.Logger;

+import net.dpml.part.Controller;
+import net.dpml.part.Directive;
import net.dpml.part.ActivationPolicy;
import net.dpml.part.Disposable;
import net.dpml.part.ControlException;
@@ -249,6 +252,48 @@
}


//--------------------------------------------------------------------------
+ // ComponentContext
+
//--------------------------------------------------------------------------
+
+ /**
+ * Return the current controller.
+ * @return the root system controller
+ */
+ public Controller getController()
+ {
+ return m_controller.getCompositionController();
+ }
+
+ /**
+ * Create a nested component handler.
+ * @param anchor the anchor classloader
+ * @param uri the component part definition
+ * @return the component handler
+ * @exception Exception if an error occurs during component loading or
establishment
+ */
+ public ComponentHandler createComponentHandler( ClassLoader anchor, URI
uri ) throws Exception
+ {
+ Directive directive = getController().loadDirective( uri );
+ if( directive instanceof ComponentDirective )
+ {
+ ComponentDirective cd = (ComponentDirective) directive;
+ String partition = getPath() + "/";
+ ComponentModel model =
+ m_controller.createComponentModel( anchor, partition, cd );
+ return m_controller.createDefaultComponentHandler(
+ this, anchor, model, true );
+ }
+ else
+ {
+ final String error =
+ "Component directive class ["
+ + directive.getClass()
+ + "] is not supported.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+
//--------------------------------------------------------------------------
// ModelListener

//--------------------------------------------------------------------------


Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
2006-01-27 17:19:29 UTC (rev 984)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -49,6 +49,11 @@
//-------------------------------------------------------------------

/**
+ * Internal handle to the component controller.
+ */
+ private final ComponentController m_control;
+
+ /**
* The component handler.
*/
private final DefaultComponentHandler m_handler;
@@ -78,6 +83,7 @@
DefaultPartsManager( ComponentController control,
DefaultComponentHandler handler, Logger logger )
throws ControlException, RemoteException
{
+ m_control = control;
m_handler = handler;
m_logger = logger;


Modified: trunk/main/planet/http/demo/src/main/net/dpml/http/demo/Demo.java
===================================================================
--- trunk/main/planet/http/demo/src/main/net/dpml/http/demo/Demo.java
2006-01-27 17:19:29 UTC (rev 984)
+++ trunk/main/planet/http/demo/src/main/net/dpml/http/demo/Demo.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -16,12 +16,21 @@
package net.dpml.http.demo;

import java.io.Serializable;
+import java.net.URI;
import java.util.Date;
import java.util.Map;
+import java.util.Hashtable;

import net.dpml.logging.Logger;

+import net.dpml.metro.ComponentContext;
+import net.dpml.metro.ComponentHandler;
+
+import net.dpml.part.Controller;
+import net.dpml.part.Directive;
+
import net.dpml.http.spi.SocketListenerService;
+import net.dpml.http.impl.HttpContextImpl;

/**
* Working demo/test component. This component is aimed primarily
@@ -37,7 +46,7 @@
/**
* HTTP Demo component context.
*/
- public interface Context
+ public interface Context extends ComponentContext
{
/**
* Get the port on which the demo listener will be assigned.
@@ -70,7 +79,9 @@
//---------------------------------------------------------

private final Logger m_logger;
+ private final Context m_context;
private final Parts m_parts;
+ private final Map m_httpContextTable = new Hashtable(); // context path
to context mapping

//---------------------------------------------------------
// constructor
@@ -86,9 +97,10 @@
{
m_logger = logger;
m_parts = parts;
+ m_context = context;
int port = context.getPort( 8080 );
parts.getSocketListenerMap().put( "port", new Integer( port ) );
- m_parts.getSocketListener();
+ m_parts.getSocketListener(); // trigger activation
}

//---------------------------------------------------------
@@ -96,20 +108,33 @@
//---------------------------------------------------------

/**
- * Testing management interface declarations.
+ * Add a new http context to the application. This implementation
+ * is experimental and can be very significantly optimized however
+ * the primary object here is to test dynamic component loading.
+ * @param path the http context path
*/
- public void doSomething()
+ public void addContext( String path ) throws Exception
{
- getLogger().info( "Hello World!" );
- }
-
- /**
- * Add a new http context to the application.
- * @param path the context path
- */
- public void addContext( String path )
- {
+ if( m_httpContextTable.containsKey( path ) )
+ {
+ final String error =
+ "Component path ["
+ + path
+ + "] is already assigned to a http context instance.";
+ throw new IllegalArgumentException( error );
+ }
+
getLogger().info( "# ADD: " + path );
+ URI uri = new URI( "link:part:dpml/planet/http/dpml-http-context" );
+ ClassLoader anchor = ManagementOperations.class.getClassLoader();
+ ComponentHandler handler = m_context.createComponentHandler( anchor,
uri );
+ handler.getContextMap().put( "contextPath", path );
+ getLogger().info( "# HANDLER: " + handler );
+ m_httpContextTable.put( path, handler );
+ Object value = handler.getProvider().getValue( false );
+ getLogger().info( "# VALUE: " + value );
+
+ // .. now we can move ahead with dynamic addition of handlers to a
context
}

/**
@@ -127,8 +152,9 @@
*/
public String[] getContextPaths()
{
+ String[] keys = (String[]) m_httpContextTable.keySet().toArray( new
String[0] );
getLogger().info( "# LIST" );
- return new String[0];
+ return keys;
}

//---------------------------------------------------------

Modified:
trunk/main/planet/http/demo/src/main/net/dpml/http/demo/ManagementOperations.java
===================================================================
---
trunk/main/planet/http/demo/src/main/net/dpml/http/demo/ManagementOperations.java
2006-01-27 17:19:29 UTC (rev 984)
+++
trunk/main/planet/http/demo/src/main/net/dpml/http/demo/ManagementOperations.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -21,15 +21,10 @@
public interface ManagementOperations
{
/**
- * Do something.
- */
- void doSomething();
-
- /**
* Add a new http context to the application.
* @param path the context path
*/
- void addContext( String path );
+ void addContext( String path ) throws Exception;

/**
* Remove an http context from the application.

Modified: trunk/main/planet/http/demo/src/test/net/dpml/http/HttpTestCase.java
===================================================================
--- trunk/main/planet/http/demo/src/test/net/dpml/http/HttpTestCase.java
2006-01-27 17:19:29 UTC (rev 984)
+++ trunk/main/planet/http/demo/src/test/net/dpml/http/HttpTestCase.java
2006-01-27 22:00:24 UTC (rev 985)
@@ -54,7 +54,7 @@
try
{
Demo demo = (Demo) component.getProvider().getValue( false );
- demo.doSomething();
+ demo.addContext( "/test" );
}
catch( ControlException e )
{

Modified: trunk/main/planet/http/module.xml
===================================================================
--- trunk/main/planet/http/module.xml 2006-01-27 17:19:29 UTC (rev 984)
+++ trunk/main/planet/http/module.xml 2006-01-27 22:00:24 UTC (rev 985)
@@ -65,6 +65,20 @@
<include ref="dpml/metro/dpml-part-api"/>
<include ref="ant/ant-junit"/>
</dependencies>
+ <dependencies scope="build">
+ <include key="dpml-http-context"/>
+ </dependencies>
</project>

+ <project name="dpml-http-context" basedir="parts/context">
+ <types>
+ <type id="part" alias="true"/>
+ </types>
+ <dependencies>
+ <include ref="dpml/metro/dpml-metro-model"/>
+ <include urn="artifact:jar:servletapi/servletapi#2.3" tag="public"/>
+ <include key="dpml-http-impl"/>
+ </dependencies>
+ </project>
+
</module>

Added: trunk/main/planet/http/parts/context/build.xml
===================================================================
--- trunk/main/planet/http/parts/context/build.xml 2006-01-27 17:19:29
UTC (rev 984)
+++ trunk/main/planet/http/parts/context/build.xml 2006-01-27 22:00:24
UTC (rev 985)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * Copyright 2004-2005 Stephen J. McConnell.
+ *
+ * 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.dpml.net/central/about/legal/
+ *
+ * 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.
+-->
+
+<project name="dpml-http-context" default="install" basedir="."
+ xmlns:transit="antlib:net.dpml.transit"
+ xmlns:depot="dpml:depot" >
+
+ <transit:import uri="local:template:dpml/tools/standard"/>
+
+ <target name="build" depends="standard.build">
+ <depot:plugin uri="link:plugin:dpml/metro/dpml-metro-tools" urn="metro"/>
+ <component xmlns="metro" type="net.dpml.http.impl.HttpContextImpl"
collection="hard">
+ <context>
+ <entry key="server" lookup="net.dpml.http.spi.HttpService"/>
+ <entry key="requestLog" lookup="org.mortbay.http.RequestLog"/>
+ <entry key="tempDirectory" value="$${java.io.tmpdir}/http/context"/>
+ <entry key="contextPath" value="/"/>
+ <entry key="gracefulStop" value="true"/>
+ </context>
+ </component>
+ </target>
+
+</project>
+




  • r985 - in trunk/main: metro/model/src/main/net/dpml/metro metro/runtime/src/main/net/dpml/metro/runtime planet/http planet/http/demo/src/main/net/dpml/http/demo planet/http/demo/src/test/net/dpml/http planet/http/parts planet/http/parts/context, mcconnell at BerliOS, 01/27/2006

Archive powered by MHonArc 2.6.24.

Top of Page