FileWatcher
class in package klyn.io

    public class FileWatcher extends Thread implements AutoClosable:

Object
└ Thread
└ FileWatcher
All Implemented Interfaces: AutoClosable

Portable file watcher based on periodic filesystem metadata polling.

The watcher observes a single path and emits typed events when existence, modification timestamp or size changes. It is implemented in Klyn and uses the existing `Path` metadata API, so it works consistently across platforms.

    import klyn.io

    watcher = FileWatcher("app.log", 250)
    watcher.updated += lambda(e: FileWatcherEvent): print("changed: " + e.path)

Properties

Modifier and Type | Member | Description
--- | --- | ---
public readonly property | isWatching `isWatching as Boolean:` | Returns true while the background watcher loop is running.
public readonly property | path `path as Path:` | Watched path.
public property | pollIntervalMs `pollIntervalMs as Int:` | Polling interval in milliseconds.

Inherited Properties
property Inherited Properties from Thread: activeCount, currentThread, id, isAlive, isInterrupted, name, priority, state
property Inherited Properties from Object: type
Events

Modifier and Type | Member | Description
--- | --- | ---
public event | changed `changed as FileWatcherEvent` | Emitted for every detected file state change.
public event | created `created as FileWatcherEvent` | Emitted when the watched file appears.
public event | deleted `deleted as FileWatcherEvent` | Emitted when the watched file disappears.
public event | modified `modified as FileWatcherEvent` | Emitted when an existing watched file changes size or timestamp.
public event | updated `updated as FileWatcherEvent` | Emitted when an existing watched file changes size or timestamp.

Constructors

Modifier and Type | Member | Description
--- | --- | ---
public | FileWatcher `FileWatcher(path as Path, pollIntervalMs as Int = 50):` | Creates a watcher for a `Path` instance.
public | FileWatcher `FileWatcher(path as String, pollIntervalMs as Int = 50):` | Creates a watcher for a path string.

Methods

Modifier and Type | Member | Description
--- | --- | ---
public | close `close() as Void:` | AutoClosable support for try-with-resources.
public | poll `poll() as Boolean:` | Polls once and emits events if the file state changed.
public | resetBaseline `resetBaseline() as Void:` | Resets the baseline without emitting events.
public override | run `run() as Void:` | Background watcher loop.
public override | start `start() as Void:` | Starts background polling.
public override | stop `stop() as Void:` | Stops background polling.

Inherited Methods
method Inherited Methods from Thread: current, interrupt, join, join, resume, sleep, start, stop, suspend, toString, yield
method Inherited Methods from AutoClosable: close
method Inherited Methods from Object: deepCopy, fromJson, toDict, toJson, toString, toXml
method Inherited Methods from Runnable: run