You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Torsten Curdt <tc...@dff.st> on 2002/04/17 21:04:07 UTC

active monitor

Can someone enlighten me... the ActiveMonitor does not report any file
changes hear as he is supposed to... I just don't get the events :(

  public class .... extends AbstractLoggable implements
        PropertyChangeListener {

        .....


        File f = new File("D:\\test.txt");

        resource = new FileResource(f);

        .....

        resource.addPropertyChangeListener(this);

        ComponentSelector selector = null;
        Monitor monitor = null;

        try {
          selector = (ComponentSelector) manager.lookup(Monitor.ROLE + "Selector");
          monitor = (Monitor) selector.select("active");


          monitor.addResource(resource);


          if (monitor.getResource(resource.getResourceKey()) != null) {
            getLogger().debug("successfully monitoring");
          }
          else {
            getLogger().debug("not monitoring");
          }
        }
        catch(ComponentException e) {
          getLogger().error("cannot monitor resource",e);
        }
        finally {
          manager.release(monitor);
          manager.release(selector);
        }

        .....

All messsage look fine... Unfortuntaly the Monitor does not log much (I
think he should - at least in debug) All I get on startup is:

  Active monitor will sample all resources every 1000 milliseconds with a
  thread priority of 5(Minimum = 1, Normal = 5, Maximum = 10).

Any idea what I have missed? I am using excalibur from 20020402
(that comes with cocoon HEAD)

Any comments appreciated...
--
Torsten


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


Re: active monitor

Posted by Berin Loritsch <bl...@apache.org>.
Torsten Curdt wrote:
>>Can someone enlighten me... the ActiveMonitor does not report any file
>>changes hear as he is supposed to... I just don't get the events :(
> 
> 
> Now what the active monitor does is to call the "testModifiedAfter" with
> the "System.currentTimeMillis()" as an argument. On a change the
> "testModifierAfter" is supposed to fire the "Resource.MODIFIED" event.
> 
> But AFAICS the current code does something else.... If you break it down
> you get:
> 
>    if ( file.lastModified() > System.currentTimeMillis() ) {
>       // fire event
>    }
> 
> Which is not much likely to happen... ;-)
> Shouldn't it be:
> 
>   if ( file.lastModified() > m_previousModified ) {
>     // fire event
>     m_previousModified = file.lastModified()
>   }
> 
> But then the "time" argument wouldn't make much sense...
> 
> Comments?


Sounds good to me...


-- 

"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] Re: active monitor

Posted by Torsten Curdt <tc...@dff.st>.
> > Looks like Berin applied them in his last update - thanks anyways!
> >
>
> I always thought people checked the commits--or at least their comments.
>
> Maybe I should say something after I do it...

Sorry, I must have missed that commit mail... :-/
--
Torsten


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


Re: [PATCH] Re: active monitor

Posted by Berin Loritsch <bl...@apache.org>.
Peter Donald wrote:
> On Tue, 23 Apr 2002 00:57, Torsten Curdt wrote:
> 
>>>>question is only if this is really desired...
>>>>
>>>>Berin, how did you wanted this to work?
>>>>Do you want me to provide a patch?
>>>
>>>Go for it.
>>
>>...so I assume this was desired :-/
>>Berin, are you really sure about this?
>>
>>I attached *both* patches. For the Resource as well as for ActiveMonitor.
>>But I am in favor for patching the Resource *only*...
>>
>>Would be great if someone could apply one of them...
> 
> 
> Looks like Berin applied them in his last update - thanks anyways!
> 

I always thought people checked the commits--or at least their comments.

Maybe I should say something after I do 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: [PATCH] Re: active monitor

Posted by Torsten Curdt <tc...@dff.st>.
On Tue, 23 Apr 2002, Peter Donald wrote:

> On Tue, 23 Apr 2002 00:57, Torsten Curdt wrote:
> > > > question is only if this is really desired...
> > > >
> > > > Berin, how did you wanted this to work?
> > > > Do you want me to provide a patch?
> > >
> > > Go for it.
> >
> > ...so I assume this was desired :-/
> > Berin, are you really sure about this?
> >
> > I attached *both* patches. For the Resource as well as for ActiveMonitor.
> > But I am in favor for patching the Resource *only*...
> >
> > Would be great if someone could apply one of them...
>
> Looks like Berin applied them in his last update - thanks anyways!

Cool, thanks for checking anyway :)
--
Torsten


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


Re: [PATCH] Re: active monitor

Posted by Peter Donald <pe...@apache.org>.
On Tue, 23 Apr 2002 00:57, Torsten Curdt wrote:
> > > question is only if this is really desired...
> > >
> > > Berin, how did you wanted this to work?
> > > Do you want me to provide a patch?
> >
> > Go for it.
>
> ...so I assume this was desired :-/
> Berin, are you really sure about this?
>
> I attached *both* patches. For the Resource as well as for ActiveMonitor.
> But I am in favor for patching the Resource *only*...
>
> Would be great if someone could apply one of them...

Looks like Berin applied them in his last update - thanks anyways!

-- 
Cheers,

Peter Donald


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


[PATCH] Re: active monitor

Posted by Torsten Curdt <tc...@dff.st>.
> > question is only if this is really desired...
> >
> > Berin, how did you wanted this to work?
> > Do you want me to provide a patch?
>
>
> Go for it.

...so I assume this was desired :-/
Berin, are you really sure about this?

I attached *both* patches. For the Resource as well as for ActiveMonitor.
But I am in favor for patching the Resource *only*...

Would be great if someone could apply one of them...

Thanks
--
Torsten

Re: active monitor

Posted by Berin Loritsch <bl...@apache.org>.
Torsten Curdt wrote:
> On Sun, 21 Apr 2002, Torsten Curdt wrote:
> 
> 
>>>Can someone enlighten me... the ActiveMonitor does not report any file
>>>changes hear as he is supposed to... I just don't get the events :(
>>
>>ok... I have been debugging the active monitor... and I run into this:
>>
>>
>>in FileResource.java:
>>
>>    public long lastModified()
>>    {
>>        return m_file.lastModified();
>>    }
>>
>>
>>in Resource.java:
>>
>>    public void testModifiedAfter( long time )
>>    {
>>        long lastModified = this.lastModified();
>>        if( lastModified > time )
>>        {
>>            m_eventSupport.firePropertyChange( Resource.MODIFIED,
>>                                               new Long( m_previousModified ),
>>                                               new Long( lastModified ) );
>>            m_previousModified = lastModified;
>>        }
>>    }
>>
>>Now what the active monitor does is to call the "testModifiedAfter" with
>>the "System.currentTimeMillis()" as an argument. On a change the
>>"testModifierAfter" is supposed to fire the "Resource.MODIFIED" event.
>>
>>But AFAICS the current code does something else.... If you break it down
>>you get:
>>
>>   if ( file.lastModified() > System.currentTimeMillis() ) {
>>      // fire event
>>   }
>>
>>Which is not much likely to happen... ;-)
>>Shouldn't it be:
>>
>>  if ( file.lastModified() > m_previousModified ) {
>>    // fire event
>>    m_previousModified = file.lastModified()
>>  }
>>
>>But then the "time" argument wouldn't make much sense...
> 
> 
> One way to solve this is to replace this:
> 
> in ActiveMonitor:
> 
>    for( int i = 0; i < resources.length; i++ )
>    {
>         resources[ i ].testModifiedAfter( currentTestTime );
>                                           ~~~~~~~~~~~~~~~
>    }
> 
> by this:
> 
>    for( int i = 0; i < resources.length; i++ )
>    {
>         resources[ i ].testModifiedAfter( resources[i].m_previousModified );
>                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    }
> 
> question is only if this is really desired...
> 
> Berin, how did you wanted this to work?
> Do you want me to provide a patch?
> --
> Torsten
> 


Go for 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: active monitor

Posted by Torsten Curdt <tc...@dff.st>.
On Mon, 22 Apr 2002, Peter Donald wrote:
> On Mon, 22 Apr 2002 00:32, Torsten Curdt wrote:
> > > Which is not much likely to happen... ;-)
> > > Shouldn't it be:
> > >
> > >   if ( file.lastModified() > m_previousModified ) {
> > >     // fire event
> > >     m_previousModified = file.lastModified()
> > >   }
> > >
> > > But then the "time" argument wouldn't make much sense...
>
> yep ;)
>
> > One way to solve this is to replace this:
> >
> > in ActiveMonitor:
> >
> >    for( int i = 0; i < resources.length; i++ )
> >    {
> >         resources[ i ].testModifiedAfter( currentTestTime );
> >                                           ~~~~~~~~~~~~~~~
> >    }
> >
> > by this:
> >
> >    for( int i = 0; i < resources.length; i++ )
> >    {
> >         resources[ i ].testModifiedAfter( resources[i].m_previousModified
> > ); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ }
> >
> > question is only if this is really desired...
>
> I am not sure thats the way to do it. Personally I would still pass
> currentTestTime in through method but test a m_previosModified inside method
> (ie ignore the input parameter). As I imagine some resources using the
> current time as parameter - just not this one ;)

Same here ;) ...but I guess as the author Berin should give a comment
before I send a patch.
--
Torsten


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


Re: active monitor

Posted by Peter Donald <pe...@apache.org>.
On Mon, 22 Apr 2002 00:32, Torsten Curdt wrote:
> > Which is not much likely to happen... ;-)
> > Shouldn't it be:
> >
> >   if ( file.lastModified() > m_previousModified ) {
> >     // fire event
> >     m_previousModified = file.lastModified()
> >   }
> >
> > But then the "time" argument wouldn't make much sense...

yep ;)

> One way to solve this is to replace this:
>
> in ActiveMonitor:
>
>    for( int i = 0; i < resources.length; i++ )
>    {
>         resources[ i ].testModifiedAfter( currentTestTime );
>                                           ~~~~~~~~~~~~~~~
>    }
>
> by this:
>
>    for( int i = 0; i < resources.length; i++ )
>    {
>         resources[ i ].testModifiedAfter( resources[i].m_previousModified
> ); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ }
>
> question is only if this is really desired...

I am not sure thats the way to do it. Personally I would still pass 
currentTestTime in through method but test a m_previosModified inside method 
(ie ignore the input parameter). As I imagine some resources using the 
current time as parameter - just not this one ;)

-- 
Cheers,

Peter Donald


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


Re: active monitor

Posted by Torsten Curdt <tc...@dff.st>.
On Sun, 21 Apr 2002, Torsten Curdt wrote:

> > Can someone enlighten me... the ActiveMonitor does not report any file
> > changes hear as he is supposed to... I just don't get the events :(
>
> ok... I have been debugging the active monitor... and I run into this:
>
>
> in FileResource.java:
>
>     public long lastModified()
>     {
>         return m_file.lastModified();
>     }
>
>
> in Resource.java:
>
>     public void testModifiedAfter( long time )
>     {
>         long lastModified = this.lastModified();
>         if( lastModified > time )
>         {
>             m_eventSupport.firePropertyChange( Resource.MODIFIED,
>                                                new Long( m_previousModified ),
>                                                new Long( lastModified ) );
>             m_previousModified = lastModified;
>         }
>     }
>
> Now what the active monitor does is to call the "testModifiedAfter" with
> the "System.currentTimeMillis()" as an argument. On a change the
> "testModifierAfter" is supposed to fire the "Resource.MODIFIED" event.
>
> But AFAICS the current code does something else.... If you break it down
> you get:
>
>    if ( file.lastModified() > System.currentTimeMillis() ) {
>       // fire event
>    }
>
> Which is not much likely to happen... ;-)
> Shouldn't it be:
>
>   if ( file.lastModified() > m_previousModified ) {
>     // fire event
>     m_previousModified = file.lastModified()
>   }
>
> But then the "time" argument wouldn't make much sense...

One way to solve this is to replace this:

in ActiveMonitor:

   for( int i = 0; i < resources.length; i++ )
   {
        resources[ i ].testModifiedAfter( currentTestTime );
                                          ~~~~~~~~~~~~~~~
   }

by this:

   for( int i = 0; i < resources.length; i++ )
   {
        resources[ i ].testModifiedAfter( resources[i].m_previousModified );
                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   }

question is only if this is really desired...

Berin, how did you wanted this to work?
Do you want me to provide a patch?
--
Torsten


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


Re: active monitor

Posted by Torsten Curdt <tc...@dff.st>.
> Can someone enlighten me... the ActiveMonitor does not report any file
> changes hear as he is supposed to... I just don't get the events :(

ok... I have been debugging the active monitor... and I run into this:


in FileResource.java:

    public long lastModified()
    {
        return m_file.lastModified();
    }


in Resource.java:

    public void testModifiedAfter( long time )
    {
        long lastModified = this.lastModified();
        if( lastModified > time )
        {
            m_eventSupport.firePropertyChange( Resource.MODIFIED,
                                               new Long( m_previousModified ),
                                               new Long( lastModified ) );
            m_previousModified = lastModified;
        }
    }

Now what the active monitor does is to call the "testModifiedAfter" with
the "System.currentTimeMillis()" as an argument. On a change the
"testModifierAfter" is supposed to fire the "Resource.MODIFIED" event.

But AFAICS the current code does something else.... If you break it down
you get:

   if ( file.lastModified() > System.currentTimeMillis() ) {
      // fire event
   }

Which is not much likely to happen... ;-)
Shouldn't it be:

  if ( file.lastModified() > m_previousModified ) {
    // fire event
    m_previousModified = file.lastModified()
  }

But then the "time" argument wouldn't make much sense...

Comments?
--
Torsten


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