package dataqueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import com.ibm.as400.access.Record;
public class
DtaQExample3aListener implements PropertyChangeListener {
/**
* This method gets called
* when a bound property is changed.
* Listen for change in bound property set by the data queue thread. Show
* property name on console. If property name is dqRead show data read
* from data queue on console.
*
* @param event A PropertyChangeEvent object describing the event
* source and the property that has changed.
*/
public void propertyChange(PropertyChangeEvent
event) {
// Print to console that a property
change event was fired and
// the name of the property.
System.out.println(" ************* propertyChange() name is: " +
event.getPropertyName() + "
********");
// The thread
listening to the data queue could fire different
// events based on what was read from
the data queue.
if ( event.getPropertyName().equals("dqRead") ) {
// dump the data read from the
data queue to the console.
try {
// Record
object with the data read from the data queue
// is passed
as the new value in the event
Record mdloData = (Record) event.getNewValue();
// Get two
values out of the record and display them.
String mdloInstruction = (String) mdloData.getField("OINSTRTN");
String mdloMessage = (String) mdloData.getField("OMESSAGE");
System.out.println(" * The model received instruction: "
+ mdloInstruction.trim()
+ "\n * and returned data: "
+ mdloMessage.trim());
System.out
.println(" ********************************************************");
} catch (Exception e) {
e.printStackTrace();
}
}
}
}