Class ObjectRecorder

  • All Implemented Interfaces:
    java.lang.AutoCloseable, java.lang.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:
    • record the call to the external system,
    • replay the recorded objects.
    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

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      ObjectRecorder()
      Instantiates a new object recorder.
      ObjectRecorder​(java.io.File logFile)
      Instantiates a new object logger.
      ObjectRecorder​(java.io.OutputStream ostream)
      Instantiates a new object logger to the given stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the stream with the logged objects.
      void log​(org.aspectj.lang.JoinPoint joinPoint, java.lang.Object returnValue)
      Both things are logged with this method: the call of a method (joinPoint) and the return value of this method.
      protected void save​(java.lang.String joinPoint, java.lang.Object returnValue)
      Saves the given joinPoint / returnValue pair to the log stream.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, 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​(java.io.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​(java.io.OutputStream ostream)
        Instantiates a new object logger to the given stream.
        Parameters:
        ostream - the ostream
    • Method Detail

      • close

        public void close()
        Closes the stream with the logged objects.
        Specified by:
        close in interface java.lang.AutoCloseable
        Overrides:
        close in class AbstractLogger
      • log

        @NullArgsAllowed
        public void log​(org.aspectj.lang.JoinPoint joinPoint,
                        java.lang.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​(java.lang.String joinPoint,
                            java.lang.Object returnValue)
                     throws java.io.IOException
        Saves the given joinPoint / returnValue pair to the log stream.
        Parameters:
        joinPoint - the join point
        returnValue - the return value
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.