|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectde.unikassel.android.sdcframework.util.LifeCycleObjectImpl
de.unikassel.android.sdcframework.service.ServiceManagerImpl
public final class ServiceManagerImpl
The Implementation of the sensor data collection service manager.
The service manager does maintain the available framework components for the
service.
The main features are
| Field Summary | |
|---|---|
private BatteryLowStateObserver |
batteryLowObserver
The battery low state observer. |
private AtomicInteger |
broadcastsEnabledCounter
Counter for requests to enable sample broadcasts. |
private DatabaseManager |
dbManager
The database manager. |
private EventObserver<SensorDeviceConfigurationChangeEvent> |
deviceConfigEventObserver
The sensor device configuration change event observer. |
private SensorDeviceManager |
deviceManager
The sensor device manager. |
private EventObserver<TransferEvent> |
fileTransferObserver
The file transfer event observer. |
private boolean |
isCreated
Flag for creation state. |
private EventObserver<LogLevelConfigurationChangeEvent> |
logLevelConfigEventObserver
The log level change event observer. |
private static String |
LOW_BATTERY_MSG
The low on battery shutdown message. |
static int |
NOTIFICATION
The notification id. |
private ApplicationPreferenceManager |
preferenceManager
The preference manager. |
private SampleBroadcastService |
sampleBroadcastService
The sample broadcast service. |
private SDCService |
service
The SDC service. |
private ServiceConfiguration |
serviceConfig
The service configuration. |
private EventObserver<ServiceConfigurationChangeEvent> |
serviceConfigEventObserver
The service configuration change event observer. |
private PersistentStorageManager |
storageManager
The persistent storage manager. |
private TimeProviderErrorStrategy |
timeErrorStrategy
The time provider error strategy. |
private EventObserver<TimeProviderConfigurationChangeEvent> |
timeProviderConfigEventObserver
The time provider change event observer. |
private EventObserver<TimeProviderEvent> |
timeProviderEventObserver
The time provider event observer. |
private TransferManager |
transferManager
The sample transfer manager. |
private AtomicBoolean |
transferStateNeedsReset
Flag to mirror the expected transfer enabled state, for the duration of a manual triggered sample transfer. |
private PowerManager.WakeLock |
wakeLock
The wake lock to keep CPU running while service is active. |
| Constructor Summary | |
|---|---|
ServiceManagerImpl(Class<?> controlActivityClass)
Constructor |
|
| Method Summary | |
|---|---|
private void |
acquireWakeLock()
Does acquire the wake lock |
private void |
attachEventObserversForConfigurationChanges()
Does attach event observers for configuration changes |
private void |
attachTimeProviderEventObserver()
Does attach the event observer for time provider events |
void |
createDatabaseManager(Context applicationContext,
String dbName)
Method to create the database manager |
private void |
createStorageManager(Context applicationContext)
Method to create and configure the storage manager |
void |
createTransferManager(Context applicationContext)
Method to create and configure the transfer manager |
void |
doChangeBroadcastServiceState(boolean doEnable)
Method to change the broadcast state of the service |
void |
doEnableSampleBroadCasting(boolean doEnable)
Does enable or disable the sample broadcast feature |
void |
doEnableSampleStorage(boolean doEnable)
Does change the persistent storage enabled state. |
void |
doEnableSampleTransfer(boolean doEnable)
Does change the sample transfer activation state. |
void |
doEnableSampling(boolean doEnable)
Does activate or deactivate the sampling process for the running service. |
void |
doTriggerSampleTransfer()
Does manually trigger an instant sample transfer ( with a short delay ). |
private BatteryLowStateObserver |
getBatteryLowObserver()
|
Context |
getContext()
Getter for the service/application context |
private DatabaseManager |
getDbManager()
Getter for the dbManager |
private EventObserver<SensorDeviceConfigurationChangeEvent> |
getDeviceConfigurationEventObserver()
Getter for the sensor device configuration event observer |
private EventObserver<TransferEvent> |
getFileTransferObserver()
Getter for the fileTransferObserver |
private EventObserver<LogLevelConfigurationChangeEvent> |
getLogLevelConfigEventObserver()
Getter for the log level configuration event observer |
ApplicationPreferenceManager |
getPreferenceManager()
Getter for the application preference manager |
private SampleBroadcastService |
getSampleBroadcastService()
Getter for the sample broadcast service |
SDCService |
getSDCService()
Getter for the SDC service |
SensorDeviceManager |
getSensorDeviceManager()
Getter for the sensor device manager |
ServiceConfiguration |
getServiceConfig()
Getter for the serviceConfig |
EventObserver<ServiceConfigurationChangeEvent> |
getServiceConfigEventObserver()
Getter for the serviceConfigEventObserver |
private PersistentStorageManager |
getStorageManager()
Getter for the storageManager |
private EventObserver<TimeProviderConfigurationChangeEvent> |
getTimeProviderConfigEventObserver()
Getter for the time provider configuration event observer |
EventObserver<TimeProviderEvent> |
getTimeProviderEventObserver()
Getter for the timeProviderEventObserver |
TransferManager |
getTransferManager()
Getter for the transferManager |
private UUID |
getUUID(Context applicationContext)
Getter for the device identifier unique per service installation |
private PowerManager.WakeLock |
getWakeLock()
Getter for the wake lock |
private void |
handleDeviceConfigurationChange(SensorDeviceConfigurationChangeEvent deviceChangeEvent)
Handler for sensor device configuration changes |
private void |
handleLogLevelConfigurationChange(LogLevelConfigurationChangeEvent loglevelChangeEvent)
Handler for log level configuration changes |
protected void |
handleServiceConfigurationChange(ServiceConfigurationChangeEvent observedEvent)
Handler for service configuration changes |
protected void |
handleTimeProviderConfigurationChange(TimeProviderConfigurationChangeEvent observedEvent)
Handler for time provider configuration changes |
private void |
handleTimeProviderEvent(TimeProviderEvent event)
Handler for time provider events |
protected boolean |
isCreated()
Getter for the created flag |
void |
onCreate(Context applicationContext)
Creation method |
void |
onDestroy(Context applicationContext)
Destroy method |
void |
onEvent(ObservableEventSource<? extends BatteryLowEvent> eventSource,
BatteryLowEvent observedEvent)
This method is called whenever the observed object does create an observed event |
void |
onPause(Context applicationContext)
Pause method |
void |
onResume(Context applicationContext)
Resume method |
protected void |
onSuccessfuleFileTransfer(TransferEvent observedEvent)
Handler for observed file transfer events. |
private void |
releaseWakeLock()
Does release the wake lock |
private void |
setBatteryLowObserver(BatteryLowStateObserver batteryLowObserver)
|
protected void |
setCreated(boolean isCreated)
Setter for the created flag |
private void |
setDbManager(DatabaseManager dbManager)
Setter for the dbManager |
private void |
setDeviceConfigurationEventObserver(EventObserver<SensorDeviceConfigurationChangeEvent> deviceConfigEventObserver)
Setter for the sensor device configuration event observer |
private void |
setLogLevelConfigEventObserver(EventObserver<LogLevelConfigurationChangeEvent> logLevelConfigEventObserver)
Setter for the the log level configuration event observer |
void |
setSampleBroadcastService(SampleBroadcastService sampleBroadcastService)
Setter for the sample broadcast service |
void |
setSDCService(SDCService service)
Setter for the SDC service |
private void |
setSensorDeviceManager(SensorDeviceManager deviceManager)
Setter for the sensor device manager |
void |
setServiceConfigEventObserver(EventObserver<ServiceConfigurationChangeEvent> serviceConfigEventObserver)
Setter for the serviceConfigEventObserver |
private void |
setStorageManager(PersistentStorageManager storageManager)
Setter for the storageManager |
private void |
setTimeProviderConfigEventObserver(EventObserver<TimeProviderConfigurationChangeEvent> timeProviderConfigEventObserver)
Setter for the the time provider configuration event observer |
void |
setTimeProviderEventObserver(EventObserver<TimeProviderEvent> timeProviderEventObserver)
Setter for the timeProviderEventObserver |
void |
setTransferManager(TransferManager transferManager)
Setter for the transferManager |
private void |
setWakeLock(PowerManager.WakeLock wakeLock)
Setter for the wake lock |
void |
stopServiceByReason(String msg)
Does stop the service, logs the message as warning and sends a notification. |
void |
updateBroadcastFrequency(SampleBroadcastService sampleBroadcastService,
long frequency)
Method to update the broadcast frequency |
private void |
updateDatabaseMaximumSize(ServiceConfiguration updateConfig)
Method to update database size by current service configuration |
private void |
updateLogTransferConfig(TransmissionProtocolConfiguration updateConfig)
Method to update the log transfer configuration |
private void |
updateSampleBroadcastService(ServiceConfiguration updateConfig,
boolean force)
Method to update sample broadcasting by current service configuration |
private void |
updateSamplingConfiguration(ServiceConfiguration updateConfig,
boolean force)
Method to update additional sampling settings |
private void |
updateStorageManager(ServiceConfiguration updateConfig,
boolean force)
Method to update persistent storage management by current service configuration |
private void |
updateStrategyConfiguration(ServiceConfiguration updateConfig)
Method to update the database full strategy configuration values |
private void |
updateTimeSyncErrorStrategy(TimeProviderConfiguration config)
Method to update the error strategy for time provider sync errors |
private void |
updateTransferManager(ServiceConfiguration updateConfig,
boolean force)
Method to update sample transfer management by current service configuration |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final String LOW_BATTERY_MSG
public static final int NOTIFICATION
private final AtomicInteger broadcastsEnabledCounter
private SDCService service
private final ServiceConfiguration serviceConfig
private SensorDeviceManager deviceManager
private final ApplicationPreferenceManager preferenceManager
private EventObserver<TimeProviderEvent> timeProviderEventObserver
private EventObserver<SensorDeviceConfigurationChangeEvent> deviceConfigEventObserver
private EventObserver<LogLevelConfigurationChangeEvent> logLevelConfigEventObserver
private EventObserver<TimeProviderConfigurationChangeEvent> timeProviderConfigEventObserver
private EventObserver<ServiceConfigurationChangeEvent> serviceConfigEventObserver
private final EventObserver<TransferEvent> fileTransferObserver
private PowerManager.WakeLock wakeLock
private SampleBroadcastService sampleBroadcastService
private DatabaseManager dbManager
private PersistentStorageManager storageManager
private TransferManager transferManager
private boolean isCreated
private final AtomicBoolean transferStateNeedsReset
private BatteryLowStateObserver batteryLowObserver
private TimeProviderErrorStrategy timeErrorStrategy
| Constructor Detail |
|---|
public ServiceManagerImpl(Class<?> controlActivityClass)
controlActivityClass - the control activity class or null| Method Detail |
|---|
public final void setSDCService(SDCService service)
ServiceManager
setSDCService in interface ServiceManagerservice - the SDC service to setpublic final SDCService getSDCService()
ServiceManager
getSDCService in interface ServiceManagerpublic final ServiceConfiguration getServiceConfig()
public final ApplicationPreferenceManager getPreferenceManager()
ServiceManager
getPreferenceManager in interface ServiceManagerprivate final void setSensorDeviceManager(SensorDeviceManager deviceManager)
deviceManager - the sensor device manager to setpublic final SensorDeviceManager getSensorDeviceManager()
ServiceManager
getSensorDeviceManager in interface ServiceManagerprivate final EventObserver<SensorDeviceConfigurationChangeEvent> getDeviceConfigurationEventObserver()
private final void setDeviceConfigurationEventObserver(EventObserver<SensorDeviceConfigurationChangeEvent> deviceConfigEventObserver)
deviceConfigEventObserver - the sensor device configuration event observer to setprivate final EventObserver<LogLevelConfigurationChangeEvent> getLogLevelConfigEventObserver()
private final void setLogLevelConfigEventObserver(EventObserver<LogLevelConfigurationChangeEvent> logLevelConfigEventObserver)
logLevelConfigEventObserver - the log level configuration event observer to setprivate final EventObserver<TimeProviderConfigurationChangeEvent> getTimeProviderConfigEventObserver()
private final void setTimeProviderConfigEventObserver(EventObserver<TimeProviderConfigurationChangeEvent> timeProviderConfigEventObserver)
timeProviderConfigEventObserver - the time provider configuration event observer to setpublic final EventObserver<ServiceConfigurationChangeEvent> getServiceConfigEventObserver()
public final void setServiceConfigEventObserver(EventObserver<ServiceConfigurationChangeEvent> serviceConfigEventObserver)
serviceConfigEventObserver - the serviceConfigEventObserver to setpublic final EventObserver<TimeProviderEvent> getTimeProviderEventObserver()
public final void setTimeProviderEventObserver(EventObserver<TimeProviderEvent> timeProviderEventObserver)
timeProviderEventObserver - the timeProviderEventObserver to setprivate EventObserver<TransferEvent> getFileTransferObserver()
private final void setWakeLock(PowerManager.WakeLock wakeLock)
wakeLock - the wake lock to setprivate final PowerManager.WakeLock getWakeLock()
private final SampleBroadcastService getSampleBroadcastService()
public final void setSampleBroadcastService(SampleBroadcastService sampleBroadcastService)
sampleBroadcastService - the sample broadcast service to setprivate final void setDbManager(DatabaseManager dbManager)
dbManager - the dbManager to setprivate final DatabaseManager getDbManager()
private final PersistentStorageManager getStorageManager()
private final void setStorageManager(PersistentStorageManager storageManager)
storageManager - the storageManager to setpublic final TransferManager getTransferManager()
public final void setTransferManager(TransferManager transferManager)
transferManager - the transferManager to setprivate void setBatteryLowObserver(BatteryLowStateObserver batteryLowObserver)
private BatteryLowStateObserver getBatteryLowObserver()
protected final void setCreated(boolean isCreated)
isCreated - the created flag to setprotected final boolean isCreated()
private final void releaseWakeLock()
private final void acquireWakeLock()
public final void onCreate(Context applicationContext)
LifeCycleObject
onCreate in interface LifeCycleObjectonCreate in class LifeCycleObjectImplapplicationContext - the application contextpublic final void createTransferManager(Context applicationContext)
applicationContext - the application contextprivate UUID getUUID(Context applicationContext)
applicationContext - the application context
public final void createDatabaseManager(Context applicationContext,
String dbName)
applicationContext - the application contextdbName - the data base nameprivate final void createStorageManager(Context applicationContext)
applicationContext - the application contextpublic final void onResume(Context applicationContext)
LifeCycleObject
onResume in interface LifeCycleObjectonResume in class LifeCycleObjectImplapplicationContext - the application contextpublic final void onPause(Context applicationContext)
LifeCycleObject
onPause in interface LifeCycleObjectonPause in class LifeCycleObjectImplapplicationContext - the application contextprivate final void attachTimeProviderEventObserver()
private final void attachEventObserversForConfigurationChanges()
public final void onDestroy(Context applicationContext)
LifeCycleObject
onDestroy in interface LifeCycleObjectonDestroy in class LifeCycleObjectImplapplicationContext - the application contextprivate final void handleTimeProviderEvent(TimeProviderEvent event)
event - the eventprivate final void handleDeviceConfigurationChange(SensorDeviceConfigurationChangeEvent deviceChangeEvent)
deviceChangeEvent - the change eventprivate final void handleLogLevelConfigurationChange(LogLevelConfigurationChangeEvent loglevelChangeEvent)
loglevelChangeEvent - the change eventprotected final void handleTimeProviderConfigurationChange(TimeProviderConfigurationChangeEvent observedEvent)
observedEvent - private void updateTimeSyncErrorStrategy(TimeProviderConfiguration config)
config - the update configurationprotected final void handleServiceConfigurationChange(ServiceConfigurationChangeEvent observedEvent)
observedEvent - private final void updateLogTransferConfig(TransmissionProtocolConfiguration updateConfig)
updateConfig - the configuration to update from
private final void updateSamplingConfiguration(ServiceConfiguration updateConfig,
boolean force)
updateConfig - the configuration to update fromforce - flag if a state update should be forced
private final void updateSampleBroadcastService(ServiceConfiguration updateConfig,
boolean force)
updateConfig - the configuration to update fromforce - flag if a state update should be forced
public void updateBroadcastFrequency(SampleBroadcastService sampleBroadcastService,
long frequency)
sampleBroadcastService - the broadcast servicefrequency - the new frequency
private final void updateStorageManager(ServiceConfiguration updateConfig,
boolean force)
updateConfig - the configuration to update fromforce - flag if a state update should be forcedprivate final void updateStrategyConfiguration(ServiceConfiguration updateConfig)
updateConfig - the configuration to update fromprivate final void updateDatabaseMaximumSize(ServiceConfiguration updateConfig)
updateConfig - the configuration to update from
private final void updateTransferManager(ServiceConfiguration updateConfig,
boolean force)
updateConfig - the configuration to update fromforce - flag if a state update should be forced
public final void onEvent(ObservableEventSource<? extends BatteryLowEvent> eventSource,
BatteryLowEvent observedEvent)
EventObserver
onEvent in interface EventObserver<BatteryLowEvent>eventSource - the event generatorobservedEvent - the event created by the observed objectpublic final void stopServiceByReason(String msg)
ServiceManager
stopServiceByReason in interface ServiceManagermsg - the message to log and for use in notificationpublic Context getContext()
ServiceManager
getContext in interface ServiceManagerpublic final void doEnableSampleBroadCasting(boolean doEnable)
ServiceManager
doEnableSampleBroadCasting in interface ServiceManagerdoEnable - flag if sample broadcasting shall be enabled or disabledpublic final void doChangeBroadcastServiceState(boolean doEnable)
doEnable - public final void doEnableSampling(boolean doEnable)
ServiceManager
doEnableSampling in interface ServiceManagerdoEnable - flag if sampling shall be active or notpublic void doEnableSampleStorage(boolean doEnable)
ServiceManager
doEnableSampleStorage in interface ServiceManagerdoEnable - flag if the transfer feature shall be enabled or disabledpublic final void doEnableSampleTransfer(boolean doEnable)
ServiceManager
doEnableSampleTransfer in interface ServiceManagerdoEnable - flag if the transfer feature shall be enabled or disabledpublic final void doTriggerSampleTransfer()
ServiceManager
doTriggerSampleTransfer in interface ServiceManagerprotected void onSuccessfuleFileTransfer(TransferEvent observedEvent)
observedEvent - the observed transfer event
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||