• Post Reply Bookmark Topic Watch Topic
  • New Topic

I wrote my own FileMonitor. Check it out.  RSS feed

 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wanted to get some feedback from you people. Basically, this will notify your class whenever a file it's watching gets modified. Very easy to use.

OK, here's the interface that a listener class would implement:



Here's the file monitor itself (1 class):




And here's a class that tests it:



[EJFH: Edited for language. Please clean it up -- this isn't your first warning. ]
[ June 21, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since when is [expletive deleted] considered an offensive language? My friends 6 year old daughter uses it as a part of normal lexicon, what's wrong with u people?
[ June 21, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ivan Jouikov:
Since when is [expletive deleted] considered an offensive language? My friends 6 year old daughter uses it as a part of normal lexicon, what's wrong with u people?


I dearly hope that your friend's six-year-old daughter steers clear of mine. I'm sure that family dinners at their house are a delight.

In any case, the number one rule at the Ranch -- you agreed to follow it when you signed up -- is be nice. I don't think that's too much to ask. So far, your language and attitude often haven't displayed very much respect for our site or its rules. We'd love to have you stay and participate, but on our terms, please.
[ June 21, 2004: Message edited by: Ernest Friedman-Hill ]
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Living in the 60s?

[ Long tirade, reminiscent of Wiliam Safire on absinthe, about how South Park is the intellectual currency of the 21st century, including pithy quotations, deleted -- EJFH ]

I hope you get my point. If you don't, I'll try my best to stay away from words that kindergartens aren't allowed to use.
[ June 21, 2004: Message edited by: Ernest Friedman-Hill ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I guess thats how the standards of civilized discourse slowly drift to the gutter. You have apprently take the side that doesn't care - personally I think its important.
Bill
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know this is utterly OT, but some (generally fairly lefty) groups will encourage use of words that are seen to be derogatory in a normal sense, thus disempowering and "reclaiming" the words. Queer rights groups often do this, with words I'm sure you can guess but I won't mention.

Anyway, this is a way in which (in some people's POV..often I'm one of these people) some words with a bad reputation can be brought into normal usage without discourse "drifting to the gutter".

Still, I wouldn't say this was one of those situations


--Tim
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
back to the topic: what do you think of the file monitor? Works great for me.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ivan Jouikov:

I hope you get my point. If you don't, I'll try my best to stay away from words that kindergartens aren't allowed to use.


My point is that this community has specific standards which I've asked you to respect. That's the important point here.

Now, it sounds as though you're going to try to play along. We'd all appreciate the effort.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ivan Jouikov:
what do you think of the file monitor? Works great for me.


I generally like it. There are a few places where I'd push code around somewhat; for example I think FileListenerTask.run() has "feature envy" for the FileInfo class; I think I'd move the whole if/then block into a method in that class. I'd also replace the body of hasListener() with a single call to fileChangeListeners.contains(), unless there's some reason to expect listeners with sloppy equals() methods.
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a good point with a listener...

On one hand, reference comparison saves from bad equals()...

On the other hand, I am already having problems with tomcat adding exactly same listeners when I reload my app, because its reference only comparison...
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update (if anyone cares )

Here's something I couldn't find anywhere: a FileMonitor, which will automatically reload modified files (well, signal your class that they have been modified)...




... And here's DynamicProperties, which is just like Properties, only it's dynamic. Also, couldn't find this anywhere. The most messed up thing is that it took my like 3x as much time to write the dynamic properties (well not write, debug it), than it took my to write FileMonitor

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,

Before I could post my responses to your older code you posted new one while I was on the phone

But still I would give my input on older code (still probably applicabe to new code).

1. I agree with Ernest that if..else in run() method of TimerTask should be moved to FileInfo. The reason is- what we are doing there? Accessing members of FileInfo ONLY, right?

2. The fileChangeListeners member as List, I would put it as Set. Why we would want to allow multiple objects of the same listener to be added to the list?

I guess those are the only two things I had on mind.

Regards
Maulin
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh

1. I guess you're right. But it's pretty much all copy-paste, so you can go ahead and do whatever you want

2. List seems to work fine, because I DO check to make sure that there's not an equal() listener inside the list. How would set make it different? I used list mainly for iteration purposes.
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ivan,

I forgot to mention that I would prefer writing equals() myself in the Listener instead of reference comparison.

If we do reference comparison we would have problems as you mentioned with Tomcat restart and all you know. Also, if you ever end up having Serialization for Listeners, it would not work for you as when you deserialize the object reference would not match with the existing repository.

So now if you write equals() and hashCode() in the Listener then it would make more sense to use Set instead of List as Set would automatically go for equals() to see that no element is repeated.

Btw, this would be point of debate again but the FileMonitor is having all static methods so make sure that you would not want to extend it in future. If you would have to then you are stuck as static methods can't be overridden. In that case make it singleton.

I guess thats all I have to say. I tried your earlier code and it works fine for me.

Regards,
Maulin
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K I'll redesign that sucker and post a new one today
 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
K here's a new one. Uses singleton pattern. I don't think it gets any better than this

 
Ivan Jouikov
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread problem?

Plz help:

http://www.coderanch.com/forums/f-1/java
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!