124 WCTME: Application Development and Case Study
* adds a message itself as a message listener
*/
public void setupMQeServer() {
mqeAdmin.createHomeServerQueue(targetQMName, targetSFQ);
Thread kicker = new Thread(this);
kicker.start();
MQeQueueManager qm = MQeQueueManager.getDefaultQueueManager();
try {
qm.addMessageListener(this, MQe.System_Default_Queue_Name, null);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* This method is called by the queue manager when a message arrives
* The method extracts the contract id and slot number from the message,
and updates
* the database with the information
*/
public void messageArrived(MQeMessageEvent arg0) throws Exception {
MQeQueueManager qm = MQeQueueManager.getDefaultQueueManager();
//until we run out of messages
for (;;) {
try {
MQeMsgObject msg = qm.getMessage(null,
MQe.System_Default_Queue_Name, null, null, 0);
String contractID = msg.getAscii("ContractID");
String slot = msg.getAscii("Slot");
System.out.println( "In messageArrived. Updating " + contractID +
" to slot " + slot);
databaseService.updateVechicleLocation(contractID, slot);
} catch (MQeMessageStoreException mqemse) {
System.out.println("Exception in messageArrived. [" +
mqemse.getMessage() + "]");
mqemse.printStackTrace();
} catch (Exception e) {
if (!e.getMessage().equalsIgnoreCase("Message not found")) {
System.out.println("Exception in messageArrived. [" +
e.getMessage() + "]");
e.printStackTrace();
}
break;
}