Skip to Content.
Sympa Menu

notify-dpml - r1512 - in trunk/main/metro: model/src/main/net/dpml/metro runtime/src/main/net/dpml/metro/runtime

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: r1512 - in trunk/main/metro: model/src/main/net/dpml/metro runtime/src/main/net/dpml/metro/runtime
  • Date: Thu, 8 Jun 2006 10:10:52 +0200

Author: mcconnell
Date: 2006-06-08 10:10:50 +0200 (Thu, 08 Jun 2006)
New Revision: 1512

Modified:
trunk/main/metro/model/src/main/net/dpml/metro/ComponentModel.java
trunk/main/metro/model/src/main/net/dpml/metro/ComponentModelManager.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.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/DefaultComponentModel.java

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

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
Log:
runtime improvements

Modified: trunk/main/metro/model/src/main/net/dpml/metro/ComponentModel.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/ComponentModel.java
2006-06-08 05:24:09 UTC (rev 1511)
+++ trunk/main/metro/model/src/main/net/dpml/metro/ComponentModel.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -24,6 +24,7 @@

import net.dpml.metro.info.LifestylePolicy;
import net.dpml.metro.info.CollectionPolicy;
+import net.dpml.metro.info.PartReference;
import net.dpml.metro.data.CategoryDirective;

import net.dpml.lang.Classpath;
@@ -91,5 +92,12 @@
* @exception RemoteException if a remote exception occurs
*/
CategoryDirective[] getCategoryDirectives() throws RemoteException;
+
+ /**
+ * Return the default set of internal part directives.
+ * @return the internal part directive array
+ * @exception RemoteException if a remote exception occurs
+ */
+ PartReference[] getPartReferences() throws RemoteException;
}


Modified:
trunk/main/metro/model/src/main/net/dpml/metro/ComponentModelManager.java
===================================================================
--- trunk/main/metro/model/src/main/net/dpml/metro/ComponentModelManager.java
2006-06-08 05:24:09 UTC (rev 1511)
+++ trunk/main/metro/model/src/main/net/dpml/metro/ComponentModelManager.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -45,7 +45,7 @@
* @return the part keys
* @exception RemoteException if a remote I/O error occurs
*/
- String[] getPartKeys() throws RemoteException;
+ //String[] getPartKeys() throws RemoteException;

/**
* Return a subsidiary component manager.
@@ -55,8 +55,8 @@
* @exception RemoteException if a remote I/O error occurs
* @see #getPartKeys()
*/
- ComponentModelManager getComponentManager( String key )
- throws UnknownKeyException, RemoteException;
+ //ComponentModelManager getComponentManager( String key )
+ // throws UnknownKeyException, RemoteException;

/**
* Override the assigned collection policy.

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-06-08 05:24:09 UTC (rev 1511)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ComponentController.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -523,8 +523,10 @@
}
}

- Object getContextValue( DefaultComponentHandler handler, String key )
throws ControlException
+ Object getContextValue( DefaultProvider provider, String key ) throws
ControlException
{
+ DefaultComponentHandler handler =
provider.getDefaultComponentHandler();
+
try
{
ComponentModel model = handler.getComponentModel();
@@ -600,7 +602,7 @@
DefaultService service = loadService( handler, request );
try
{
- return executeLookup( handler, service );
+ return executeLookup( provider, service );
}
catch( Exception ee )
{
@@ -666,14 +668,21 @@
}
}

- private Object executeLookup( DefaultComponentHandler handler,
DefaultService service )
+ private Object executeLookup( DefaultProvider provider, DefaultService
service )
throws Exception
{
+ // Provider parent = provider.getParentProvider();
+
+ DefaultComponentHandler handler =
provider.getDefaultComponentHandler();
Component parent = handler.getParentHandler();
+
if( null != parent )
{
try
{
+ //Provider p = parent.lookup( service );
+ //return p.getValue( false );
+
Component component = parent.lookup( service );
return component.getProvider().getValue( false );
}

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-06-08 05:24:09 UTC (rev 1511)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/ContextInvocationHandler.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -22,6 +22,8 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

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

@@ -101,7 +103,8 @@
if( name.startsWith( "get" ) )
{
String key = EntryDescriptor.getEntryKey( method );
- Object value = handler.getContextValue( key );
+ Object value = getContextValue( key );
+ //Object value = handler.getContextValue( key );
if( null != value )
{
return value;
@@ -135,4 +138,9 @@
throw new NoSuchMethodException( name );
}
}
+
+ Object getContextValue( String key ) throws ControlException
+ {
+ return m_handler.getComponentController().getContextValue(
m_provider, key );
+ }
}

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-06-08 05:24:09 UTC (rev 1511)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentHandler.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -629,6 +629,11 @@
// DefaultComponentHandler

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

+ ComponentController getComponentController()
+ {
+ return m_controller;
+ }
+
/**
* Return the internal parts manager.
* @return the part manager
@@ -706,10 +711,10 @@
}
}

- Object getContextValue( String key ) throws ControlException
- {
- return m_controller.getContextValue( this, key );
- }
+ //Object getContextValue( String key ) throws ControlException
+ //{
+ // return m_controller.getContextValue( this, key );
+ //}

State getStateGraph()
{

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentModel.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentModel.java
2006-06-08 05:24:09 UTC (rev 1511)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultComponentModel.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 Stephen J. McConnell.
+ * Copyright 2005-2006 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.
@@ -71,19 +71,16 @@
private final ComponentDirective m_directive;
private final ClassLoader m_classloader;
private final Classpath m_classpath;
-
- private final List m_keys = new LinkedList();
- private final Hashtable m_parts = new Hashtable();
private final DefaultContextModel m_context;
private final String m_path;
+ private final PartReference[] m_references;
+ private final Class m_class;
+ private final String m_classname;

- private String m_classname;
private ActivationPolicy m_activation;
private LifestylePolicy m_lifestyle;
private CollectionPolicy m_collection;

- private Class m_class;
-
//
------------------------------------------------------------------------
// constructor
//
------------------------------------------------------------------------
@@ -101,38 +98,15 @@
m_classname = m_directive.getClassname();
m_class = m_controller.loadComponentClass( m_classloader,
m_classname );
m_type = m_controller.loadType( m_class );
-
- String name = m_directive.getName();
- if( null == name )
- {
- m_path = partition + m_type.getInfo().getName();
- }
- else
- {
- m_path = partition + name;
- }
-
+ m_path = setupPath( partition );
m_activation = m_directive.getActivationPolicy();
-
- LifestylePolicy lifestyle = m_directive.getLifestylePolicy();
- if( null == lifestyle )
- {
- m_lifestyle = m_type.getInfo().getLifestylePolicy();
- }
- else
- {
- m_lifestyle = lifestyle;
- }
-
+ m_lifestyle = setupLifestyle();
m_collection = m_directive.getCollectionPolicy();
ContextDirective context = m_directive.getContextDirective();
m_context = new DefaultContextModel( this, logger, m_classloader,
m_type, context );
-
- final String base = m_path + PARTITION_SEPARATOR;
- processParts( controller, m_classloader, m_type, m_parts, base );
- processParts( controller, m_classloader, m_directive, m_parts, base
);
+ m_references = buildPartReferences();
}
-
+
public DefaultComponentModel(
Logger logger, ClassLoader anchor, ComponentController controller,
Classpath classpath,
ComponentDirective directive, String partition )
@@ -143,74 +117,26 @@
m_classpath = classpath;
m_controller = controller;
m_directive = directive;
-
m_classloader = m_controller.getClassLoader( anchor, classpath );
m_classname = directive.getClassname();
m_class = m_controller.loadComponentClass( m_classloader,
m_classname );
m_type = m_controller.loadType( m_class );
-
- String name = directive.getName();
- if( null == name )
- {
- m_path = partition + m_type.getInfo().getName();
- }
- else
- {
- m_path = partition + name;
- }
-
+ m_path = setupPath( partition );
m_activation = directive.getActivationPolicy();
-
- LifestylePolicy lifestyle = directive.getLifestylePolicy();
- if( null == lifestyle )
- {
- m_lifestyle = m_type.getInfo().getLifestylePolicy();
- }
- else
- {
- m_lifestyle = lifestyle;
- }
-
+ m_lifestyle = setupLifestyle();
m_collection = directive.getCollectionPolicy();
ContextDirective context = directive.getContextDirective();
m_context = new DefaultContextModel( this, logger, m_classloader,
m_type, context );
-
- final String base = m_path + PARTITION_SEPARATOR;
- processParts( controller, m_classloader, m_type, m_parts, base );
- processParts( controller, m_classloader, m_directive, m_parts, base
);
+ m_references = buildPartReferences();
}

- private void processParts(
- ComponentController controller, ClassLoader classloader, Composite
composite, Map map, String base )
- throws ControlException, RemoteException
+ /**
+ * Return the inital array of part references.
+ * @return the part reference array
+ */
+ public PartReference[] getPartReferences()
{
- PartReference[] references = composite.getPartReferences();
- for( int i=0; i < references.length; i++ )
- {
- PartReference ref = references[i];
- String key = ref.getKey();
- Directive part = composite.getDirective( key );
- if( part instanceof ComponentDirective )
- {
- Classpath classpath = new Classpath();
- ComponentDirective component = (ComponentDirective) part;
- ComponentModel model =
- controller.createComponentModel( classloader, classpath,
base, component );
- if( !map.containsKey( key ) )
- {
- m_keys.add( key );
- }
- map.put( key, model );
- }
- else
- {
- final String error =
- "Foreign part ["
- + part.getClass()
- + "] not supported.";
- throw new UnsupportedOperationException( error );
- }
- }
+ return m_references;
}

public Classpath getClasspath()
@@ -390,35 +316,8 @@
throw new IllegalStateException( error );
}
}
-
+
/**
- * Return the internal part keys.
- * @return the component part keys
- */
- public String[] getPartKeys()
- {
- return (String[]) m_keys.toArray( new String[0] );
- //return (String[]) m_parts.keySet().toArray( new String[0] );
- }
-
- /**
- * Return the component model of an internal part referenced by the
supplied key.
- * @return the internal part component model
- */
- public ComponentModelManager getComponentManager( String key ) throws
UnknownKeyException
- {
- ComponentModelManager model = (ComponentModelManager) m_parts.get(
key );
- if( null == model )
- {
- throw new UnknownKeyException( key );
- }
- else
- {
- return model;
- }
- }
-
- /**
* Return the component logging categories.
* @return the categories
* @exception RemoteException if a remote exception occurs
@@ -440,15 +339,6 @@
// DefaultComponentModel
//
------------------------------------------------------------------------

- /**
- * Return the internal component models.
- * @return the internal component model array
- */
- ComponentModel[] getComponentModels()
- {
- return (ComponentModel[]) m_parts.values().toArray( new
ComponentModel[0] );
- }
-
ClassLoader getClassLoader()
{
return m_classloader;
@@ -468,15 +358,62 @@
// internals
//
------------------------------------------------------------------------

- private String[] getPartKeys( Type type )
+ private String setupPath( String partition )
{
- PartReference[] references = m_type.getPartReferences();
- String[] keys = new String[ references.length ];
- for( int i=0; i<references.length; i++ )
+ String name = m_directive.getName();
+ if( null == name )
{
- keys[i] = references[i].getKey();
+ return partition + m_type.getInfo().getName();
}
- return keys;
+ else
+ {
+ return partition + name;
+ }
}
+
+ private LifestylePolicy setupLifestyle()
+ {
+ LifestylePolicy lifestyle = m_directive.getLifestylePolicy();
+ if( null == lifestyle )
+ {
+ return m_type.getInfo().getLifestylePolicy();
+ }
+ else
+ {
+ return lifestyle;
+ }
+ }
+
+ private PartReference[] buildPartReferences()
+ {
+ List list = new LinkedList();
+ Map map = new Hashtable();
+ populatePartReferences( list, map, m_type );
+ populatePartReferences( list, map, m_directive );
+ PartReference[] refs = new PartReference[ list.size() ];
+ String[] names = (String[]) list.toArray( new String[0] );
+ for( int i=0; i<names.length; i++ )
+ {
+ String name = names[i];
+ PartReference ref = (PartReference) map.get( name );
+ refs[ i ] = ref;
+ }
+ return refs;
+ }
+
+ private void populatePartReferences( List names, Map map, Composite
composite )
+ {
+ PartReference[] references = composite.getPartReferences();
+ for( int i=0; i < references.length; i++ )
+ {
+ PartReference ref = references[i];
+ String key = ref.getKey();
+ if( !names.contains( key ) )
+ {
+ names.add( key );
+ }
+ map.put( key, ref );
+ }
+ }
}


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-06-08 05:24:09 UTC (rev 1511)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -29,6 +29,7 @@
import net.dpml.component.Component;
import net.dpml.component.Model;
import net.dpml.component.Service;
+import net.dpml.component.Directive;

import net.dpml.job.CommissionerEvent;
import net.dpml.job.CommissionerController;
@@ -36,13 +37,16 @@
import net.dpml.job.TimeoutError;
import net.dpml.job.impl.DefaultCommissioner;

+import net.dpml.lang.Classpath;
+import net.dpml.lang.UnknownKeyException;
import net.dpml.lang.Version;
-import net.dpml.lang.UnknownKeyException;

import net.dpml.metro.PartsManager;
import net.dpml.metro.ComponentHandler;
import net.dpml.metro.ComponentModelManager;
import net.dpml.metro.ComponentModel;
+import net.dpml.metro.info.PartReference;
+import net.dpml.metro.data.ComponentDirective;

import net.dpml.util.Logger;

@@ -79,13 +83,17 @@
private final Map m_handlers = new Hashtable();

private boolean m_commissioned = false;
-
+
+ private final Map m_parts;
+
+ private final String[] m_keys;
+
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------

/**
- * Create a new instance handler.
+ * Create a new parts manager.
*
* @param handler the component handler
* @param logger the logging channel
@@ -98,28 +106,24 @@
m_logger = logger;

ClassLoader classloader = handler.getClassLoader();
- ComponentModelManager model = handler.getComponentManager();
- String[] keys = model.getPartKeys();
- for( int i=0; i<keys.length; i++ )
+ ComponentModel model = handler.getComponentModel();
+ PartReference[] references = model.getPartReferences();
+
+ m_keys = getKeys( references );
+
+ String partition = model.getContextPath();
+ final String base = partition + Model.PARTITION_SEPARATOR;
+ m_parts = processParts( control, classloader, base, references );
+ for( int i=0; i<references.length; i++ )
{
- String key = keys[i];
+ PartReference reference = references[i];
+ String key = reference.getKey();
try
{
- ComponentModelManager m = model.getComponentManager( key );
- ComponentModel cm = (ComponentModel) m;
- Component h = control.createDefaultComponentHandler(
handler, classloader, cm, true );
- m_handlers.put( key, h );
+ ComponentModel manager = (ComponentModel) m_parts.get( key );
+ Component component = control.createDefaultComponentHandler(
handler, classloader, manager, true );
+ m_handlers.put( key, component );
}
- catch( UnknownKeyException e )
- {
- final String error =
- "Invalid part key ["
- + key
- + "] in component ["
- + handler
- + "]";
- throw new ControllerRuntimeException( error, e );
- }
catch( Exception e )
{
final String error =
@@ -148,18 +152,7 @@
*/
public String[] getKeys()
{
- try
- {
- return m_handler.getComponentManager().getPartKeys();
- }
- catch( RemoteException e )
- {
- final String error =
- "Remote IO error while attempting to get parts keys in
component ["
- + m_handler
- + "]";
- throw new ControllerRuntimeException( error, e );
- }
+ return m_keys;
}

/**
@@ -367,16 +360,6 @@
"Ignoring exception raised during deactivation.";
getLogger().warn( message, e );
}
- //try
- //{
- // component.decommission();
- //}
- //catch( RemoteException e )
- //{
- // final String message =
- // "Ignoring remote exception raised during
deactivation.";
- // getLogger().warn( message, e );
- //}
}
}
finally
@@ -395,6 +378,36 @@
return m_logger;
}

+ private Map processParts(
+ ComponentController controller, ClassLoader classloader, String base,
PartReference[] references )
+ throws ControlException, RemoteException
+ {
+ Map map = new Hashtable();
+ for( int i=0; i < references.length; i++ )
+ {
+ PartReference ref = references[i];
+ String key = ref.getKey();
+ Directive part = ref.getDirective();
+ if( part instanceof ComponentDirective )
+ {
+ Classpath classpath = new Classpath();
+ ComponentDirective component = (ComponentDirective) part;
+ ComponentModel model =
+ controller.createComponentModel( classloader, classpath,
base, component );
+ map.put( key, model );
+ }
+ else
+ {
+ final String error =
+ "Foreign part ["
+ + part.getClass()
+ + "] not supported.";
+ throw new UnsupportedOperationException( error );
+ }
+ }
+ return map;
+ }
+
/**
* Test controller.
*/
@@ -549,4 +562,16 @@
}
}
}
+
+ private String[] getKeys( PartReference[] references )
+ {
+ String[] keys = new String[ references.length ];
+ for( int i=0; i < references.length; i++ )
+ {
+ PartReference ref = references[i];
+ String key = ref.getKey();
+ keys[i] = key;
+ }
+ return keys;
+ }
}

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
2006-06-08 05:24:09 UTC (rev 1511)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultProvider.java
2006-06-08 08:10:50 UTC (rev 1512)
@@ -98,6 +98,8 @@
*/
private boolean m_disposed = false;

+ //private final DefaultPartsManager m_parts;
+
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
@@ -126,6 +128,9 @@
State graph = handler.getStateGraph();
m_machine = new DefaultStateMachine( graph );
m_machine.addPropertyChangeListener( new StateEventPropergator( this
) );
+
+ //m_parts = new DefaultPartsManager( control, handler, logger );
+
initialize();
}





  • r1512 - in trunk/main/metro: model/src/main/net/dpml/metro runtime/src/main/net/dpml/metro/runtime, mcconnell at BerliOS, 06/08/2006

Archive powered by MHonArc 2.6.24.

Top of Page