ParkNPark.common
Class Logger

java.lang.Object
  extended by ParkNPark.common.Logger

public class Logger
extends Object

Logger class that, as quickly as possible, logs information into a pre-allocated buffer and has facilities for manual and automatic flushing.


Field Summary
protected  int allocationSize
          The number of array elements to allocate when creating new Lists
protected  List<LogEntry> log
          Our currently-active log
protected  Object logMutex
          Consistent mutex for the currently-active log (because log can get replaced by a new instance)
protected  BufferedWriter probeClientManagerIn
          Sink for the times that client manager access begins
protected  BufferedWriter probeClientManagerOut
          Sink for the times that client manager access ends
protected  BufferedWriter probeDbIn
          Sink for the times that database access begins
protected  BufferedWriter probeDbOut
          Sink for the times that database access ends
protected  BufferedWriter probeFaultDetection
          Fault detection sink
protected  BufferedWriter probeFaultRecovery
          Fault recovery sink
protected  BufferedWriter probeIn
          Sink for the times that method calls begin in
protected  BufferedWriter probeMethod
          Method name sink
protected  BufferedWriter probeNameServiceIn
          Sink for the times that naming service access begins
protected  BufferedWriter probeNameServiceOut
          Sink for the times that naming service access ends
protected  BufferedWriter probeOut
          Sink for the times that method calls complete in
protected  BufferedWriter probeSource
          Client name sink
protected  BufferedWriter probeWaitIn
          Sink for the times that the waiting begins
protected  BufferedWriter probeWaitOut
          Sink for the times that the waiting stops
protected static File tempFilePath
          Our temporary file path for logging
 
Constructor Summary
Logger(int numClients, int numServers, int requestsPerClient, int interRequestTime, int replySize, String tier, String hostname, boolean logServerInfo, boolean logClientInfo, boolean appendLogs)
          Creates a new Logger instance that can be used to log activities and, in the background, flush existing log entries to disk
 
Method Summary
 LogEntry beginLogEntry(String methodName)
          Creates a new LogEntry object instance, adds it to the log, and, just before returning it, sets its probeIn property to the current time in microseconds.
 LogEntry beginLogEntry(String methodName, String clientName)
          Creates a new LogEntry object instance, adds it to the log, and, just before returning it, sets its probeIn property to the current time in microseconds
 void close()
          Closes the log files.
 void endLogEntry(LogEntry logEntry)
          Ends a LogEntry after setting the probeOut property to the current time in microseconds
 void flush()
          Flush out all the log entries into the output files.
protected  File getLogFile(int numClients, int numServers, int interRequestTime, int replySize, String probeType, String machine, String hostname)
          Generate the full name of the log file name according to the given parameters
protected static File getTempFilePath()
          Returns the temporary file path to store logging files into
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected List<LogEntry> log
Our currently-active log


logMutex

protected Object logMutex
Consistent mutex for the currently-active log (because log can get replaced by a new instance)


allocationSize

protected int allocationSize
The number of array elements to allocate when creating new Lists


probeIn

protected BufferedWriter probeIn
Sink for the times that method calls begin in


probeOut

protected BufferedWriter probeOut
Sink for the times that method calls complete in


probeMethod

protected BufferedWriter probeMethod
Method name sink


probeSource

protected BufferedWriter probeSource
Client name sink


probeFaultDetection

protected BufferedWriter probeFaultDetection
Fault detection sink


probeFaultRecovery

protected BufferedWriter probeFaultRecovery
Fault recovery sink


probeDbIn

protected BufferedWriter probeDbIn
Sink for the times that database access begins


probeDbOut

protected BufferedWriter probeDbOut
Sink for the times that database access ends


probeNameServiceIn

protected BufferedWriter probeNameServiceIn
Sink for the times that naming service access begins


probeNameServiceOut

protected BufferedWriter probeNameServiceOut
Sink for the times that naming service access ends


probeClientManagerIn

protected BufferedWriter probeClientManagerIn
Sink for the times that client manager access begins


probeClientManagerOut

protected BufferedWriter probeClientManagerOut
Sink for the times that client manager access ends


probeWaitIn

protected BufferedWriter probeWaitIn
Sink for the times that the waiting begins


probeWaitOut

protected BufferedWriter probeWaitOut
Sink for the times that the waiting stops


tempFilePath

protected static File tempFilePath
Our temporary file path for logging

Constructor Detail

Logger

public Logger(int numClients,
              int numServers,
              int requestsPerClient,
              int interRequestTime,
              int replySize,
              String tier,
              String hostname,
              boolean logServerInfo,
              boolean logClientInfo,
              boolean appendLogs)
Creates a new Logger instance that can be used to log activities and, in the background, flush existing log entries to disk

Parameters:
numClients - The number of clients in the current test
numServers - The number of servers in the current test
requestsPerClient - The number of requests expected from each client
interRequestTime - The delay between each invocation, which is used when constructing the log file names
replySize - The size of the server's replies, which is used when constructing the log file names
tier - The tier being logged: srv or cli
hostname - The host name of the machine being logged
logServerInfo - Log information relating to the server
logFaults - Log the fault detection and fault recovery times, which primarily makes sense on a client
appendLogs - True when the log files should be appended or false if the log files should be overwritten
Method Detail

beginLogEntry

public LogEntry beginLogEntry(String methodName)
                       throws ServiceUnavailableException
Creates a new LogEntry object instance, adds it to the log, and, just before returning it, sets its probeIn property to the current time in microseconds. Use this method only if you constructed this Logger instance with logSource set to false

Parameters:
methodName - The name of the method that was called
Returns:
A new LogEntry with the current time in microseconds into the probeIn property
Throws:
ServiceUnavailableException - Thrown if a log entry is attempted when the log has already been closed

beginLogEntry

public LogEntry beginLogEntry(String methodName,
                              String clientName)
                       throws ServiceUnavailableException
Creates a new LogEntry object instance, adds it to the log, and, just before returning it, sets its probeIn property to the current time in microseconds

Parameters:
methodName - The name of the method that was called
clientName - The hostname of the client that called the method
Returns:
A new LogEntry with the current time in microseconds into the probeIn property
Throws:
ServiceUnavailableException - Thrown if a log entry is attempted when the log has already been closed

endLogEntry

public void endLogEntry(LogEntry logEntry)
                 throws ServiceUnavailableException
Ends a LogEntry after setting the probeOut property to the current time in microseconds

Parameters:
logEntry - The LogEntry instance to finish
Throws:
ServiceUnavailableException - Thrown when the logger has been shut down and thus this log entry cannot be persisted

flush

public void flush()
           throws IOException
Flush out all the log entries into the output files. Do not call this method if you have logMutex locked or else a deadlock might occur!

Throws:
IOException - Thrown if an IOException occurs during the flushing, such as out-of-disk-space exceptions

close

public void close()
           throws IOException
Closes the log files. Note that you must not call flush() nor log any more data after calling this method. Attempts to do so will throw NullPointerExceptions

Throws:
IOException

getLogFile

protected File getLogFile(int numClients,
                          int numServers,
                          int interRequestTime,
                          int replySize,
                          String probeType,
                          String machine,
                          String hostname)
Generate the full name of the log file name according to the given parameters

Parameters:
numClients - The number of clients in the current test
numServers - The number of servers in the current test
interRequestTime - The delay between each invocation
replySize - The size of the server's replies
probeType - The type of probe: in, out, msg, or source
machine - The machine being logged: srv or cli
hostname - The host name of the machine being logged
Returns:
A File object containing the full path to the log file

getTempFilePath

protected static File getTempFilePath()
Returns the temporary file path to store logging files into

Returns:
The temporary file path to store logging files into