public class FileEvent extends EventObject
By calling FileEvent.getFile()
the original file where the action occurred
can be obtained.
source
Constructor and Description |
---|
FileEvent(FileObject src)
Creates new
FileEvent . |
FileEvent(FileObject src,
FileObject file)
Creates new
FileEvent , specifying the action object. |
FileEvent(FileObject src,
FileObject file,
boolean expected)
Creates new
FileEvent , specifying the action object. |
FileEvent(FileObject src,
FileObject file,
boolean expected,
long time)
Creates new
FileEvent , specifying all its details. |
Modifier and Type | Method and Description |
---|---|
boolean |
firedFrom(FileSystem.AtomicAction run)
Tests if this event has been generated from given atomic action.
|
FileObject |
getFile() |
long |
getTime()
The time when this event has been created.
|
boolean |
isExpected()
Getter to test whether the change has been expected or not.
|
void |
runWhenDeliveryOver(Runnable r)
Support for batch processing of events.
|
String |
toString() |
getSource
public FileEvent(FileObject src)
FileEvent
. The FileObject
where the action occurred
is assumed to be the same as the source object.
Delegates to FileEvent(src, src, false, -1)
.src
- source file which sent this eventpublic FileEvent(FileObject src, FileObject file)
FileEvent
, specifying the action object.
Delegates to FileEvent(src, file, false, -1)
.src
- source file which sent this eventfile
- FileObject
where the action occurredpublic FileEvent(FileObject src, FileObject file, boolean expected)
FileEvent
, specifying the action object.
Delegates to FileEvent(src, file, expected, -1)
.src
- source file which sent this eventfile
- FileObject
where the action occurredexpected
- sets flag whether the value was expectedpublic FileEvent(FileObject src, FileObject file, boolean expected, long time)
FileEvent
, specifying all its details.
Note that the two arguments of this method need not be identical in cases where it is reasonable that a different file object from the one affected would be listened to by other components. E.g., in the case of a file creation event, the event source (which listeners are attached to) would be the containing folder, while the action object would be the newly created file object.
The time is usually System.currentTimeMillis()
(which is the one
used if the parameter value is lower or equal to zero), but it may
be any other suitable time. For example when a file was changed, it
may be reasonable to use the timestamp of the file after its stream
has been closed.
src
- source file which sends this eventfile
- FileObject
where the action occuredexpected
- whether the change has been expected or nottime
- the time when the change happenedpublic final FileObject getFile()
public final long getTime()
public final boolean isExpected()
public final void runWhenDeliveryOver(Runnable r)
FileUtil.runAtomicAction(java.lang.Runnable)
action, there can be valid reason to do the processing only after
all of them are delivered. In such situation attach your Runnable
to provided event. Such Runnable
is then guaranteed to be called once.
Either immediately (if there is no batch delivery in progress)
or some time later (if there is a batch delivery). You can attach
single runnable multiple times, even to different events in the
same batch section and its Runnable.run()
method will still be
called just once. Object.equals(java.lang.Object)
is used
to check equality of two Runnable
s.r
- the runnable to execute when batch event deliver is over
(can be even executed immediately)public String toString()
toString
in class EventObject
public boolean firedFrom(FileSystem.AtomicAction run)
class MyAction implementsFileSystem.AtomicAction
{ public void run() throwsIOException
{ // change a file } public boolean equals(Object obj) { return obj != null && obj.getClass() ==Object.getClass()
; } public int hashCode() { return getClass().Object.hashCode()
; } } // later when an event is delivered toyour listener
one can check: public void fileChangedEvent(FileEvent
ev) { if (!ev.firedFrom(new MyAction()) { // the event is not caused by my action, so react somehow } }
run
- is tested atomic action.