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 probeIn
          Sink for the times that method calls begin in
protected  BufferedWriter probeMethod
          Method name sink
protected  BufferedWriter probeOut
          Sink for the times that method calls complete in
protected  BufferedWriter probeSource
          Client name sink
 
Constructor Summary
Logger(int numClients, int requestsPerClient, int interRequestTime, int replySize, String tier, String hostname, boolean logSource)
          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  String generateLogFileName(int numClients, int interRequestTime, int replySize, String probeType, String machine, String hostname)
          Generate the name of the log file name according to the given parameters
 
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

Constructor Detail

Logger

public Logger(int numClients,
              int requestsPerClient,
              int interRequestTime,
              int replySize,
              String tier,
              String hostname,
              boolean logSource)
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
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
Method Detail

beginLogEntry

public 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. 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

beginLogEntry

public 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

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

endLogEntry

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

Parameters:
logEntry - The LogEntry instance to finish

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

generateLogFileName

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

Parameters:
numClients - The number of clients 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