Class ServiceRegistry

java.lang.Object
slash.navigation.converter.gui.helpers.ServiceRegistry

public class ServiceRegistry extends Object
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
  • Constructor Details

  • Method Details

    • getMapView

      public MapView getMapView()
    • setMapView

      public void setMapView(String className, ServiceRegistry.MapViewSwapped callback)
      Creates a new map view from className, disposes the previous one (if there was one) and installs the new one -- all while holding this registry's lock, with callback invoked in between so the caller can do its Swing wiring atomically with the field swap.
    • isMapViewAvailable

      public boolean isMapViewAvailable()
    • getPositionAugmenter

      public PositionAugmenter getPositionAugmenter()
    • getAudioPlayer

      public AudioPlayer 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.