events
Generic event timelines and OBSERVER contracts
Generic OBSERVER contracts over immutable, naturally ordered timestamps, with no non-JDK runtime dependencies.
Rationale
Why. The JDK's java.util.Observer and java.util.Observable are deprecated since Java 9: Observable is a class to extend, and it delivers each notification as an untyped Object.
Problem. Modules that publish events and modules that react to them need a shared contract, and an event's time needs a type that orders the timeline without tying every module to one clock.
Solution. Four interfaces. Event is parameterized by its timestamp type, Observable and Observer by the event type, and MutableObservable adds registration. Storage, ordering and threading of registrations are left to the implementation, and a module that keeps one clock fixes the timestamp type in its own event.
Key Concepts
Event timelines
Role. Event<T extends Comparable<? super T>> reports when a fact occurred. Timestamp types must be immutable; comparability is enforced by Java and immutability is a documented contract.
Notification
Role. An Observable<E> is the SUBJECT and an Observer<E> receives events through update. MutableObservable<E> adds registration and removal.
Pattern. OBSERVER
Lane
Purpose. Typed OBSERVER contracts for publishing and receiving timestamped events within one process.
Alternative. java.util.concurrent.Flow when a subscriber must signal demand; java.beans.PropertyChangeSupport for a bean's property changes.
When to avoid. Asynchronous streams that need back-pressure, or events that cross a process boundary.
Usage
An event on the JDK timeline
record Recorded(java.time.Instant when) implements Event<java.time.Instant> {}Views
Drawn from the release. A link in a view opens its source at the release tag.