You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Marcus Crafter <cr...@fztig938.bank.dresdner.net> on 2002/07/08 18:46:06 UTC

Fortress questions

Hi All,

	Hope all is well.
	
	Couple of questions about Fortress.

	1. How should a Container get a reference to its own CM/SM - via
	getComponentManager() or via compose()/service().

	getComponentManager() currently means you have to write code like:
	
	public void initialize() throws Exception
	{
		super.initialize();
		m_manager = getComponentManager();
	}
       	
	(compose()/service() currently aren't invoked if there's no parent
	manager given to the container so that above code can't be placed
	there).

	IMHO, I think it would be better if the component/service manager
	was available in a protected m_componentManager variable at the
	AbstractContainer level, after compose()/service() is called.

	Something like (in AbstractContainer):
	
		protected ComponentManager m_componentManager;
		
		public void compose(ComponentManager cm)
			throws ComponentException
		{
			// parent component manager specified)
			if (cm != null)
			{
				m_componentManager =
					new FortressComponentManager(this, cm);
			}
			// no parent component manager specified
			else
			{
				m_componentManager = 
					new FortressComponentManager(this);
			}
		}
		
	and something similar in service().
	
	An alternative would be where the CM passed into compose() is
	actually the container's CM, with any specified parent-CM parenting it.
	(but perhaps this breaks Composable's contract ?)
	 
	Either way, it would be good if it could all be set up during
	compose()/service(), but from what I see, this is difficult to do due
	to the possible presence of Composable *or* Servicable.
	
	(ie. a container can currently have a Composable or Servicable parent)
	
	Which leads to:

	2. Composable and Serviceable - how are they meant to work together ?

	Currently in Fortress you can only have a Composable or a Servicable
	Container, not both *but* it is possible to have an external
	ServiceManager parenting a ComponentManager inside the container and
	vice versa.
	
	This can occur when one specifies a ServiceManager as parent to the
	container, but uses ComponentManager inside the container
	(and vice versa).
	
	On one side this is advantageous as it means you can supply a parent
	CM/SM to a container, without knowing whether it uses a CM or SM
	internally, but on the other side it sets up the container for
	potential runtime problems, eg. if a ServiceManager parent returns a
	non-Component castable object to a component manager inside of the
	container.
	
	I feel that this could be dangerous - should we actually allow this
	mixing of Service and Component managers ?
	
	3. Asynchronous initialization of component handlers seems to be
	broken.

	From what I can see the asynchronous initialization code within
	Fortress isn't working. When I trace through the code the component
	handlers aren't initialized until components are actually lookup()'d.
	
	In the ContextManager a default CommandQueue object is created if one
	is not specified (and also if setCommandQueue(null) is given to the
	ContextBuilder (which seems suspicious)) and there seems to be no
	ThreadManager associated with the CommandQueue, so initialize()'s are
	only done inside FortressComponent/ServiceManager.lookup().
	
	Unfortunately I don't know the event and queue code well enough to
	fix this problem if my analysis is correct. Any thoughts from the
	more experienced developers there ?
	
	That's it for the moment! Any ideas, feedback would be much
	appreciated :)
	
	Cheers,
	
	Marcus
	
-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Peter Royal <pr...@apache.org>.
On Tuesday 09 July 2002 06:11 am, Marcus Crafter wrote:
> 	One other question for you if its ok - in your container, how are
> 	you solving my first question about getting a component manager
> 	reference inside of the container ?

I don't.

My container is managed by a phoenix block. My subclass of AbstractContainer 
exposes a single method,

public ComponentManager getCM()
{
  return this.getComponentManager();
}

which is called by the block after initializing the container.

If I needed to get a handle to the container's CM from inside the container, I 
would probably override initialize() as you did.
-pete


-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Marcus Crafter <cr...@fztig938.bank.dresdner.net>.
Hi Peter,

On Mon, Jul 08, 2002 at 02:46:09PM -0400, Peter Royal wrote:
> On Monday 08 July 2002 01:21 pm, Marcus Crafter wrote:
> > 	One of my ThreadSafe components wasn't being start()ed until I
> > 	actually looked it up. If I forced sync init, everything worked
> > 	fine, but with async init, it didn't.
> 
> Just guessing here, but could another component have stalled the queue?

	Unfortunately not, there was only one component :)
	
	Thanks for posting the code, none of that CommandManager/ThreadManager
	code is in the current Fortress code base, so I suspect its just
	not being registered (?).
	
	One other question for you if its ok - in your container, how are
	you solving my first question about getting a component manager
	reference inside of the container ?
	
	Do you call getComponentManager() somewhere, or access the component
	handlers directly ? or something else ?

...<snip cool code>...

> > 	Unfortunately setCommandQueue(null) does not disable async init,
> > 	as I thought it would due to OverridableContext which throws an
> > 	exception if a null is stored :(
> 
> imho we need an explicit way to disable the async.

	*nod* I agree.
	
	Cheers,
	
	Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Peter Royal <pr...@apache.org>.
On Monday 08 July 2002 01:21 pm, Marcus Crafter wrote:
> 	One of my ThreadSafe components wasn't being start()ed until I
> 	actually looked it up. If I forced sync init, everything worked
> 	fine, but with async init, it didn't.

Just guessing here, but could another component have stalled the queue?

> 	Ok, so you created a command queue instead of using the default
> 	one that's created if its not specified. Would be great if you
> 	could post the code how its created & registered with the
> 	ThreadManager ? :)

    private ContextBuilder createContextBuilder() throws Exception
    {
        final ContextBuilder builder = new ContextBuilder( createContext() );
        final CommandManager cm = new CommandManager();

        this.m_containerConfiguration =
          ConfigurationHelper.buildConfiguration( 
Thread.currentThread().getContextClassLoader(),
                                                  
this.m_blockConfiguration.getChild( Constants.CONFIG_XCONF_FILE ).getValue() 
);

        createThreadManager( cm );

        this.m_roleManager = createRoleManager();

        builder.setContainerClass( ObjectModelContainer.class );
        builder.setContextDirectory( m_blockContext.getBaseDirectory() );
        builder.setWorkDirectory( m_blockContext.getBaseDirectory() );
        builder.setComponentManagerParent( this.m_blocksManager );
        builder.setContainerConfiguration( this.m_containerConfiguration );
        builder.setRoleManager( this.m_roleManager );
        builder.setLoggerManager( new LoggerLoggerManager( 
getLogger().getChildLogger( "container" ) ) );
        builder.setCommandQueue( cm.getCommandQueue() );
//        builder.setCommandQueue( null );

        return builder;
    }

    private void createThreadManager( final CommandManager cm ) throws 
Exception
    {
        this.m_containerThreadManager = new TPCThreadManager();

        ContainerUtil.enableLogging( this.m_containerThreadManager, 
getLogger().getChildLogger( "thread-manager" ) );
        ContainerUtil.parameterize( this.m_containerThreadManager, 
createThreadManagerParameters() );
        ContainerUtil.initialize( this.m_containerThreadManager );

        this.m_containerThreadManager.register( cm );
    }

    private Parameters createThreadManagerParameters()
    {
        Parameters p = new Parameters();

        p.setParameter( "threads-per-processor", "2" );

        return p;
    }


> 	Unfortunately setCommandQueue(null) does not disable async init,
> 	as I thought it would due to OverridableContext which throws an
> 	exception if a null is stored :(

imho we need an explicit way to disable the async.
-pete

-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Marcus Crafter <cr...@fztig938.bank.dresdner.net>.
On Mon, Jul 08, 2002 at 12:56:53PM -0400, Peter Royal wrote:
> On Monday 08 July 2002 12:46 pm, Marcus Crafter wrote:
> > 	From what I can see the asynchronous initialization code within
> > 	Fortress isn't working. When I trace through the code the component
> > 	handlers aren't initialized until components are actually lookup()'d.
> 
> Are you tracing w/a debugger? If the other thread might not get a chance to 
> run if you are stepping through with a debugger.

	One of my ThreadSafe components wasn't being start()ed until I
	actually looked it up. If I forced sync init, everything worked
	fine, but with async init, it didn't.
	
	I also checked it with jswat too, but didn't completely trust the
	results as you pointed out too.

> > 	In the ContextManager a default CommandQueue object is created if one
> > 	is not specified (and also if setCommandQueue(null) is given to the
> > 	ContextBuilder (which seems suspicious)) and there seems to be no
> > 	ThreadManager associated with the CommandQueue, so initialize()'s are
> > 	only done inside FortressComponent/ServiceManager.lookup().
> 
> The auto-creation of a CommandQueue doesn't work, for the reasons you noted.
> 
> > 	Unfortunately I don't know the event and queue code well enough to
> > 	fix this problem if my analysis is correct. Any thoughts from the
> > 	more experienced developers there ?
> 
> The async init does work though, if you specify a CommandQueue via the 
> ContextBuilder.setCommandQueue(). I have it working here (verified w/log msgs 
> and the source for some is the ThreadManager thread).

	Ok, so you created a command queue instead of using the default
	one that's created if its not specified. Would be great if you
	could post the code how its created & registered with the
	ThreadManager ? :)
	
	Unfortunately setCommandQueue(null) does not disable async init,
	as I thought it would due to OverridableContext which throws an
	exception if a null is stored :(
	
	Cheers,
	
	Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Peter Royal <pr...@apache.org>.
On Monday 08 July 2002 12:46 pm, Marcus Crafter wrote:
> 	From what I can see the asynchronous initialization code within
> 	Fortress isn't working. When I trace through the code the component
> 	handlers aren't initialized until components are actually lookup()'d.

Are you tracing w/a debugger? If the other thread might not get a chance to 
run if you are stepping through with a debugger.

> 	In the ContextManager a default CommandQueue object is created if one
> 	is not specified (and also if setCommandQueue(null) is given to the
> 	ContextBuilder (which seems suspicious)) and there seems to be no
> 	ThreadManager associated with the CommandQueue, so initialize()'s are
> 	only done inside FortressComponent/ServiceManager.lookup().

The auto-creation of a CommandQueue doesn't work, for the reasons you noted.

> 	Unfortunately I don't know the event and queue code well enough to
> 	fix this problem if my analysis is correct. Any thoughts from the
> 	more experienced developers there ?

The async init does work though, if you specify a CommandQueue via the 
ContextBuilder.setCommandQueue(). I have it working here (verified w/log msgs 
and the source for some is the ThreadManager thread).
-pete



-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Marcus Crafter <cr...@fztig938.bank.dresdner.net>.
On Mon, Jul 08, 2002 at 01:04:29PM -0400, Berin Loritsch wrote:
> > From: Marcus Crafter [mailto:crafterm@fztig938.bank.dresdner.net] 
> > 
> > 	1. How should a Container get a reference to its own CM/SM - via
> > 	getComponentManager() or via compose()/service().
> 
>       The CM/SM is merely a lookup interface for the internals of the
>       Container.  The getComponentManager()/getServiceManager() methods
>       are factory methods so that each client can have its own copy.
> 
>       This is a plus, because we can safely delay thread contention issues
>       until the last possible minute.
> 
> > 	public void initialize() throws Exception
> > 	{
> > 		super.initialize();
> > 		m_manager = getComponentManager();
> > 	}
> 
> 
>       ?!

	Yes, terrible isn't it :)

>       Danger Will Robinson!  Danger!  Subversion of Control is bad.
>       If an AbstractContainer is Composable or Serviceable it will get
>       the parent manager from the compose()/service() methods.  It is
>       the ContainerManager's responsibility to provide one.  If it doesn't
>       then there is a bug.

	Currently AbstractContainer is both Composable and Serviceable, however
	compose() and service() are only called on the container, if a
	parent CM or SM is provided via the ContextBuilder.
	
	This means if you want a componentManager reference inside of a
	container, you have to do it in initialize or on the fly :(
	
	This is why I was proposing that the component manager reference
	be set to a protected variable in compose(), and that compose
	always be called, either with a valid parent CM, or null as the
	parent CM if none was given.
	
> > 	IMHO, I think it would be better if the component/service manager
> > 	was available in a protected m_componentManager variable at the
> > 	AbstractContainer level, after compose()/service() is called.
> 
>       There is a huge difference between a parent CM and the managed
>       component's CM.  The AbstractContainer creates a new ServiceManager
>       All the components created and managed by Fortress are given a
>       FortressComponentManager or a FortressServiceManager.  If the
>       container does not handle that type of component, it will lookup
>       in the parent component manager.
> 
>       Don't confuse the two CMs.

	Ok - I understand the difference between the 2 CM's, the question
	is how can I fix it so I don't have to write the code above to get
	a reference to the component manager ?
	
	At the moment you have to do:
	
	public void initialize()
	{
		super.initialize();
		m_manager = getComponentManager();
	}
	
	which I don't like either, or something like:
	
	public void someMethodOnMyContainer()
	{
		ComponentManager cm = getComponentManager();
		MyComponent comp = (MyComponent) cm.lookup(MyComponent.ROLE);
		...
		...
		cm.release(comp);
	}
	
	which is ok, but requires calling getComponentManager() each time
	you want the reference. 
	
	I'd find it better if we could allow the component manager reference 
	to be set (like how we advocate when writing Components) in compose():
	
	(in AbstractContainer)
	
	public void compose(ComponentManager cm)
		throws ComponentException
	{
		// parent component manager specified
		if (cm != null)
		{
			m_componentManager =
				// this = container
				// cm = parent CM
				new FortressComponentManager(this, cm);
		}
		// no parent component manager specified
		else
		{
			m_componentManager =
				// this = container
				new FortressComponentManager(this);
		}
	}
	
	(then we wouldn't need getComponentManager(), as it the CM would
	already be available in m_componentManager, ditto for ServiceManager).
	
	This does what you said above. That is, if a component of a
	particular type is not supported by the Container, then its
	fetched from the parent CM - and it also means one doesn't have to
	write mucky initialize() methods or excessive on-the-fly
	getComponentManager() calls to get a CM reference.
	
	Is that clearer ? or have I missed something ?

> > 	Currently in Fortress you can only have a Composable or 
> > a Servicable
> > 	Container, not both *but* it is possible to have an external
> > 	ServiceManager parenting a ComponentManager inside the 
> > container and
> > 	vice versa.
> 
> We have a way of wrapping the ComponentManager or ServiceManager
> so that they can be used interchangeably.

	This is what I meant by 'together' - how can they be used
	interchangeably - If a wrapped ServiceManager returns an Object, the
	cast to Component could fail, and we have no way of preventing this
	from happening. Isn't this a danger we should fix ?
	
	Cheers,
	
	Marcus

-- 
        .....
     ,,$$$$$$$$$,      Marcus Crafter
    ;$'      '$$$$:    Computer Systems Engineer
    $:         $$$$:   ManageSoft GmbH
     $       o_)$$$:   82-84 Mainzer Landstrasse
     ;$,    _/\ &&:'   60327 Frankfurt Germany
       '     /( &&&
           \_&&&&'
          &&&&.
    &&&&&&&:

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Peter Royal <pr...@apache.org>.
On Monday 08 July 2002 01:18 pm, Berin Loritsch wrote:
> Let's not exploit the bug then.  Let's provide two concrete
> containers: one that does lazy initialization, and one that
> does async initialization.
>
> Both can be extended, and use the common parts of AbstractContainer.
> It also helps AbstractContainer to be more abstract and let the
> concrete version choose the initialization policy.

AbstractContainer is fine, its the ContextManager that is at fault. It would 
be a waste to create a ThreadManager + CommandManager from the ContextManager 
and not have the container use them.
-pete

-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Fortress questions

Posted by Berin Loritsch <bl...@apache.org>.
> From: Peter Royal [mailto:proyal@apache.org] 
> 
> On Monday 08 July 2002 01:04 pm, Berin Loritsch wrote:
> > > 	In the ContextManager a default CommandQueue object is 
> created if 
> > > one
> > > 	is not specified (and also if setCommandQueue(null) is 
> given to the
> > > 	ContextBuilder (which seems suspicious)) and there
> > > seems to be no
> > > 	ThreadManager associated with the CommandQueue, so
> > > initialize()'s are
> > > 	only done inside FortressComponent/ServiceManager.lookup().
> >
> > We need to make the CommandManager initialize a default 
> ThreadManager 
> > if one isn't provided.
> 
> Is that really what we want?
> 
> Currently there is no way to *not* use the async init (other 
> than exploiting 
> the above bug). It'd be nice to keep that option.

Let's not exploit the bug then.  Let's provide two concrete
containers: one that does lazy initialization, and one that
does async initialization.

Both can be extended, and use the common parts of AbstractContainer.
It also helps AbstractContainer to be more abstract and let the
concrete version choose the initialization policy.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Fortress questions

Posted by Peter Royal <pr...@apache.org>.
On Monday 08 July 2002 01:04 pm, Berin Loritsch wrote:
> > 	In the ContextManager a default CommandQueue object is
> > created if one
> > 	is not specified (and also if setCommandQueue(null) is
> > given to the
> > 	ContextBuilder (which seems suspicious)) and there
> > seems to be no
> > 	ThreadManager associated with the CommandQueue, so
> > initialize()'s are
> > 	only done inside FortressComponent/ServiceManager.lookup().
>
> We need to make the CommandManager initialize a default ThreadManager
> if one isn't provided.

Is that really what we want?

Currently there is no way to *not* use the async init (other than exploiting 
the above bug). It'd be nice to keep that option.
-pete

-- 
peter royal -> proyal@apache.org

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Fortress questions

Posted by Berin Loritsch <bl...@apache.org>.
> From: Marcus Crafter [mailto:crafterm@fztig938.bank.dresdner.net] 
> 
> Hi All,
> 
> 	Hope all is well.
> 	
> 	Couple of questions about Fortress.
> 
> 	1. How should a Container get a reference to its own CM/SM - via
> 	getComponentManager() or via compose()/service().

      The CM/SM is merely a lookup interface for the internals of the
      Container.  The getComponentManager()/getServiceManager() methods
      are factory methods so that each client can have its own copy.

      This is a plus, because we can safely delay thread contention
issues
      until the last possible minute.


> 	public void initialize() throws Exception
> 	{
> 		super.initialize();
> 		m_manager = getComponentManager();
> 	}


      ?!

      Danger Will Robinson!  Danger!  Subversion of Control is bad.
      If an AbstractContainer is Composable or Serviceable it will get
      the parent manager from the compose()/service() methods.  It is
      the ContainerManager's responsibility to provide one.  If it
doesn't
      then there is a bug.


> 	IMHO, I think it would be better if the 
> component/service manager
> 	was available in a protected m_componentManager variable at the
> 	AbstractContainer level, after compose()/service() is called.


      There is a huge difference between a parent CM and the managed
      component's CM.  The AbstractContainer creates a new
ServiceManager
      All the components created and managed by Fortress are given a
      FortressComponentManager or a FortressServiceManager.  If the
      container does not handle that type of component, it will lookup
      in the parent component manager.

      Don't confuse the two CMs.


> 	2. Composable and Serviceable - how are they meant to 
> work together ?


They are mutually exclusive.  They should not be used together.


> 	Currently in Fortress you can only have a Composable or 
> a Servicable
> 	Container, not both *but* it is possible to have an external
> 	ServiceManager parenting a ComponentManager inside the 
> container and
> 	vice versa.


We have a way of wrapping the ComponentManager or ServiceManager
so that they can be used interchangeably.

> 	
> 	I feel that this could be dangerous - should we 
> actually allow this
> 	mixing of Service and Component managers ?

No!


> 	3. Asynchronous initialization of component handlers seems to be
> 	broken.

We need to fix it.

> 
> 	From what I can see the asynchronous initialization code within
> 	Fortress isn't working. When I trace through the code 
> the component
> 	handlers aren't initialized until components are 
> actually lookup()'d.


Hmm. :/

Lazy initialization != asynchronous initialization.  What happened?
It used to work?


> 	In the ContextManager a default CommandQueue object is 
> created if one
> 	is not specified (and also if setCommandQueue(null) is 
> given to the
> 	ContextBuilder (which seems suspicious)) and there 
> seems to be no
> 	ThreadManager associated with the CommandQueue, so 
> initialize()'s are
> 	only done inside FortressComponent/ServiceManager.lookup().
> 	
> 	Unfortunately I don't know the event and queue code 
> well enough to
> 	fix this problem if my analysis is correct. Any 
> thoughts from the
> 	more experienced developers there ?


We need to make the CommandManager initialize a default ThreadManager
if one isn't provided.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>