Package org.apache.commons.vfs2.util
Class WeakRefFileListener
- java.lang.Object
-
- org.apache.commons.vfs2.util.WeakRefFileListener
-
- All Implemented Interfaces:
FileListener
public class WeakRefFileListener extends java.lang.Object implements FileListener
Wraps a listener with a WeakReference.- Since:
- 2.0
-
-
Field Summary
Fields Modifier and Type Field Description private FileSystem
fs
private java.lang.ref.WeakReference<FileListener>
listener
private FileName
name
-
Constructor Summary
Constructors Modifier Constructor Description protected
WeakRefFileListener(FileObject file, FileListener listener)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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
getListener()
Gets the wrapped listener.static void
installListener(FileObject file, FileListener listener)
Installs thelistener
at the givenfile
.
-
-
-
Field Detail
-
fs
private final FileSystem fs
-
name
private final FileName name
-
listener
private final java.lang.ref.WeakReference<FileListener> listener
-
-
Constructor Detail
-
WeakRefFileListener
protected WeakRefFileListener(FileObject file, FileListener listener)
-
-
Method Detail
-
installListener
public static void installListener(FileObject file, FileListener listener)
Installs thelistener
at the givenfile
.- Parameters:
file
- The FileObject to listen on.listener
- The FileListener
-
getListener
protected FileListener getListener() throws java.lang.Exception
Gets the wrapped listener. If it is gone, the WeakRefFileListener wrapper will remove itself from the list of listeners.- Returns:
- The FileListener.
- Throws:
java.lang.Exception
- if an error occurs.
-
fileCreated
public void fileCreated(FileChangeEvent event) throws java.lang.Exception
Called when a file is created.- Specified by:
fileCreated
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
java.lang.Exception
- if an error occurs.
-
fileDeleted
public void fileDeleted(FileChangeEvent event) throws java.lang.Exception
Called when a file is deleted.- Specified by:
fileDeleted
in interfaceFileListener
- Parameters:
event
- The FileChangeEvent.- Throws:
java.lang.Exception
- if an error occurs.
-
fileChanged
public void fileChanged(FileChangeEvent event) throws java.lang.Exception
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:
java.lang.Exception
- if an error occurs.
-
-