de.unikassel.android.sdcframework.util
Class LogfileManager

Package class diagram package LogfileManager
java.lang.Object
  extended by java.lang.Thread
      extended by de.unikassel.android.sdcframework.util.AbstractWorkerThread
          extended by de.unikassel.android.sdcframework.util.LogfileManager
All Implemented Interfaces:
UpdatableTransmissionComponent<TransmissionProtocolConfiguration>, EventObserver<AlarmEvent>, WorkerThread, Runnable

public final class LogfileManager
extends AbstractWorkerThread
implements UpdatableTransmissionComponent<TransmissionProtocolConfiguration>, EventObserver<AlarmEvent>

A worker thread to realize a the global log file handling.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  ObservableAlarm alarm
          The observable wake up alarm
private  ConnectionStrategy connectionStrategy
          The connection strategy
private  Context context
          The context
private static String FILE_NAME
          The log file name
private static LogfileManager instance
          The singleton instance
private  ConcurrentLinkedQueue<LogEvent> logEvents
          The queue for log messages
protected  ProtocolStrategy protocolStrategy
          The strategy implementing the protocol
static String RELATIVE_PATH
          Relative file path on the external storage media
private static String STORAGE_DIR
          The environmental storage directory
private static long TERMINATION_DELAY
          The delay for the automatic instance release ( to allow final log information be still logged)
private  ConcurrentLinkedQueue<String> transferFiles
          The queue for files to transfer
private  UUID uuid
          The uuid of the device
private  WakeLockHolder wakeLockHolder
          The wake lock holder instance
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
private LogfileManager(Context context, UUID uuid)
          Constructor
 
Method Summary
 void addLogEvent(LogEvent event)
          Method to add a log event
static void clearAllLogs()
          Static method to clear any available log file on the external storage media
static void createInstance(Context context, UUID uuid)
          Method to create the global instance
protected  void doCleanUp()
          The clean up method executed on termination
protected  void doWork()
          The working method executed in the running loop if started
static LogfileManager getInstance()
          Getter for the instance
protected  File getLogFile(long ts)
          Getter for the actual log file
protected  boolean isConfigured()
          Method to test for a valid configuration
private  boolean isExternalStorageAvailable()
          Test method for availability of the external storage device
 void onEvent(ObservableEventSource<? extends AlarmEvent> eventSource, AlarmEvent observedEvent)
          This method is called whenever the observed object does create an observed event
static void prepareReleaseInstance()
          Method to prepare delayed instance release
private static void releaseInstance()
          Method to destroy the global instance
private  boolean saveLogEvent(LogEvent event)
          Me6thod to save a log event
 void updateConfiguration(Context context, TransmissionProtocolConfiguration config)
          Method to update the component by a configuration
private  boolean uploadFile(String fileName)
          Does upload a file to the configured remote server using the given authentication data
 
Methods inherited from class de.unikassel.android.sdcframework.util.AbstractWorkerThread
doTerminate, hasTerminated, isLogging, isWorking, logMessage, run, setLogging, start, startWork, stopWork
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TERMINATION_DELAY

private static final long TERMINATION_DELAY
The delay for the automatic instance release ( to allow final log information be still logged)

See Also:
Constant Field Values

FILE_NAME

private static final String FILE_NAME
The log file name


RELATIVE_PATH

public static final String RELATIVE_PATH
Relative file path on the external storage media


STORAGE_DIR

private static final String STORAGE_DIR
The environmental storage directory


logEvents

private final ConcurrentLinkedQueue<LogEvent> logEvents
The queue for log messages


transferFiles

private final ConcurrentLinkedQueue<String> transferFiles
The queue for files to transfer


protocolStrategy

protected ProtocolStrategy protocolStrategy
The strategy implementing the protocol


connectionStrategy

private ConnectionStrategy connectionStrategy
The connection strategy


wakeLockHolder

private final WakeLockHolder wakeLockHolder
The wake lock holder instance


uuid

private final UUID uuid
The uuid of the device


alarm

private final ObservableAlarm alarm
The observable wake up alarm


context

private final Context context
The context


instance

private static LogfileManager instance
The singleton instance

Constructor Detail

LogfileManager

private LogfileManager(Context context,
                       UUID uuid)
Constructor

Parameters:
context - the context
uuid - the unique SDC installation identifier for this device
Method Detail

getInstance

public static final LogfileManager getInstance()
Getter for the instance

Returns:
the log file transfer task instance

createInstance

public static final void createInstance(Context context,
                                        UUID uuid)
Method to create the global instance

Parameters:
context - the context
uuid - the unique SDC installation identifier for this device

releaseInstance

private static final void releaseInstance()
Method to destroy the global instance


prepareReleaseInstance

public static void prepareReleaseInstance()
Method to prepare delayed instance release


isConfigured

protected final boolean isConfigured()
Method to test for a valid configuration

Returns:
true if upload configuration is available

addLogEvent

public final void addLogEvent(LogEvent event)
Method to add a log event

Parameters:
event - the log event to add to the queue

doCleanUp

protected final void doCleanUp()
Description copied from class: AbstractWorkerThread
The clean up method executed on termination

Specified by:
doCleanUp in class AbstractWorkerThread

doWork

protected final void doWork()
Description copied from class: AbstractWorkerThread
The working method executed in the running loop if started

Specified by:
doWork in class AbstractWorkerThread

saveLogEvent

private boolean saveLogEvent(LogEvent event)
Me6thod to save a log event

Parameters:
event - the log event to save to file
Returns:
true if successful, false otherwise

getLogFile

protected final File getLogFile(long ts)
                         throws IOException
Getter for the actual log file

Parameters:
ts - the time stamp
Returns:
the current log file if accessible
Throws:
IOException

isExternalStorageAvailable

private boolean isExternalStorageAvailable()
Test method for availability of the external storage device

Returns:
true if available, false otherwise

uploadFile

private final boolean uploadFile(String fileName)
Does upload a file to the configured remote server using the given authentication data

Parameters:
fileName - the file to upload
Returns:
true if successful, false otherwise

updateConfiguration

public final void updateConfiguration(Context context,
                                      TransmissionProtocolConfiguration config)
Description copied from interface: UpdatableTransmissionComponent
Method to update the component by a configuration

Specified by:
updateConfiguration in interface UpdatableTransmissionComponent<TransmissionProtocolConfiguration>
Parameters:
context - the application context
config - the configuration to update from

clearAllLogs

public static final void clearAllLogs()
Static method to clear any available log file on the external storage media


onEvent

public void onEvent(ObservableEventSource<? extends AlarmEvent> eventSource,
                    AlarmEvent observedEvent)
Description copied from interface: EventObserver
This method is called whenever the observed object does create an observed event

Specified by:
onEvent in interface EventObserver<AlarmEvent>
Parameters:
eventSource - the event generator
observedEvent - the event created by the observed object