You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Berin Loritsch <bl...@apache.org> on 2001/11/30 19:31:39 UTC

[VOTE] ComponentUtil

The following snippet is supposed to describe how ComponentUtil was envisioned
to perform.  Unfortunately, Java does not pass primitives by reference, but
by value.

public class SimpleComponent implements Component, Initializable {
     final int m_mask;
     int m_state = 0;

     public SimpleComponent()
     {
        m_mask = ComponentUtil.getMask(this);
     }

     public void initialize () throws Exception
     {
        ComponentUtil.checkInitialized(m_state);

        //do stuff
     }
}


If we do not like this usage pattern, then we should choose once and for all
whether to provide it or not.


Include ComponentUtil?

Since it is broken and I really want to get Avalon Framework 4.1 out the door,
I vote -1, remove it.

-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


Re: [VOTE] ComponentUtil

Posted by Berin Loritsch <bl...@apache.org>.
Peter Donald wrote:

> On Sat, 1 Dec 2001 05:31, Berin Loritsch wrote:
> 
> Well I think it is kinda nice but I can't see it being used widely enough to 
> be included in framework. Maybe it would be best to include it in excalibur 
> somewhere (maybe excalibur.util ?)


NO!  It needs to be in Framework to be effective.  A framework becomes more
effective when it provides tools to enforce the contracts that are declared by
the framework.  Honestly, just because _you_ wouldn't use it does not mean
that others would not.


> Put bluntly it is highly unlikely I would ever use it or recomend using it. 
> The main reason it assumes that the environment in whihc you are working has 
> 
> a) a dodgy container


This is likely to occur when developers create Components that act as containers
for other components.  You MUST test for this!



> b) evil clients who can get direct reference to component


You can never rule this out.  It is like saying we should get rid of file permissions
just because noone is *supposed* to be able to gain access to it in a
non-prescribed manner.  Just as UNIX as a platform is hostile to viruses,
Avalon needs to be Hostile to malcontent environments.  Ignoring a potential
hole because _you_ are not concerned with it is stupidity.  It will inevitable
come and bite you in the hind quarters sooner or later.  Period.


> Even if you manage to shore up all the holes the component can still be 
> fubared by another evil component going
> 
> synchronized( myComponent )
> {
>   while( 1 ) System.sleep(100000000);
> }


Look who's been writing C++ lately!  (while only responds to boolean values,
this won't compile) ;p

Seriously, you need to close up the holes you can.  Stuff that is beyond your
control, you have to prepare for, BUT don't leave open invitations and an unlocked
door just because someone can fit down your chimney.


> If (b) is the case you are protecting against then your container should 
> never hand out direct references but instead hand out references wrapped in 
> proxies (maybe by 1.4s dynamic proxy api.
> 
> Is there another use I am missing?


ENFORCING CONTRACTS!  Good engineering ALWAYS *explicitly* enforces their contracts.


> 
> 



-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


Re: [VOTE][Patch] ComponentUtil

Posted by Peter Donald <pe...@apache.org>.
On Sat, 1 Dec 2001 11:04, Michael McKibben wrote:
> One way to accomplish what you are trying to do is to make the state java
> object, e.g. ComponentState, that has instance methods for validating the
> component's state.
>
> Usage pattern would then be something like:
>
> // Checks what lifecycle interfaces are implemented and returns the
> // initial state
> private ComponentState state = new ComponentState(this);
>
> Thenthe  user would call the check methods for component state validation
>
> state.configure();
> state.initialize();
> state.start();
> state.stop();
> state.dispose();
>
> // invalid state, throws some type of IllegalStateException
> state.initialize();
>
> Anyway, just a thought. Another idea would be to make the state object
> opaque and passed into the static check methods of ComponentUtil. What do
> you think?

I like that better than inheritance ! ;)

-- 
Cheers,

Pete

----------------------------------------------------
"The only way to discover the limits of the possible 
is to go beyond them into the impossible." 
                             -Arthur C. Clarke
----------------------------------------------------

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


Re: [VOTE][Patch] ComponentUtil

Posted by Berin Loritsch <bl...@apache.org>.
Leo Sutic wrote:

> Michael,
> 
> true. That would be even better and provide something similar to the
> impossible multiple inheritance that I would see as the optimal solution.
> 
> Could you implement & submit a patch - maybe we can get it into framework
> 4.2 or 4.1.1. Berin?


We can get it into FRAMEWORK 4.1.



-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


Re: [PATCH/SUMBISSION] ComponentStateValidator (was RE: [VOTE][Patch] ComponentUtil)

Posted by Berin Loritsch <bl...@apache.org>.
Peter Donald wrote:

> Hi,
> 
> On Sun, 2 Dec 2001 08:11, Michael McKibben wrote:
> 
>>Okay, I've attached an implementation called ComponentStateValidator.java
>>that basically does what ComponentUtil and AbstractComponent does. I didn't
>>patch ComponentUtil because I noticed that it has been removed from the cvs
>>tree. Feel free to move/rename it to whatever makes sense.
>>
> 
> kool - added it into Excalibur projects until it stabilizes.


Keep it in Framework.  When it is ready, we release.


>>I was also thinking that maybe in the future this could be enhanced to
>>switch off the validation, for example a static debug flag initialized via
>>a property like
>>
> 
> That could work. WHats everyone think ?


It could work, BUT just how much overhead is there with bit-tests?


-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


Re: [PATCH/SUMBISSION] ComponentStateValidator (was RE: [VOTE][Patch] ComponentUtil)

Posted by Peter Donald <pe...@apache.org>.
Hi,

On Sun, 2 Dec 2001 08:11, Michael McKibben wrote:
> Okay, I've attached an implementation called ComponentStateValidator.java
> that basically does what ComponentUtil and AbstractComponent does. I didn't
> patch ComponentUtil because I noticed that it has been removed from the cvs
> tree. Feel free to move/rename it to whatever makes sense.

kool - added it into Excalibur projects until it stabilizes.

> I was also thinking that maybe in the future this could be enhanced to
> switch off the validation, for example a static debug flag initialized via
> a property like

That could work. WHats everyone think ?

-- 
Cheers,

Pete

----------------------------------------------
Money is how people with no talent keep score.
----------------------------------------------

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


RE: [PATCH/SUMBISSION] ComponentStateValidator (was RE: [VOTE][Patch] ComponentUtil)

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> -----Original Message-----
> From: Peter Donald [mailto:peter@apache.org]
> 
> On Mon, 3 Dec 2001 02:56, Leo Sutic wrote:
> > Now if a COMMITTER could just APPLY THE PATCH... :-)
> 
> oops - I completely missed that there was a patch attached to mail. Will 
> apply it now ...

I was actually referring to Michael's patch - but that was far from obvious...

Could you please apply the http://nagoya.apache.org/bugzilla/showattachment.cgi?attach_id=849
patch to Excalibur as well?

/LS


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


Re: [PATCH/SUMBISSION] ComponentStateValidator (was RE: [VOTE][Patch] ComponentUtil)

Posted by Peter Donald <pe...@apache.org>.
On Mon, 3 Dec 2001 02:56, Leo Sutic wrote:
> > -----Original Message-----
> > From: Michael McKibben [mailto:mike@hihat.net]
> > Sent: den 1 december 2001 22:12
> > To: Avalon Developers List
> > Subject: [PATCH/SUMBISSION] ComponentStateValidator (was RE:
> > [VOTE][Patch] ComponentUtil)
> >
> >
> > Also, I noticed when I refreshed cvs that AbstractComponent.java has some
> > compilation problems.
>
> I noticed this - it is taken care of in my patch from 2001-12-01 00:19
> GMT+1.
>
> Now if a COMMITTER could just APPLY THE PATCH... :-)

oops - I completely missed that there was a patch attached to mail. Will 
apply it now ...

-- 
Cheers,

Pete

---------------------------------------------------
Murphy's law - "Anything that can go wrong, will." 
(Actually, this is Finagle's law, which in itself 
shows that Finagle was right.)
---------------------------------------------------

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


RE: [PATCH/SUMBISSION] ComponentStateValidator (was RE: [VOTE][Patch] ComponentUtil)

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> -----Original Message-----
> From: Michael McKibben [mailto:mike@hihat.net]
> Sent: den 1 december 2001 22:12
> To: Avalon Developers List
> Subject: [PATCH/SUMBISSION] ComponentStateValidator (was RE:
> [VOTE][Patch] ComponentUtil)
>
>
> Also, I noticed when I refreshed cvs that AbstractComponent.java has some
> compilation problems.

I noticed this - it is taken care of in my patch from 2001-12-01 00:19
GMT+1.

Now if a COMMITTER could just APPLY THE PATCH... :-)

/LS


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


[PATCH/SUMBISSION] ComponentStateValidator (was RE: [VOTE][Patch] ComponentUtil)

Posted by Michael McKibben <mi...@hihat.net>.
Okay, I've attached an implementation called ComponentStateValidator.java
that basically does what ComponentUtil and AbstractComponent does. I didn't
patch ComponentUtil because I noticed that it has been removed from the cvs
tree. Feel free to move/rename it to whatever makes sense.

Also, I noticed when I refreshed cvs that AbstractComponent.java has some
compilation problems. It still has two old references to
ComponentUtil.checkActive(...) instead of the protected member method. You
probably didn't notice it because you still had the old ComponentUtil class
in your local tree.

I was also thinking that maybe in the future this could be enhanced to
switch off the validation, for example a static debug flag initialized via a
property like

static {
	debug = Boolean.getBoolean("org.apache.avalon.framework.someproperty");
}

then the check*** methods would be wrapped with an if test

if (debug)
{
// validate component state ...
}

Another idea is to use JDK 1.4 assertions.

Regards,

--mike

-----Original Message-----
From: Leo Sutic [mailto:leo.sutic@inspireinfrastructure.com]
Sent: Saturday, December 01, 2001 7:16 AM
To: Avalon Developers List
Subject: RE: [VOTE][Patch] ComponentUtil


Michael,

true. That would be even better and provide something similar to the
impossible multiple inheritance that I would see as the optimal solution.

Could you implement & submit a patch - maybe we can get it into framework
4.2 or 4.1.1. Berin?

/LS

> -----Original Message-----
> From: Michael McKibben [mailto:mike@hihat.net]
> Sent: den 1 december 2001 01:05
> To: Avalon Developers List
> Subject: RE: [VOTE][Patch] ComponentUtil
>
>
> One way to accomplish what you are trying to do is to make the state java
> object, e.g. ComponentState, that has instance methods for validating the
> component's state.
>


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

RE: [VOTE][Patch] ComponentUtil

Posted by Leo Sutic <le...@inspireinfrastructure.com>.
Michael,

true. That would be even better and provide something similar to the
impossible multiple inheritance that I would see as the optimal solution.

Could you implement & submit a patch - maybe we can get it into framework
4.2 or 4.1.1. Berin?

/LS

> -----Original Message-----
> From: Michael McKibben [mailto:mike@hihat.net]
> Sent: den 1 december 2001 01:05
> To: Avalon Developers List
> Subject: RE: [VOTE][Patch] ComponentUtil
>
>
> One way to accomplish what you are trying to do is to make the state java
> object, e.g. ComponentState, that has instance methods for validating the
> component's state.
>


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


RE: [VOTE][Patch] ComponentUtil

Posted by Michael McKibben <mi...@hihat.net>.
One way to accomplish what you are trying to do is to make the state java
object, e.g. ComponentState, that has instance methods for validating the 
component's state.

Usage pattern would then be something like:

// Checks what lifecycle interfaces are implemented and returns the
// initial state
private ComponentState state = new ComponentState(this);

Thenthe  user would call the check methods for component state validation

state.configure();
state.initialize();
state.start();
state.stop();
state.dispose();

// invalid state, throws some type of IllegalStateException
state.initialize();

Anyway, just a thought. Another idea would be to make the state object
opaque and passed into the static check methods of ComponentUtil. What do
you think?

Regards,

--mike

On Sat, 1 Dec 2001, Leo Sutic wrote:

> 
> 
> > -----Original Message-----
> > From: Peter Donald [mailto:peter@apache.org]
> > 
> > a) a dodgy container
> > or
> > b) evil clients who can get direct reference to component
> > 
> > if (a) is true then it should be fixed not worked around.
> 
> True, it should be fixed in the container. There is no reasonable way to survive the handling of a container that calls the methods in the wrong order. And that is just the point: Fail early. Do not wait and fail later. If the container is dodgy, the component can help by failing fast, much like the Iterator classes.
> 
> Here's a patch for some refactoring of AbstractComponent.
> 
> /LS
> 


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


RE: [VOTE][Patch] ComponentUtil

Posted by Leo Sutic <le...@inspireinfrastructure.com>.

> -----Original Message-----
> From: Peter Donald [mailto:peter@apache.org]
> 
> a) a dodgy container
> or
> b) evil clients who can get direct reference to component
> 
> if (a) is true then it should be fixed not worked around.

True, it should be fixed in the container. There is no reasonable way to survive the handling of a container that calls the methods in the wrong order. And that is just the point: Fail early. Do not wait and fail later. If the container is dodgy, the component can help by failing fast, much like the Iterator classes.

Here's a patch for some refactoring of AbstractComponent.

/LS

Re: [VOTE] ComponentUtil

Posted by Peter Donald <pe...@apache.org>.
On Sat, 1 Dec 2001 05:31, Berin Loritsch wrote:
> The following snippet is supposed to describe how ComponentUtil was
> envisioned to perform.  Unfortunately, Java does not pass primitives by
> reference, but by value.
...
> If we do not like this usage pattern, then we should choose once and for
> all whether to provide it or not.
>
>
> Include ComponentUtil?
>
> Since it is broken and I really want to get Avalon Framework 4.1 out the
> door, I vote -1, remove it.

Well I think it is kinda nice but I can't see it being used widely enough to 
be included in framework. Maybe it would be best to include it in excalibur 
somewhere (maybe excalibur.util ?)

Put bluntly it is highly unlikely I would ever use it or recomend using it. 
The main reason it assumes that the environment in whihc you are working has 

a) a dodgy container
or
b) evil clients who can get direct reference to component

if (a) is true then it should be fixed not worked around. If (b) is true then 
these guards are going to be the least of your worries - you are going to 
have to code so many other protections about your code it is not funny. 

Even if you manage to shore up all the holes the component can still be 
fubared by another evil component going

synchronized( myComponent )
{
  while( 1 ) System.sleep(100000000);
}


If (b) is the case you are protecting against then your container should 
never hand out direct references but instead hand out references wrapped in 
proxies (maybe by 1.4s dynamic proxy api.

Is there another use I am missing?

-- 
Cheers,

Pete

----------------------------------------
Whatever you do will be insignificant, 
but it is very important that you do it. 
                              --Gandhi
----------------------------------------

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


RE: [VOTE] ComponentUtil

Posted by Leo Sutic <le...@inspireinfrastructure.com>.
+10^6 - Nice work!

Haven't had time to test it yet, but:

Three points:

 1) The message parameter of the check* methods... I would like to add a
method that provides a default value (otherwise I just see myself writing
checkLogEnabled("eror"); - yes, the misspelling is there on purpose to
emphasize sloppiness):

  public final void checkLogEnabled()
  {
    checkLogEnabled ("Stages out of order for " + getClass ().getName () +
". (LogEnabled)");
  }

  public final void checkLogEnabled( final String message ) { ... }

 2) AbstractLogEnabled should extends AbstractComponent.
 OR
 2) AbstractValidatingLogEnabled extends AbstractComponent

 3)

    protected final void checkSuspended( final String message )
    {
>>>>>>> ComponentUtil.checkActive( m_state, m_mask, message );
<<<<<<<<<<<<<<<<<<<<<<<<<
        if ( ( (m_state & m_mask & SUSPENDED) > 0 ) || ( (m_mask &
SUSPENDED) == 0 ) )

I am working on a patch - should have it up in half an hour...

/LS

> -----Original Message-----
> From: Berin Loritsch [mailto:bloritsch@apache.org]
> Sent: den 30 november 2001 23:11
> To: Avalon Developers List
> Subject: Re: [VOTE] ComponentUtil
>
>
> Leo Sutic wrote:
>
> > I can not vote, but I say +1 for including it. Mark it up as
> broken, use a
> > @deprecated tag or move it to a scratchpad directory or *something*. It
> > provides functions for validating the lifecycle contracts and I think we
> > should not throw away the code.
> >
> > I wrote in bugzilla that it should be renamed
> AbstractComponent. I did not
> > mean that it should implement all lifecycle methods, but rather
> provide a
> > "checkInitialized" method. It is not cruft - remember, the code
> of a class
> > only has one instance in the system and it is the data that is unique to
> > each instance. If there are too many methods, have a
> >
> >   validateLifecycle (int stage) throws IllegalStateException
> >
> > with stage being INITIALIZE, COMPOSE, etc.:
>
>
> I have something that works!
>
> why don't you try it (the testcase is even included)?






> --
>
> "They that give up essential liberty to obtain a little temporary safety
>   deserve neither liberty nor safety."
>                  - Benjamin Franklin
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>



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


Re: [VOTE] ComponentUtil

Posted by Berin Loritsch <bl...@apache.org>.
Leo Sutic wrote:

> I can not vote, but I say +1 for including it. Mark it up as broken, use a
> @deprecated tag or move it to a scratchpad directory or *something*. It
> provides functions for validating the lifecycle contracts and I think we
> should not throw away the code.
> 
> I wrote in bugzilla that it should be renamed AbstractComponent. I did not
> mean that it should implement all lifecycle methods, but rather provide a
> "checkInitialized" method. It is not cruft - remember, the code of a class
> only has one instance in the system and it is the data that is unique to
> each instance. If there are too many methods, have a
> 
>   validateLifecycle (int stage) throws IllegalStateException
> 
> with stage being INITIALIZE, COMPOSE, etc.:


I have something that works!

why don't you try it (the testcase is even included)?




-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


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


RE: [VOTE] ComponentUtil

Posted by Leo Sutic <le...@inspireinfrastructure.com>.
I can not vote, but I say +1 for including it. Mark it up as broken, use a
@deprecated tag or move it to a scratchpad directory or *something*. It
provides functions for validating the lifecycle contracts and I think we
should not throw away the code.

I wrote in bugzilla that it should be renamed AbstractComponent. I did not
mean that it should implement all lifecycle methods, but rather provide a
"checkInitialized" method. It is not cruft - remember, the code of a class
only has one instance in the system and it is the data that is unique to
each instance. If there are too many methods, have a

  validateLifecycle (int stage) throws IllegalStateException

with stage being INITIALIZE, COMPOSE, etc.:

public class SimpleComponent extends AbstractComponent implements Component,
Initializable {

      public void initialize () throws Exception
      {
         validateLifecycle (INITIALIZE);

         //do stuff
      }
}

The setWriteOnceObject can be re-declared:

Object setWriteOnceObject (Object source, Object value, String message)

and used as

void compose (ComponentManager manager) {
    this.manager = (ComponentManager) setWriteOnceObject (this.manager,
value, "Already set CM");
}

I do not see two methods which perform some very practical tasks as "cruft".
(Now if only Java supported multiple inheritance...)

/LS

> -----Original Message-----
> From: Berin Loritsch [mailto:bloritsch@apache.org]
> Sent: den 30 november 2001 19:32
> To: avalon-dev@jakarta.apache.org
> Subject: [VOTE] ComponentUtil
>
>
> The following snippet is supposed to describe how ComponentUtil
> was envisioned
> to perform.  Unfortunately, Java does not pass primitives by
> reference, but
> by value.
>
> public class SimpleComponent implements Component, Initializable {
>      final int m_mask;
>      int m_state = 0;
>
>      public SimpleComponent()
>      {
>         m_mask = ComponentUtil.getMask(this);
>      }
>
>      public void initialize () throws Exception
>      {
>         ComponentUtil.checkInitialized(m_state);
>
>         //do stuff
>      }
> }
>
>
> If we do not like this usage pattern, then we should choose once
> and for all
> whether to provide it or not.
>
>
> Include ComponentUtil?
>
> Since it is broken and I really want to get Avalon Framework 4.1
> out the door,
> I vote -1, remove it.
>
> --
>
> "They that give up essential liberty to obtain a little temporary safety
>   deserve neither liberty nor safety."
>                  - Benjamin Franklin
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>



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