--- Laran Coates <[EMAIL PROTECTED]> wrote:
> This compiles runs but it doesn't do anything.  Am I
> missing something.
> 
> Please let me know if sending code like this is
> considered a faux pas.

It's fine.

The first thing I noticed was that you did not set
the Logger.  The ActiveMonitor extends
AbstractLoggable.

The DataSourceComponentTest shows how to obtain a
Logger instance for a Component.  I would have to
see my code up close again, but the Logger is used
in Configuration.

BTW, the javadocs describe how the configuration
should look--although I believe I have reasonable
defaults for a production system.  In order to
override
the frequency to be less than a minute, you will have
to do something like this:

Configuration frequency = new
DefaultConfiguration("frequency", "test");
frequency.setValue("1"); // every millisecond
Configuration root = new
DefaultConfiguration("monitor", "test");
root.addChild(frequency);

testMonitor.configure( root );

(At least until we have an abstract test that loads
a configuration)

Be sure to wait long enough for the Monitor to
actually
look at the resource.

Also, since the code is completely untested the
implementation is theoretical.  I may have screwed up
royally ;P

Anyway, if that doesn't work, I will have another look
at it tomorrow.

> ////////////////////////////////////////////// BEGIN
> CODE
> 
> package org.apache.avalon.excalibur.monitor.test;
> 
> /*
>  * FileResourceTest.java
>  * Created on August 15, 2001, 3:58 PM
>  * @author
>  * @version
>  * @description
>  *
>  */
> 
> import java.beans.PropertyChangeListener;
> import java.beans.PropertyChangeEvent;
> import java.io.File;
> import java.io.Reader;
> import org.apache.avalon.excalibur.monitor.*;
> import org.apache.avalon.framework.configuration.*;
> 
> public class FileResourceTest implements
> PropertyChangeListener {
> 
>     public FileResourceTest()
>     {
>     } // FileResourceTest()
> 
>     public static void main (String args[])
>     {
> 
>         ActiveMonitor testMonitor = new
> ActiveMonitor();
>         FileResource fileResource = null;
>         String file               = "D:/yahoo.txt";
> 
>         try
>         {
>             if(args.length > 0) file = args[0];
>             fileResource = new FileResource(file);
>         } // try
>         catch (Exception e)
>         {
>             e.printStackTrace();
>         } // catch
> 
>         if (null != fileResource)
>         {
>             Reader reader = null;
> 
>             try
>             {
>                 //testMonitor
>                 testMonitor.configure(new
> DefaultConfiguration(null, null));
>                 testMonitor.start();
>                
> testMonitor.addResource(fileResource);
>                 reader =
> fileResource.getResourceAsReader();
>             } // try
>             catch(Exception e)
>             {
>                 e.printStackTrace();
>             } // catch
> 
>             try
>             {
>                 // while(reader.read()!=-1)
> {System.out.print('.');}
> 
>                 File file_ = new File(file);
>                
> file_.setLastModified(System.currentTimeMillis());
>                 file_ = null;
>             } // try
>             catch(Exception e)
>             {
>                 e.printStackTrace();
>             } // catch
>             finally {
>                 try
>                 {
>                     FileResource res =
> (FileResource)testMonitor.getResource(file);
>                    
>
res.testModifiedAfter(System.currentTimeMillis()-100);
>                    
> testMonitor.removeResource(fileResource);
>                    
> //res.removeAllPropertyChangeListeners();
>                     testMonitor.stop();
>                 } // try
>                 catch(Exception ee)
>                 {
>                     ee.printStackTrace();
>                 } // catch
>             } // finally
>         } // if
>     } // main(String[])
> 
>     public void propertyChange(PropertyChangeEvent
> propertyChangeEvent)
>     {
>         System.out.println(propertyChangeEvent.
>             getPropertyName() + "\n  IS::" +
>            
> (String)propertyChangeEvent.getNewValue() +
>             "\n  WAS::" +
> (String)propertyChangeEvent.getOldValue());
>     } // propertyChange(PropertyChangeEvent)
> 
> } // FileResourceTest
> 
> ////////////////////////////////////////////// END
> CODE
> 
> -----Original Message-----
> From: Berin Loritsch [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 15, 2001 6:46 PM
> To: Avalon Development; [EMAIL PROTECTED]
> Subject: RE: New Monitor framework
> 
> 
> You have to instantiate the ActiveMonitor Component:
> 
> ActiveMonitor monitor = new ActiveMonitor();
> monitor.setLogger(logger);
> monitor.configure(new Configuration()); // the
> defaults
>                                         // are every
>                                         // minute
> monitor.start()
> 
> Resource resource = new FileResource( "test.file" );
> resource.addPropertyChangeListener( listener );
> 
> monitor.addResource( resource );
> 
> // add code to modify the file.
> // The PropertyChangeListener you added should
> // catch the "last-modified" property
> 
> monitor.removeResource( resource );
> resource.removeAllPropertyChangeListeners();
> monitor.stop();
> 
> 
> I'll leave the rest for you to work out.
> 
> --- Laran Coates <[EMAIL PROTECTED]> wrote:
> > OK, first time I've done this so one question.
> >
> > I wrote something to test the FileResource and
> > ActiveMonitor.  What's the
> > "proper" way to make it available?
> >
> > -----Original Message-----
> > From: Berin Loritsch [mailto:[EMAIL PROTECTED]]
> > Sent: Wednesday, August 15, 2001 3:26 PM
> > To: Avalon Development
> > Subject: Re: New Monitor framework
> >
> >
> > Berin Loritsch wrote:
> > >
> > > Laran Coates wrote:
> > > >
> > > > Well explained.  Sounds brilliant.  I'm all in
> > favor.  Let me know how
> > if I
> > > > can help.
> > >
> > > Sure thing.  I can use test cases, and the
> > FileResource and JarResource
> > implementations
> > > written.  I am rapidly running out of spare time
> > here.  The first (albeit
> > untested
> > > cut is in CVS now).
> >
> >
> > Ok, initial implementations are in CVS now.  We
> need
> > testing to make sure it
> > actually
> > works :), but I have a feeling it won't take much
> to
> > get it going.
> >
> > In order to be notified of a resource
> modification,
> > you must implement the
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to