com.wolfram.jlink
Class PacketPrinter

java.lang.Object
  extended by com.wolfram.jlink.PacketPrinter
All Implemented Interfaces:
PacketListener, java.util.EventListener

public class PacketPrinter
extends java.lang.Object
implements PacketListener

PacketPrinter is an implementation of the PacketListener interface that prints the contents of incoming packets to a stream that you specify.

PacketPrinter is useful for debugging, when you want to see exactly what Mathematica is sending you. Here is how you might use it:

     // ml is a KernelLink
     PacketListener stdoutPrinter = new PacketPrinter(System.out);
     ml.addPacketListener(stdoutPrinter);
After the execution of the above code, the contents of all packets that arrive during calls to the KernelLink methods waitForAnswer(), discardAnswer(), or any of the "evaluateTo" set will be printed to System.out. No matter how many PacketListeners are registered, their monitoring of incoming packets will never interfere with any other packet-handling code in your program, so you can turn on and off this full packet tracing by just adding or removing the two lines above. No other changes whatsoever are required to your program.

See Also:
PacketListener, PacketArrivedEvent, KernelLink

Constructor Summary
PacketPrinter()
          Prints packets to System.out.
PacketPrinter(java.io.PrintStream strm)
           
 
Method Summary
 boolean packetArrived(PacketArrivedEvent evt)
          Invoked when a packet arrives on the link.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketPrinter

public PacketPrinter()
Prints packets to System.out.


PacketPrinter

public PacketPrinter(java.io.PrintStream strm)
Parameters:
strm - the stream on which packets will be printed
Method Detail

packetArrived

public boolean packetArrived(PacketArrivedEvent evt)
                      throws MathLinkException
Invoked when a packet arrives on the link.

Specified by:
packetArrived in interface PacketListener
Parameters:
evt - the PacketArrivedEvent
Returns:
true
Throws:
MathLinkException


J/Link is Copyright (c) 1999-2008, Wolfram Research, Inc. All rights reserved.