Class TransformerDebug

  • Direct Known Subclasses:
    AdminUiTransformerDebug

    public class TransformerDebug
    extends java.lang.Object
    Debugs transformers selection and activity.

    As transformations are frequently composed of lower level transformations, log messages include a prefix to identify the transformation. A numeric dot notation is used (such as 123.1.2 indicating the second third level transformation of the 123rd top level transformation).

    Author:
    Alan Davis
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String FINISHED_IN  
      protected org.apache.commons.logging.Log logger  
      protected org.alfresco.service.cmr.repository.MimetypeService mimetypeService  
      protected static java.lang.String NO_TRANSFORMERS  
      protected org.alfresco.service.cmr.repository.NodeService nodeService  
      protected static java.lang.String TRANSFORM_SERVICE_NAME  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()  
      void debug​(java.lang.String message)
      Log a message prefixed with the current transformation reference.
      void debug​(java.lang.String sourceMimetype, java.lang.String targetMimetype, org.alfresco.service.cmr.repository.NodeRef sourceNodeRef, long sourceSize, java.util.Map<java.lang.String,​java.lang.String> options, java.lang.String renditionName, java.lang.String message)  
      void debug​(java.lang.String message, java.lang.Throwable t)
      Log a message prefixed with the current transformation reference and include a exception, suppressing the stack trace if repeated as we return up the stack of transformers.
      int debugTransformServiceRequest​(java.lang.String sourceMimetype, long sourceSize, org.alfresco.service.cmr.repository.NodeRef sourceNodeRef, int contentHashcode, java.lang.String fileName, java.lang.String targetMimetype, java.util.Map<java.lang.String,​java.lang.String> options, java.lang.String renditionName)
      Debugs a request to the Transform Service
      void debugTransformServiceResponse​(org.alfresco.service.cmr.repository.NodeRef sourceNodeRef, int contentHashcode, long requested, int id, java.lang.String sourceExt, java.lang.String targetExt, java.lang.String msg)
      Debugs a response to the Transform Service
      void debugUsingPreviousReference​(java.lang.String message)
      Log a message prefixed with the previous transformation reference, used by this Thread.
      java.lang.String fileSize​(long size)  
      java.lang.String getFileName​(org.alfresco.service.cmr.repository.NodeRef sourceNodeRef, boolean firstLevel, long sourceSize)  
      protected java.lang.String getMimetypeExt​(java.lang.String mimetype)  
      protected java.lang.String getSourceAndTargetExt​(java.lang.String sourceMimetype, java.lang.String targetMimetype)  
      java.lang.StringBuilder getStringBuilder()
      Returns the current StringBuilder (if any) being used to capture debug information for the current Thread.
      boolean isEnabled()
      Indicates if any logging is required.
      protected void log​(java.lang.String message)  
      protected void log​(java.lang.String message, boolean debug)  
      protected void logBasicDetails​(TransformerDebug.Frame frame, long sourceSize, java.util.Map<java.lang.String,​java.lang.String> options, java.lang.String renditionName, java.lang.String message, boolean firstLevel)  
      java.lang.String ms​(long time)  
      protected int pop​(TransformerDebug.Call callType, boolean suppressFinish, boolean suppressChecking)  
      void popMisc()
      Removes a frame from the stack.
      void popTransform()
      Called after performing a transform.
      void pushMisc()
      Adds a new level to the stack to get a new request number or nesting number.
      void pushTransform​(java.lang.String transformerName, java.lang.String fromUrl, java.lang.String sourceMimetype, java.lang.String targetMimetype, long sourceSize, java.util.Map<java.lang.String,​java.lang.String> options, java.lang.String renditionName, org.alfresco.service.cmr.repository.NodeRef sourceNodeRef)  
      <T extends java.lang.Throwable>
      T
      setCause​(T t)
      Sets the cause of a transformation failure, so that only the message of the Throwable is reported later rather than the full stack trace over and over.
      static boolean setDebugOutput​(boolean debugOutput)
      Enable or disable debug log output.
      void setMimetypeService​(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)  
      void setNodeService​(org.alfresco.service.cmr.repository.NodeService nodeService)  
      void setPreviousTransformId​(int id)  
      void setStringBuilder​(java.lang.StringBuilder sb)
      Sets the StringBuilder to be used to capture debug information for the current Thread.
      void setTransformerDebugLog​(org.apache.commons.logging.Log transformerDebugLog)  
      void setTransformerLog​(org.apache.commons.logging.Log transformerLog)  
      protected java.lang.String spaces​(int i)  
      static java.lang.String toString​(java.util.Map<java.lang.String,​java.lang.String> options)
      Obtains a String for log messages.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NO_TRANSFORMERS

        protected static final java.lang.String NO_TRANSFORMERS
        See Also:
        Constant Field Values
      • TRANSFORM_SERVICE_NAME

        protected static final java.lang.String TRANSFORM_SERVICE_NAME
        See Also:
        Constant Field Values
      • logger

        protected org.apache.commons.logging.Log logger
      • nodeService

        protected org.alfresco.service.cmr.repository.NodeService nodeService
      • mimetypeService

        protected org.alfresco.service.cmr.repository.MimetypeService mimetypeService
    • Constructor Detail

      • TransformerDebug

        public TransformerDebug()
    • Method Detail

      • setTransformerLog

        public void setTransformerLog​(org.apache.commons.logging.Log transformerLog)
      • setTransformerDebugLog

        public void setTransformerDebugLog​(org.apache.commons.logging.Log transformerDebugLog)
      • setNodeService

        public void setNodeService​(org.alfresco.service.cmr.repository.NodeService nodeService)
      • setMimetypeService

        public void setMimetypeService​(org.alfresco.service.cmr.repository.MimetypeService mimetypeService)
      • setPreviousTransformId

        public void setPreviousTransformId​(int id)
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • pushTransform

        public void pushTransform​(java.lang.String transformerName,
                                  java.lang.String fromUrl,
                                  java.lang.String sourceMimetype,
                                  java.lang.String targetMimetype,
                                  long sourceSize,
                                  java.util.Map<java.lang.String,​java.lang.String> options,
                                  java.lang.String renditionName,
                                  org.alfresco.service.cmr.repository.NodeRef sourceNodeRef)
      • pushMisc

        public void pushMisc()
        Adds a new level to the stack to get a new request number or nesting number. Called prior to working out what transformers are active and prior to listing the supported mimetypes for an active transformer.
      • logBasicDetails

        protected void logBasicDetails​(TransformerDebug.Frame frame,
                                       long sourceSize,
                                       java.util.Map<java.lang.String,​java.lang.String> options,
                                       java.lang.String renditionName,
                                       java.lang.String message,
                                       boolean firstLevel)
      • debug

        public void debug​(java.lang.String sourceMimetype,
                          java.lang.String targetMimetype,
                          org.alfresco.service.cmr.repository.NodeRef sourceNodeRef,
                          long sourceSize,
                          java.util.Map<java.lang.String,​java.lang.String> options,
                          java.lang.String renditionName,
                          java.lang.String message)
      • popTransform

        public void popTransform()
        Called after performing a transform.
      • popMisc

        public void popMisc()
        Removes a frame from the stack. Called prior to working out what transformers are active and prior to listing the supported mimetypes for an active transformer.
      • pop

        protected int pop​(TransformerDebug.Call callType,
                          boolean suppressFinish,
                          boolean suppressChecking)
      • isEnabled

        public boolean isEnabled()
        Indicates if any logging is required.
      • setDebugOutput

        public static boolean setDebugOutput​(boolean debugOutput)
        Enable or disable debug log output. Normally used to hide calls to getTransformer as trace rather than debug level log messages. There are lots of these and it makes it hard to see what is going on.
        Parameters:
        debugOutput - if true both debug and trace is generated. Otherwise all output is trace.
        Returns:
        the original value.
      • debug

        public void debug​(java.lang.String message)
        Log a message prefixed with the current transformation reference.
        Parameters:
        message -
      • debugUsingPreviousReference

        public void debugUsingPreviousReference​(java.lang.String message)
        Log a message prefixed with the previous transformation reference, used by this Thread.
        Parameters:
        message -
      • debug

        public void debug​(java.lang.String message,
                          java.lang.Throwable t)
        Log a message prefixed with the current transformation reference and include a exception, suppressing the stack trace if repeated as we return up the stack of transformers.
        Parameters:
        message -
      • log

        protected void log​(java.lang.String message)
      • log

        protected void log​(java.lang.String message,
                           boolean debug)
      • setCause

        public <T extends java.lang.Throwable> T setCause​(T t)
        Sets the cause of a transformation failure, so that only the message of the Throwable is reported later rather than the full stack trace over and over.
      • getStringBuilder

        public java.lang.StringBuilder getStringBuilder()
        Returns the current StringBuilder (if any) being used to capture debug information for the current Thread.
      • setStringBuilder

        public void setStringBuilder​(java.lang.StringBuilder sb)
        Sets the StringBuilder to be used to capture debug information for the current Thread.
      • getFileName

        public java.lang.String getFileName​(org.alfresco.service.cmr.repository.NodeRef sourceNodeRef,
                                            boolean firstLevel,
                                            long sourceSize)
      • getSourceAndTargetExt

        protected java.lang.String getSourceAndTargetExt​(java.lang.String sourceMimetype,
                                                         java.lang.String targetMimetype)
      • getMimetypeExt

        protected java.lang.String getMimetypeExt​(java.lang.String mimetype)
      • spaces

        protected java.lang.String spaces​(int i)
      • ms

        public java.lang.String ms​(long time)
      • fileSize

        public java.lang.String fileSize​(long size)
      • debugTransformServiceRequest

        public int debugTransformServiceRequest​(java.lang.String sourceMimetype,
                                                long sourceSize,
                                                org.alfresco.service.cmr.repository.NodeRef sourceNodeRef,
                                                int contentHashcode,
                                                java.lang.String fileName,
                                                java.lang.String targetMimetype,
                                                java.util.Map<java.lang.String,​java.lang.String> options,
                                                java.lang.String renditionName)
        Debugs a request to the Transform Service
      • debugTransformServiceResponse

        public void debugTransformServiceResponse​(org.alfresco.service.cmr.repository.NodeRef sourceNodeRef,
                                                  int contentHashcode,
                                                  long requested,
                                                  int id,
                                                  java.lang.String sourceExt,
                                                  java.lang.String targetExt,
                                                  java.lang.String msg)
        Debugs a response to the Transform Service
      • toString

        public static java.lang.String toString​(java.util.Map<java.lang.String,​java.lang.String> options)
        Obtains a String for log messages.
        Parameters:
        options - to be turned into a string.
        Returns:
        a string of options that may be included in debug messages.