Package com.tccc.kos.core.service.device
Class DeviceService
java.lang.Object
com.tccc.kos.commons.util.ready.ReadyBean
com.tccc.kos.commons.core.service.AbstractService
com.tccc.kos.core.service.device.DeviceService
- All Implemented Interfaces:
CtxEventListener
,ContextHandleAware
,HandleAware
,Ready
,ReadyListener
Track device changes and send notifications.
- Since:
- 1.0
- Version:
- 2023-11-13
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDevice<?>
Return the device serial number.Get the serial number provider.void
Called from the device when it changes.boolean
Override in subclasses to be notified when all dependencies are ready.void
Set the device.void
setSerialNumber
(String serialNum) Set the device serial number.void
setSerialNumberProvider
(SerialNumberProvider provider) Set the serial number provider.Methods inherited from class com.tccc.kos.commons.core.service.AbstractService
getHandle, getHandlePrefix
Methods inherited from class com.tccc.kos.commons.util.ready.ReadyBean
getReady, onDependenciesReady
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.tccc.kos.commons.core.context.CtxEventListener
onCtxAutowiringCompleted, onCtxDestroyed, onCtxPhaseCompleted
Methods inherited from interface com.tccc.kos.commons.core.service.handle.HandleAware
addHandleChild, getName, getPath
Methods inherited from interface com.tccc.kos.commons.util.ready.ReadyListener
onDependenciesGroupReady
-
Constructor Details
-
DeviceService
public DeviceService()
-
-
Method Details
-
onBeanReady
public boolean onBeanReady()Description copied from class:ReadyBean
Override in subclasses to be notified when all dependencies are ready. Return true to indicate that this bean is also ready. If the bean needs to callsetReady()
later due to some async processing, return false to preventsetReady()
from being called automatically.It is recommended to override this method rather than
onDependenciesReady()
as a majority of the time it requires callingsuper.onDependneciesReady()
or explicitly callingsetReady()
which defaults to a failure mode.- Overrides:
onBeanReady
in classReadyBean
- Returns:
-
setDevice
Set the device. This is called internally to set the device to an instance ofAssemblyDevice
, but can be called from the system app to use a differentDevice
implementation. -
getSerialNumberProvider
Get the serial number provider. The serial number should be set / fetched viaDeviceService
which verifies that the provider is installed and ready. However, in cases where a provider may take some time to be ready, such as when using critical data, it can be convenient to fetch the provider directly and usewhenReady()
. This allows application code to know when the provider is ready for use. This can be used to avoid callinggetSerialNumber()
when the provider isn't ready as it will simply throw an exception. -
setSerialNumberProvider
Set the serial number provider. This is how the device determines the serial number. The provider implementsReady
and the serial number will not be available until the provider becomes ready. Depending on the provider, this may take some time or may, under some conditions, never become ready. In this case the device effectively has no serial number.If this is called more than once, only the last provider will be used.
-
getSerialNumber
Return the device serial number.- Throws:
Exception
-
setSerialNumber
Set the device serial number. This will be stored using the associatedSerialNumberProvider
. It is up to the provider to persist the serial number in some way to survive reboots and board swaps.- Throws:
Exception
-
notifyListeners
public void notifyListeners()Called from the device when it changes. -
getDevice
-