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
ConstructorsModifierConstructorDescriptionprotected
WeakRefFileListener
(FileObject file, FileListener listener) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fileChanged
(FileChangeEvent event) Called when a file is changed.void
fileCreated
(FileChangeEvent event) Called when a file is created.void
fileDeleted
(FileChangeEvent event) Called when a file is deleted.protected FileListener
Gets the wrapped listener.static void
installListener
(FileObject file, FileListener listener) Install thelistener
at the givenfile
.
-
Constructor Details
-
WeakRefFileListener
Constructs a new instance.- Parameters:
file
- the file object.listener
- the file listener.
-
-
Method Details
-
installListener
Install thelistener
at 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:
fileChanged
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
Exception
- if an error occurs.
-
fileCreated
Called when a file is created.- Specified by:
fileCreated
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
Exception
- if an error occurs.
-
fileDeleted
Called when a file is deleted.- Specified by:
fileDeleted
in 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.
-