HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Debugging and Optimization Techniques"
Volume: 5 Issue: 3, p.94

	

Listing 1: Modification of the Core Output Routine
    

static boolean bOn = true;
static boolean bSystemOut = true;
static SimpleDateFormat DateFormat = null;

public synchronized static void println( String Line ){
 if ( !bOn )
  return;
 
    if ( DateFormat == null )
    DateFormat = new SimpleDateFormat( "dd/MMM HH:mm.ss: ");

  String D = DateFormat.format(new java.util.Date()) + Line + "\r\n";

  if ( bSystemOut )
    System.out.println( D );
}


Listing 2: Controlling the Output


public static void On(){
  bOn=true;
}

public static void Off(){
  bOn=false;
}

public static void SystemOn(){
  bSystemOut=true;
}

public static void SystemOff(){
  bSystemOut=false;
}


Listing 3: Listening for client Connections

public final class Debug extends Thread {
  static Vector clients = null;
  static int SOCKET_PORT = 2000;

  public void run(){
    Socket sIN;
    ServerSocket sSERVER;

    try{
      sSERVER = new ServerSocket( SOCKET_PORT );
    }catch(Exception E){
      return;
    }

    for(;;){
      try{
        sIN = sSERVER.accept();
        clients.addElement( new clientDebug( sIN ) );

    }catch(Exception E){}
  }
}
}


Listing 4: Handling the Client Connection


class clientDebug {
  private Socket sIn;
  private DataOutputStream out;

  public clientDebug(Socket _sIn){
    sIn = _sIn;
    try{
      out = new DataOutputStream( sIn.getOutputStream() );
      out.writeBytes( "------Logging Restarted------- n-ary limited v1.3 ---------\r\n" );

      out.writeBytes( "[os.name]      = [" + System.getProperty("os.name") + "]\r\n" );
      out.writeBytes( "[os.arch]      = [" + System.getProperty("os.arch") + "]\r\n" );
      out.writeBytes( "[os.version]   = [" + System.getProperty("os.version") + "]\r\n" );


      out.writeBytes( "[java.version] = [" + System.getProperty("java.version") + "]\r\n" );
      out.writeBytes( "[java.vendor]  = [" + System.getProperty("java.vendor") + "]\r\n" );

      Runtime RT = Runtime.getRuntime();
      out.writeBytes( "[total memory] = [" + RT.totalMemory() + " bytes]\r\n" );
      out.writeBytes( "[free memory]  = [" + RT.freeMemory() + " bytes]\r\n" );
      out.writeBytes( "----------------\r\n" );

    }catch(Exception E){
      out = null;
    }
  }

  public boolean println( String _D ){

    try{
      out.writeBytes( _D );
      return true;
    }catch(Exception E){
      return false;
    }
  }
}





 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.