avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laran Coates" <laran_coa...@yahoo.com>
Subject RE: New Monitor framework
Date Wed, 15 Aug 2001 23:01:35 GMT
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.



////////////////////////////////////////////// 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:bloritsch@yahoo.com]
Sent: Wednesday, August 15, 2001 6:46 PM
To: Avalon Development; laran_coates@yahoo.com
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 <laran_coates@yahoo.com> 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:bloritsch@apache.org]
> 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
> java.beans.PropertyChangeListener interface, and
> register yourself with the
> Resource.
>
> If you use the FileResource to obtain a stream or
> writer for the resource,
> it will
> automatically perform the notifications when the
> stream is closed.
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> avalon-dev-help@jakarta.apache.org
>
>
>
_________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at
> http://mail.yahoo.com
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> avalon-dev-help@jakarta.apache.org
>


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

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org


Mime
View raw message