Class ServiceRegistry
java.lang.Object
slash.navigation.converter.gui.helpers.ServiceRegistry
Owns the lazily-initialised, shared services that used to live directly on
BaseRouteConverter: the map view, the audio player (TimeAlbum) and
the position augmenter. Each accessor is guarded by a single private lock
so a service is created at most once, even under concurrent first access
(issue #214) -- the class does not change what is created or when, only
where the field and its lock live.
positionAugmenter and audioPlayer follow the classic
double-checked-locking-over-a-volatile-field pattern: created on first
access. mapView is a holder instead -- it is not created on demand
but explicitly replaced by setMapView(String, MapViewSwapped),
whose callback runs while this class's lock is held, so the field swap and
the caller's Swing wiring (adding the new view's component to a panel) are
one atomic step from the outside; the lock itself is never handed out (a
getLock() accessor trips SpotBugs' USO_UNSAFE_ACCESSIBLE_OBJECT_SYNCHRONIZATION).
- Author:
- Christian Pesch
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceRuns whilesetMapView(String, MapViewSwapped)holds this registry's lock, so the field swap and whatever Swing wiring the caller does for the new view are one atomic step to outside readers ofgetMapView()/isMapViewAvailable(). -
Constructor Summary
ConstructorsConstructorDescriptionServiceRegistry(Supplier<JTable> positionsViewSupplier, Supplier<PositionsModel> positionsModelSupplier, Supplier<JFrame> frameSupplier, ElevationServiceFacade elevationServiceFacade, GeocodingServiceFacade geocodingServiceFacade) -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Disposes whichever services have been created so far.booleanvoidsetMapView(String className, ServiceRegistry.MapViewSwapped callback) Creates a new map view fromclassName, disposes the previous one (if there was one) and installs the new one -- all while holding this registry's lock, withcallbackinvoked in between so the caller can do its Swing wiring atomically with the field swap.
-
Constructor Details
-
Method Details
-
getMapView
-
isMapViewAvailable
public boolean isMapViewAvailable() -
getPositionAugmenter
-
getAudioPlayer
-
dispose
public void dispose()Disposes whichever services have been created so far. Idempotent: a second call is a no-op. A service accessed again after dispose() is not recreated -- the accessor keeps returning the same, now disposed, instance, matching the behaviour before this extraction.
-