Package org.apache.commons.vfs2.util
Class WeakRefFileListener
java.lang.Object
org.apache.commons.vfs2.util.WeakRefFileListener
- All Implemented Interfaces:
FileListener
Wraps a listener with a WeakReference.
- Since:
- 2.0
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWeakRefFileListener(FileObject file, FileListener listener) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidfileChanged(FileChangeEvent event) Called when a file is changed.voidfileCreated(FileChangeEvent event) Called when a file is created.voidfileDeleted(FileChangeEvent event) Called when a file is deleted.protected FileListenerGets the wrapped listener.static voidinstallListener(FileObject file, FileListener listener) Install thelistenerat the givenfile.
-
Constructor Details
-
WeakRefFileListener
Constructs a new instance.- Parameters:
file- the file object.listener- the file listener.
-
-
Method Details
-
installListener
Install thelistenerat the givenfile.This installs a wrapper with a weak reference, so the listener can be collected. The reference to the listener is removed when the first event can't be delivered.
Warning: you cannot remove the listener with
fs.removeListener(file, listener)as you do'nt have the wrapper instance at hand.Method is used by
DelegateFileObject, as used forVirtualFileSystem.- Parameters:
file- The FileObject to listen on.listener- The FileListener
-
fileChanged
Called when a file is changed.This will only happen if you monitor the file using
FileMonitor.- Specified by:
fileChangedin interfaceFileListener- Parameters:
event- The FileChangeEvent.- Throws:
Exception- if an error occurs.
-
fileCreated
Called when a file is created.- Specified by:
fileCreatedin interfaceFileListener- Parameters:
event- The FileChangeEvent.- Throws:
Exception- if an error occurs.
-
fileDeleted
Called when a file is deleted.- Specified by:
fileDeletedin interfaceFileListener- Parameters:
event- The FileChangeEvent.- Throws:
Exception- if an error occurs.
-
getListener
Gets the wrapped listener. If it is gone, the WeakRefFileListener wrapper will remove itself from the list of listeners.- Returns:
- The FileListener.
- Throws:
Exception- if an error occurs.
-