public interface SmartInspectListener
| Modifier and Type | Method and Description |
|---|---|
void |
onControlCommand(ControlCommandEvent e)
Occurs when a ControlCommand packet is processed.
|
void |
onError(ErrorEvent e)
This event is fired after an error occurred.
|
void |
onFilter(FilterEvent e)
Occurs before a packet is processed.
|
void |
onLogEntry(LogEntryEvent e)
Occurs when a LogEntry packet is processed.
|
void |
onProcessFlow(ProcessFlowEvent e)
Occurs when a ProcessFlow packet is processed.
|
void |
onWatch(WatchEvent e)
This event occurs when a Watch packet is processed.
|
void onError(ErrorEvent e)
This event is fired when an error occurs. An error could be a connection problem or wrong permissions when writing log files, for example. Instead of throwing exceptions, this event is used for error reporting in the SmartInspect Java library. The event handlers are always called in the context of the thread which causes the event. In asynchronous protocol mode, this is not necessarily the thread that initiated the related log call.
Please note: Keep in mind that adding SmartInspect log statements or other code to the event handlers which can lead to the error event can cause a presumably undesired recursive behavior.
Example:
import com.gurock.smartinspect.*;
class Listener extends SmartInspectAdapter
{
public void onError(ErrorEvent e)
{
System.out.println(e.getException());
}
}
public class ErrorHandling
{
public static void main(String[] args)
{
// Register our event handler for the error event.
SiAuto.si.addListener(new Listener());
try
{
// Force a connection error.
SiAuto.si.setConnections("file(filename=c:\\\\)");
}
catch (InvalidConnectionsException e)
{
// This catch block is useless. It won't be reached
// anyway, because a connection error doesn't result
// in a Java exception. The SmartInspect Java library
// uses the Error event for this purpose.
}
SiAuto.si.setEnabled(true);
}
}
e - The event argument for the event handlersErrorEventvoid onControlCommand(ControlCommandEvent e)
You can use this event if custom processing of ControlCommand packets is needed. The event handlers are always called in the context of the thread which causes the event.
Please note: Keep in mind that adding SmartInspect log
statements to the event handlers can cause a presumably undesired
recursive behavior. Also, if you specified that one or more
connections of this SmartInspect object should operate in
asynchronous protocol mode, you need to protect the passed ControlCommand packet and its data by
calling its Packet.lock() and Packet.unlock() methods before and after processing.
import com.gurock.smartinspect.*;
class Listener extends SmartInspectAdapter
{
public void onControlCommand(ControlCommandEvent e)
{
System.out.println(e.getControlCommand().toString());
}
}
public class ControlCommandHandling
{
public static void main(String[] args)
{
SiAuto.si.setEnabled(true);
SiAuto.si.addListener(new Listener());
SiAuto.main.clearAll();
}
}
e - The event argument for the event handlersControlCommand,
ControlCommandEventvoid onLogEntry(LogEntryEvent e)
You can use this event if custom processing of LogEntry packets is needed. The event handlers are always called in the context of the thread which causes the event.
Please note: Keep in mind that adding SmartInspect log statements to the event handlers can cause a presumably undesired recursive behavior. Also, if you specified that one or more connections of this SmartInspect object should operate in asynchronous protocol mode, you need to protect the passed LogEntry packet and its data by calling its lock and unlock methods before and after processing.
Example:
import com.gurock.smartinspect.*;
class Listener extends SmartInspectAdapter
{
public void onLogEntry(LogEntryEvent e)
{
System.out.println(e.getLogEntry().toString());
}
}
public class LogEntryHandling
{
public static void main(String[] args)
{
SiAuto.si.setEnabled(true);
SiAuto.si.addListener(new Listener());
SiAuto.main.logMessage("This is an event test!");
}
}
e - The event argument for the event handlersLogEntry,
LogEntryEventvoid onProcessFlow(ProcessFlowEvent e)
Please note: Keep in mind that adding SmartInspect log statements to the event handlers can cause a presumably undesired recursive behavior. Also, if you specified that one or more connections of this SmartInspect object should operate in asynchronous protocol mode, you need to protect the passed ProcessFlow packet and its data by calling its lock and unlock methods before and after processing.
Example:
import com.gurock.smartinspect.*;
class Listener extends SmartInspectAdapter
{
public void onProcessFlow(ProcessFlowEvent e)
{
System.out.println(e.getProcessFlow().toString());
}
}
public class ProcessFlowHandling
{
public static void main(String[] args)
{
SiAuto.si.setEnabled(true);
SiAuto.si.addListener(new Listener());
SiAuto.main.enterThread("Main Thread");
}
}
e - The event argument for the event handlersProcessFlow,
ProcessFlowEventvoid onWatch(WatchEvent e)
Please note: Keep in mind that adding SmartInspect log statements to the event handlers can cause a presumably undesired recursive behavior. Also, if you specified that one or more connections of this SmartInspect object should operate in asynchronous protocol mode, you need to protect the passed Watch packet and its data by calling its lock and unlock methods before and after processing.
Usage example:
import com.gurock.smartinspect.*;
class Listener extends SmartInspectAdapter
{
public void onWatch(WatchEvent e)
{
System.out.println(e.getWatch().toString());
}
}
public class WatchHandling
{
public static void main(String[] args)
{
SiAuto.si.setEnabled(true);
SiAuto.si.addListener(new Listener());
SiAuto.main.watchInt("Integer", 23);
}
}
e - the event argument for the event handlersWatch,
WatchEventvoid onFilter(FilterEvent e)
import com.gurock.smartinspect.*;
class Listener extends SmartInspectAdapter
{
public void onFilter(FilterEvent e)
{
if (e.getPacket() instanceof LogEntry)
{
LogEntry logEntry = (LogEntry) e.getPacket();
if (logEntry.getTitle().equals("Cancel Me"))
{
e.setCancel(true);
}
}
}
}
public class FilterHandling
{
public static void main(String[] args)
{
SiAuto.si.setEnabled(true);
// Register a listener for the filter event
SiAuto.si.addListener(new Listener());
// The second message will not be logged
SiAuto.main.logMessage("Message");
SiAuto.main.logMessage("Cancel Me");
}
}
e - The event argument for the event handlersPacket,
FilterEventCopyright © 2023. All rights reserved.