ecologylab.services.logging
Class Logging<T extends MixedInitiativeOp>

java.lang.Object
  extended by ecologylab.generic.Debug
      extended by ecologylab.xml.ElementState
          extended by ecologylab.services.logging.Logging<T>
All Implemented Interfaces:
ServicesHostsAndPorts, OptimizationTypes, XMLTranslationExceptionTypes, java.lang.Runnable

public class Logging<T extends MixedInitiativeOp>
extends ElementState
implements java.lang.Runnable, ServicesHostsAndPorts

Provides a framework for interaction logging. Uses ecologylab.xml to serialize user and agent actions, and write them either to a file on the user's local machine, or, across the network, to the LoggingServer.

Author:
andruid

Nested Class Summary
protected  class Logging.FileLogWriter
          LogWriter that uses a local file for logging.
protected  class Logging.LogWriter
          Objects that process queuedActions for writing, either to a local file, or, using the network, to the LoggingServer.
protected  class Logging.MemoryMappedFileLogWriter
          LogWriter that uses a memory-mapped local file for logging.
protected  class Logging.NetworkLogWriter
          LogWriter that connects to the ServicesServer over the network for logging.
 
Nested classes/interfaces inherited from class ecologylab.xml.ElementState
ElementState.ClassToCollectionMap, ElementState.DeclarationStyle, ElementState.xml_attribute, ElementState.xml_class, ElementState.xml_classes, ElementState.xml_collection, ElementState.xml_leaf, ElementState.xml_map, ElementState.xml_nested, ElementState.xml_tag
 
Field Summary
static java.lang.String LOG_CLOSING
          Logging closing message string written to the logging file at the end
static int LOG_TO_FILE
          Preference setting for logging to a file using normal IO.
static int LOG_TO_FILE_AND_SERVER_REDUNDANT
          Preference setting for logging both to a normal IO file and a server.
static int LOG_TO_MEMORY_MAPPED_FILE
          Preference setting for logging to a file using memory-mapped IO.
static int LOG_TO_MM_FILE_AND_SERVER_REDUNDANT
          Preference setting for logging both to a memory-mapped file and a server.
static int LOG_TO_SERVICES_SERVER
          Preference setting for logging to a remote server.
static java.lang.String LOGGING_HOST_PARAM
           
static java.lang.String LOGGING_MODE_PARAM
           
static java.lang.String LOGGING_PORT_PARAM
           
static int NO_LOGGING
          Preference setting for no logging.
protected  ArrayListState<T> opSequence
          This field is used for reading a log in from a file, but not for writing one, because we dont the write the log file all at once, and so can't automatically translate the start tag and end tag for this element.
 
Fields inherited from class ecologylab.xml.ElementState
CDATA, ESTIMATE_CHARS_PER_FIELD, FLOATING_PRECISION_OFF, MARSHALLING_PARAMS, NORMAL, UTF16, UTF16_LE, UTF8, XML_FILE_HEADER
 
Fields inherited from interface ecologylab.services.distributed.common.ServicesHostsAndPorts
BROWSER_SERVICES_PORT, CF_SERVICES_PORT, CSDLL_HOST, LOGGING_HOST, LOGGING_PORT, PHYSI_ROGUE_UDP_PORT, ROGUE_OSC_SOUND_PATCH_LISTENER_PORT, ROGUE_OSC_SOUND_RECORDER_ACKNOWLEDGE_PORT, ROGUE_PORT, WEB_START_APP_SERVICES_PORT
 
Fields inherited from interface ecologylab.xml.OptimizationTypes
BAD_FIELD, COLLECTION_ELEMENT, COLLECTION_SCALAR, IGNORED_ATTRIBUTE, IGNORED_ELEMENT, LEAF_NODE_VALUE, MAP_ELEMENT, MAP_SCALAR, NAME_SPACE_ATTRIBUTE, NAME_SPACE_LEAF_NODE, NAME_SPACE_MASK, NAME_SPACE_NESTED_ELEMENT, NAMESPACE_IGNORED_ELEMENT, NAMESPACE_TRIAL_ELEMENT, OTHER_NESTED_ELEMENT, REGULAR_ATTRIBUTE, REGULAR_NESTED_ELEMENT, ROOT, UNSET_TYPE, XMLNS_ATTRIBUTE, XMLNS_IGNORED
 
Fields inherited from interface ecologylab.xml.XMLTranslationExceptionTypes
FILE_NOT_FOUND, IO_EXCEPTION, NULL_PURL, UNKNOWN
 
Constructor Summary
  Logging()
          Constructor for automatic translation from XML
protected Logging(int maxOpsBeforeWrite)
           
  Logging(java.lang.String logFileName)
          Instantiates a Logging object based on the given log file name.
  Logging(java.lang.String logFileName, int maxOpsBeforeWrite)
          Instantiates a Logging object based on the given log file name and the maximum operations before write.
  Logging(java.lang.String logFileName, int maxOpsBeforeWrite, int logMode, java.lang.String loggingHost, int loggingPort)
          Instantiates a Logging object based on the supplied parameters.
 
Method Summary
protected  Epilogue getEpilogue()
          A message at the end of the log.
 ArrayListState<T> getOpSequence()
           
 Prologue getPrologue()
          A message at the beginnging of the log.
 void logAction(MixedInitiativeOp op)
          Translates op to XML then logs it.
 void run()
          Logging to a file is delayed to the actions of this thread, because otherwise, it can mess up priorities in the system, because events get logged in the highest priority thread.
static long sessionStartTime()
          Return our session start timestamp.
 int size()
          Returns the size of the list of log ops.
 void start()
          Write the start of the log header out to the log file OR, send the begining logging file message so that logging server write the start of the log header.
 void stop()
          Finishes writing any queued actions, then sends the epilogue; then shuts down.
protected  void writeBufferedOps()
          Use the LogWriter, if there is one, to output queued actions to the log.
 
Methods inherited from class ecologylab.xml.ElementState
addNestedElement, addNestedElement, appendTextNodeString, buildDOM, buildDOM, buildDOM, buildDOM, buildDOM, buildDOMFromXMLCharSequence, buildDOMFromXMLString, checkAnnotation, convertNameStyles, createChildHook, fieldToXMLOptimizations, floatingPrecision, getCollection, getElementStateById, getMap, getNestedNameSpace, getTextNodeString, leafElementFieldNames, lookupNestedNameSpace, optimizations, parent, postTranslationProcessingHook, preTranslationProcessingHook, recycle, setDeclarationStyle, setFieldUsingTypeRegistry, setFloatingPrecision, setParent, setUseDOMForTranslateTo, translateFromXML, translateFromXML, translateFromXML, translateFromXML, translateFromXML, translateFromXMLCharSequence, translateFromXMLDOM, translateFromXMLDOM, translateFromXMLDOM, translateFromXMLDOM, translateFromXMLDOM, translateFromXMLDOM, translateFromXMLDOMCharSequence, translateFromXMLDOMCharSequence, translateFromXMLRootNode, translateFromXMLSAX, translateFromXMLSAX, translateFromXMLSAX, translateFromXMLSAX, translateFromXMLSAX, translateToDOM, translateToXML, translateToXML, translateToXML, translateToXML, writePrettyXML, writePrettyXML, writePrettyXML
 
Methods inherited from class ecologylab.generic.Debug
classSimpleName, closeLoggingFile, debug, debug, debug, debug, debugA, debugA, debugA, debugI, debugI, debugI, error, error, getClassName, getClassName, getInteractive, getPackageName, getPackageName, getPackageName, initialize, level, level, level, logToFile, print, print, println, println, println, println, println, println, printlnA, printlnA, printlnA, printlnI, printlnI, printlnI, printlnI, setLoggingFile, show, show, superString, toggleInteractive, toString, toString, warning, warning, weird, weird
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

opSequence

protected ArrayListState<T extends MixedInitiativeOp> opSequence
This field is used for reading a log in from a file, but not for writing one, because we dont the write the log file all at once, and so can't automatically translate the start tag and end tag for this element.


LOG_CLOSING

public static final java.lang.String LOG_CLOSING
Logging closing message string written to the logging file at the end

See Also:
Constant Field Values

NO_LOGGING

public static final int NO_LOGGING
Preference setting for no logging.

See Also:
Constant Field Values

LOG_TO_FILE

public static final int LOG_TO_FILE
Preference setting for logging to a file using normal IO.

See Also:
Constant Field Values

LOG_TO_SERVICES_SERVER

public static final int LOG_TO_SERVICES_SERVER
Preference setting for logging to a remote server.

See Also:
Constant Field Values

LOG_TO_MEMORY_MAPPED_FILE

public static final int LOG_TO_MEMORY_MAPPED_FILE
Preference setting for logging to a file using memory-mapped IO.

See Also:
Constant Field Values

LOG_TO_MM_FILE_AND_SERVER_REDUNDANT

public static final int LOG_TO_MM_FILE_AND_SERVER_REDUNDANT
Preference setting for logging both to a memory-mapped file and a server.

See Also:
Constant Field Values

LOG_TO_FILE_AND_SERVER_REDUNDANT

public static final int LOG_TO_FILE_AND_SERVER_REDUNDANT
Preference setting for logging both to a normal IO file and a server.

See Also:
Constant Field Values

LOGGING_HOST_PARAM

public static final java.lang.String LOGGING_HOST_PARAM
See Also:
Constant Field Values

LOGGING_PORT_PARAM

public static final java.lang.String LOGGING_PORT_PARAM
See Also:
Constant Field Values

LOGGING_MODE_PARAM

public static final java.lang.String LOGGING_MODE_PARAM
See Also:
Constant Field Values
Constructor Detail

Logging

public Logging(java.lang.String logFileName)
Instantiates a Logging object based on the given log file name. This constructor assumes that a set of loaded Prefs will handle other settings, indicating how logging will be performed, and the server setup (if logging over a network).


Logging

public Logging(java.lang.String logFileName,
               int maxOpsBeforeWrite)
Instantiates a Logging object based on the given log file name and the maximum operations before write. This constructor assumes that a set of loaded Prefs will handle other settings, indicating how logging will be performed, and the server setup (if logging over a network).


Logging

public Logging(java.lang.String logFileName,
               int maxOpsBeforeWrite,
               int logMode,
               java.lang.String loggingHost,
               int loggingPort)
Instantiates a Logging object based on the supplied parameters. This constructor does not rely on Prefs.

Parameters:
logFileName - the name of the file to which the log will be written.
maxOpsBeforeWrite - the maximum number of ops to record in memory before writing them to the set media.
logMode - the media to which the logger will write, such as a memory-mapped file or a server.
loggingHost - the host to which to log if using networked logging (may be null if local logging is desired).
loggingPort - the port of the host to which to log if using networked logging (may be 0 if local logging is desired).

Logging

public Logging()
Constructor for automatic translation from XML


Logging

protected Logging(int maxOpsBeforeWrite)
Method Detail

logAction

public void logAction(MixedInitiativeOp op)
Translates op to XML then logs it.

Parameters:
op - - the operation to be logged.

size

public int size()
Returns the size of the list of log ops. May not be the correct value if called during logging. This method should only be used for playback purposes.

Returns:
the size of opSequence.

start

public void start()
Write the start of the log header out to the log file OR, send the begining logging file message so that logging server write the start of the log header.

Then start the looping thread that periodically wakes up and performs log i/o.


stop

public void stop()
Finishes writing any queued actions, then sends the epilogue; then shuts down.


run

public void run()
Logging to a file is delayed to the actions of this thread, because otherwise, it can mess up priorities in the system, because events get logged in the highest priority thread.

This MUST be the only thread that ever calls writeQueuedActions().

Specified by:
run in interface java.lang.Runnable

writeBufferedOps

protected void writeBufferedOps()
Use the LogWriter, if there is one, to output queued actions to the log.

NB: This method is SINGLE Threaded! It is not thread safe. It must only be called from the run() method.


getPrologue

public Prologue getPrologue()
A message at the beginnging of the log. This method may be overridden to return a subclass of Prologue, by subclasses of this, that wish to emit application specific information at the start of a log.

Returns:

getEpilogue

protected Epilogue getEpilogue()
A message at the end of the log. This method may be overridden to return a subclass of Epilogue, by subclasses of this, that wish to emit application specific information at the end of a log.

Returns:

sessionStartTime

public static final long sessionStartTime()
Return our session start timestamp.

Returns:

getOpSequence

public ArrayListState<T> getOpSequence()
Returns:
the opSequence