package dataqueue;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import
com.ibm.as400.access.KeyedDataQueueEntry;
import com.ibm.as400.access.Record;
import com.ibm.as400.access.RecordFormat;
import common.MDLOFMFormat;
/**
* PropertyChangeListener to listen for events fired by ModelOutputDataQueue
* which formats generic KeyedDataQueue entries received from the generic
* ModelOutputDataQueue and render them into data according to RecordFormats
* of a specific model implementation. This class encapsulates specific
* knowledge of the Model which output the data queue entries read by
* ModelOutputDataQueue.
*
* @author Bill Blalock
*
*/
public class
DtaQExample3dListener implements PropertyChangeListener {
RecordFormat mdloFormat = new MDLOFMFormat();
/**
* 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 {
// The KeyedDataQueueEntry returned by KeyedDataQueue.read()
// is passed
as the new value in the event
Record mdloData = mdloFormat
.getNewRecord(
((KeyedDataQueueEntry) event.getNewValue()).getData() );
// 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();
}
}
}
}