The JSMTrace interface allows the programmer who wrote the service class to write out trace information.

If the JSMTrace object is not null, you can write to a trace file because it exists.

String text is written to the trace file UTF-8 encoded.

The println method appends CRLF (0x0D0x0A) to the end of the UTF-8 encoded bytes.

It is recommended not to embed "\n" in the String text, but use the print and println methods.

public interface JSMTrace
{
public void flush () ;

public int getNumber () ;

public File createTraceFile ( String fileName ) ;

public void print ( String text ) ;
public void println ( String text ) ;

public void println ( Object object1, Object object2 ) ;
public void println ( Object object1, Object object2, Object object3 ) ;
public void println ( Object object1, Object object2, Object object3, Object object4 ) ;
public void println ( Object object1, Object object2, Object object3, Object object4, Object object5 ) ;
public void println ( Object object1, Object object2, Object object3, Object object4, Object object5, Object object6 ) ;
public void println ( Object object1, Object object2, Object object3, Object object4, Object object5, Object object6, Object object7 ) ;
public void println ( Object object1, Object object2, Object object3, Object object4, Object object5, Object object6, Object object7, Object object8 ) ;

public void print ( Throwable throwable ) ;
public void print ( JSMCommand command ) ;
public void print ( JSMCommand command, JSMResponse response ) ;
public void print ( JSMCommand command, Throwable throwable ) ;
}

Example

    public final void service ( JSMContainer container )
   {
       m_trace = container.getServiceTrace () ;
   }

   public final JSMResponse command ( JSMCommand command ) throws JSMException
   {
       try
       {
           if ( m_trace != null )
           {
               m_trace.print ( command ) ;
           }

           JSMResponse response = runCommand ( command ) ;

           if ( m_trace != null )
           {
               m_trace.print ( command, response ) ;
           }

           return response ;
       }
       catch ( Throwable t )
       {
           if ( m_trace != null )
           {
               m_trace.print ( command, t ) ;
           }

          return new JSMResponse ( t ) ;
       }
   }

   private final JSMResponse runCommand ( JSMCommand command ) throws Exception
   {
      if ( command.equals ( command.SERVICE_LOAD ) )
      {
          return new JSMResponse ( "Command has completed" ) ;
      }

      return new JSMResponse ( JSMResponse.ERROR, "Unknown command" ) ;
  }
  • No labels