Package org.deepsymmetry.beatlink
Class LifecycleParticipant
- java.lang.Object
-
- org.deepsymmetry.beatlink.LifecycleParticipant
-
- Direct Known Subclasses:
AnalysisTagFinder
,ArtFinder
,BeatFinder
,BeatGridFinder
,ConnectionManager
,DeviceFinder
,MetadataFinder
,SignatureFinder
,TimeFinder
,VirtualCdj
,WaveformFinder
public abstract class LifecycleParticipant extends Object
Provides the abstract skeleton for all the classes that can be started and stopped in Beat Link, and for which other classes may have a need to know when they start or stop.
-
-
Constructor Summary
Constructors Constructor Description LifecycleParticipant()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addLifecycleListener(LifecycleListener listener)
Adds the specified life cycle listener to receive announcements when the component starts and stops.protected void
deliverLifecycleAnnouncement(org.slf4j.Logger logger, boolean starting)
Send a lifecycle announcement to all registered listeners.protected void
ensureRunning()
Helper method to throw anIllegalStateException
if we are not currently running.Set<LifecycleListener>
getLifecycleListeners()
Get the set of lifecycle listeners that are currently registered.abstract boolean
isRunning()
Check whether this component has been started.void
removeLifecycleListener(LifecycleListener listener)
Removes the specified life cycle listener so that it no longer receives announcements when the component starts or stops.
-
-
-
Method Detail
-
addLifecycleListener
public void addLifecycleListener(LifecycleListener listener)
Adds the specified life cycle listener to receive announcements when the component starts and stops. If
listener
isnull
or already present in the list of registered listeners, no exception is thrown and no action is performed.Lifecycle announcements are delivered to listeners on a separate thread to avoid worries about deadlock in synchronized start and stop methods. The called function should still be fast, or delegate long operations to its own separate thread.
- Parameters:
listener
- the device announcement listener to add
-
removeLifecycleListener
public void removeLifecycleListener(LifecycleListener listener)
Removes the specified life cycle listener so that it no longer receives announcements when the component starts or stops. Iflistener
isnull
or not present in the list of registered listeners, no exception is thrown and no action is performed.- Parameters:
listener
- the life cycle listener to remove
-
getLifecycleListeners
public Set<LifecycleListener> getLifecycleListeners()
Get the set of lifecycle listeners that are currently registered.- Returns:
- the currently registered lifecycle listeners
-
deliverLifecycleAnnouncement
protected void deliverLifecycleAnnouncement(org.slf4j.Logger logger, boolean starting)
Send a lifecycle announcement to all registered listeners.- Parameters:
logger
- the logger to use, so the log entry shows as belonging to the proper subclass.starting
- will betrue
if the DeviceFinder is starting,false
if it is stopping.
-
isRunning
public abstract boolean isRunning()
Check whether this component has been started.- Returns:
- the component has started successfully and is ready to perform any service it offers.
-
ensureRunning
protected void ensureRunning()
Helper method to throw anIllegalStateException
if we are not currently running.- Throws:
IllegalStateException
- if the component is not running
-
-