Java Doc for DefaultFileMonitor.java in  » Library » Apache-commons-vfs-20070724-src » org » apache » commons » vfs » impl » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Library » Apache commons vfs 20070724 src » org.apache.commons.vfs.impl 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.commons.vfs.impl.DefaultFileMonitor

DefaultFileMonitor
public class DefaultFileMonitor implements Runnable,FileMonitor(Code)
A polling FileMonitor implementation.

The DefaultFileMonitor is a Thread based polling file system monitor with a 1 second delay.

Design:

There is a Map of monitors known as FileMonitorAgents. With the thread running, each FileMonitorAgent object is asked to "check" on the file it is responsible for. To do this check, the cache is cleared.

  • If the file existed before the refresh and it no longer exists, a delete event is fired.
  • If the file existed before the refresh and it still exists, check the last modified timestamp to see if that has changed.
  • If it has, fire a change event.

With each file delete, the FileMonitorAgent of the parent is asked to re-build its list of children, so that they can be accurately checked when there are new children.
New files are detected during each "check" as each file does a check for new children. If new children are found, create events are fired recursively if recursive descent is enabled.

For performance reasons, added a delay that increases as the number of files monitored increases. The default is a delay of 1 second for every 1000 files processed.


Example usage:

 FileSystemManager fsManager = VFS.getManager();
 FileObject listendir = fsManager.resolveFile("/home/username/monitored/");
 

DefaultFileMonitor fm = new DefaultFileMonitor(new CustomFileListener()); fm.setRecursive(true); fm.addFile(listendir); fm.start();

(where CustomFileListener is a class that implements the FileListener interface.)
author:
   Christopher Ottley
version:
   $Revision: 537938 $ $Date: 2007-05-14 11:26:40 -0700 (Mon, 14 May 2007) $



Constructor Summary
public  DefaultFileMonitor(FileListener listener)
    

Method Summary
public  voidaddFile(FileObject file)
     Adds a file to be monitored.
public  intgetChecksPerRun()
    
public  longgetDelay()
    
 FileListenergetFileListener()
     Access method to get the current FileListener object notified when there are changes with the files added.
public  booleanisRecursive()
     Access method to get the recursive setting when adding files for monitoring.
protected  voidqueueAddFile(FileObject file)
     Queues a file for addition to be monitored.
protected  voidqueueRemoveFile(FileObject file)
     Queues a file for removal from being monitored.
public  voidremoveFile(FileObject file)
     Removes a file from being monitored.
public  voidrun()
     Asks the agent for each file being monitored to check its file for changes.
public  voidsetChecksPerRun(int checksPerRun)
     set the number of files to check per run.
public  voidsetDelay(long delay)
    
public  voidsetRecursive(boolean newRecursive)
     Access method to set the recursive setting when adding files for monitoring.
public  voidstart()
     Starts monitoring the files that have been added.
public  voidstop()
     Stops monitoring the files that have been added.


Constructor Detail
DefaultFileMonitor
public DefaultFileMonitor(FileListener listener)(Code)




Method Detail
addFile
public void addFile(FileObject file)(Code)
Adds a file to be monitored.



getChecksPerRun
public int getChecksPerRun()(Code)
get the number of files to check per run



getDelay
public long getDelay()(Code)
Get the delay between runs



getFileListener
FileListener getFileListener()(Code)
Access method to get the current FileListener object notified when there are changes with the files added.



isRecursive
public boolean isRecursive()(Code)
Access method to get the recursive setting when adding files for monitoring.



queueAddFile
protected void queueAddFile(FileObject file)(Code)
Queues a file for addition to be monitored.



queueRemoveFile
protected void queueRemoveFile(FileObject file)(Code)
Queues a file for removal from being monitored.



removeFile
public void removeFile(FileObject file)(Code)
Removes a file from being monitored.



run
public void run()(Code)
Asks the agent for each file being monitored to check its file for changes.



setChecksPerRun
public void setChecksPerRun(int checksPerRun)(Code)
set the number of files to check per run. a additional delay will be added if there are more files to check
Parameters:
  checksPerRun - a value less than 1 will disable this feature



setDelay
public void setDelay(long delay)(Code)
Set the delay between runs



setRecursive
public void setRecursive(boolean newRecursive)(Code)
Access method to set the recursive setting when adding files for monitoring.



start
public void start()(Code)
Starts monitoring the files that have been added.



stop
public void stop()(Code)
Stops monitoring the files that have been added.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.