[p2p-hackers] keeping metadata synchronized
markus-kern at gmx.net
Wed Sep 15 16:34:01 UTC 2004
On Wednesday, September 15, 2004, 6:08:53 PM Eric Hanson <eric at aquameta.com> wrote:
> Markus Kern (markus-kern at gmx.net) wrote:
>> > That's kind of what I was thinking, but I don't even know where
>> > to start looking on how to do it. It's going to be a Java app,
>> > so I can write a listener to listen for moves, deletes and
>> > renames and sync on that. But, say on a OSX box, is there an
>> > event thrown that can be tapped into somehow? How about
>> > Windows? How about Linux?
>> On Windows there is ReadDirectoryChangesW  to monitor directory
>> trees for changes. How easy this would be to use in Java (especially
>> in asynchronous mode) I don't know.
> I'm thinking more of going the other way, writing something in C
> that calls the Java daemon upon the event of a move delete or
> So using ReadDirectoryChangesW would rely on a polling
> mechanism? This isn't going to work for my uses because... ok
> let me explain a bit.
> So if I understand correctly, ReadDirectoryChangesW uses the
> windows Last Accessed property, which is stored with the file.
> This doesn't quite cut it because it relies on a polling of the
> entire filesystem periodically checking last accessed stats.
The time of last access is not used to determine changes when using
ReadDirectoryChangesW. It can be one of the properties you monitor
however in which case the one hour resolution applies.
There are various ways to use ReadDirectoryChangesW.
You can use it synchronously in which case Windows simply buffers all
changes and gives them to you the next time you call the function.
This is probably the easiest way to do it. You can sleep a while,
check for new events and send them to your Java application, then
loop. The danger with this approach is that the buffer may overflow
while you are sleeping and additional events will simply be dropped.
Another way is to set up a callback which is called by Windows when
there are any changes. Since your application will not do anything
else and you thus don't need the main thread this solution is probably
not the most elegant either.
A third possibilty is to set up an event object, pass it to
ReadDirectoryChangesW and then wait on the object in a loop. There are
some comments in the MSDN which indicate this may not work on Windows
9x/ME though. Some experimentation will be needed here.
More information about the P2p-hackers