patterntesting.runtime.log
Class ObjectRecorder

Package class diagram package ObjectRecorder
java.lang.Object
  extended by java.lang.Thread
      extended by patterntesting.runtime.log.AbstractLogger
          extended by patterntesting.runtime.log.ObjectRecorder
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
LazyObjectRecorder

public class ObjectRecorder
extends AbstractLogger

This class allows you to record objects. Later you can replay the logged objects, e.g. to simulate external you can:

You must write your own aspect to realize it.

If you want a pure java solution you can try ThOR, the Java Test Object Recorder.

Since:
1.3.1 (31.08.2013)
Author:
oliver (boehm@javatux.de)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ObjectRecorder()
          Instantiates a new object recorder.
ObjectRecorder(File logFile)
          Instantiates a new object logger.
ObjectRecorder(OutputStream ostream)
          Instantiates a new object logger to the given stream.
 
Method Summary
 void close()
          Closes the stream with the logged objects.
 void log(JoinPoint joinPoint, Object returnValue)
          Both things are logged with this method: the call of a method (joinPoint) and the return value of this method.
 void run()
          This method is called at shutdown to close the open stream.
protected  void save(String joinPoint, Object returnValue)
          Saves the given joinPoint / returnValue pair to the log stream.
 
Methods inherited from class patterntesting.runtime.log.AbstractLogger
createTempLogFile, getLogStream, getStreamFor, toString
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, 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, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ObjectRecorder

public ObjectRecorder()
Instantiates a new object recorder. The logged objects are stored in a temporary file.


ObjectRecorder

public ObjectRecorder(File logFile)
Instantiates a new object logger. The logged objects will be stored in the given log file.

Parameters:
logFile - the log file

ObjectRecorder

public ObjectRecorder(OutputStream ostream)
Instantiates a new object logger to the given stream.

Parameters:
ostream - the ostream
Method Detail

run

public void run()
This method is called at shutdown to close the open stream. Otherwise the closing "" tag in the generated file would be missing (it is generated by the used XStream library).

Specified by:
run in interface Runnable
Overrides:
run in class AbstractLogger
See Also:
Thread.run()

close

public void close()
Closes the stream with the logged objects.

Overrides:
close in class AbstractLogger

log

@NullArgsAllowed
public void log(JoinPoint joinPoint,
                                Object returnValue)
Both things are logged with this method: the call of a method (joinPoint) and the return value of this method. Constructors or method of type 'void' are not recorded because the have no return value.

Because the given joinPoint cannot be used as key for a map in ObjectPlayer it is saved as string. As a side effect this will speedup the serialization stuff and shorten the generated record file.

Parameters:
joinPoint - the joinpoint
returnValue - the return value

save

protected void save(String joinPoint,
                    Object returnValue)
             throws IOException
Saves the given joinPoint / returnValue pair to the log stream.

Parameters:
joinPoint - the join point
returnValue - the return value
Throws:
IOException - Signals that an I/O exception has occurred.


Copyright © 2002–2014 PatternTesting Team. All rights reserved.