Package limn.backend.spi
Class Installed<T>
java.lang.Object
limn.backend.spi.Installed<T>
- Type Parameters:
T- the service
The one slot a backend fills for a service the toolkit offers statically: the image decoder,
the audio engine, the text ruler, the 3D provider, the crash handler, the UI runtime.
Nine classes kept this slot by hand and wrote the same four operations on it: install (never null), uninstall if it is still mine so that a late teardown cannot clear a newer one, is-installed, and require with a message saying which backend was not started. This is the slot once. What differs per service is what "nothing installed" is — null for most, a no-op ruler or a default crash handler for two — and what the message says.
Reads are volatile: a service is installed by the backend's thread and asked for from workers, and the slot is the one thing both touch.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Installed
A slot whose empty state isnull.- Parameters:
missing- whatrequire()says when nothing is installed
-
Installed
A slot whose empty state is a value of its own: a no-op ruler, a default handler.- Parameters:
absent- what the slot holds when nothing is installed; may be nullmissing- whatrequire()says when nothing is installed
-
-
Method Details
-
install
Fills the slot, replacing whatever was there.- Parameters:
value- the service; never null
-
uninstall
Empties the slot if it still holdsexpected, so that a late teardown cannot clear a newer install.- Parameters:
expected- what the caller installed
-
isInstalled
public boolean isInstalled()- Returns:
- whether something other than the empty state is installed
-
current
- Returns:
- what is installed, or the empty state
-
require
- Returns:
- what is installed
- Throws:
IllegalStateException- with the message this slot was given, when nothing is
-