}
public BridgeMsg receiveMessage() throws BridgeException {
try {
/* get MQ message */
MQMessage mqMsg = new MQMessage();
MQGetMessageOptions opt = new MQGetMessageOptions();
opt.options = MQC.MQGMO_SYNCPOINT | MQC.MQGMO_ALL_SEGMENTS_AVAILABLE | MQC.MQGMO_COMPLETE_MSG | MQC.MQGMO_WAIT;
opt.waitInterval = 4000; // this value should be smaller than what ChannelInstance.close allows for normal shutdown
log.debug("queue.get() start");
for (;;) {
synchronized (stopping) {
if (stopping.value)
return null;
}
try {
queue.get(mqMsg, opt);
break;
}
catch (MQException ex) {
if (ex.reasonCode != MQException.MQRC_NO_MSG_AVAILABLE)
throw ex;
}
}
log.debug("queue.get() returned");
msgLog.logEarlyReceive(createBridgeMessageId(mqMsg.messageId));
/* build bridge message */
BridgeMsg msg = new BridgeMsg();
/* message payload */
if (mqMsg.format.equals(MQC.MQFMT_STRING)) {
/* text message */
msg.setMsgType(BridgeMsg.TYPE_TEXT);
String textData = mqMsg.readStringOfByteLength(mqMsg.getDataLength());
msg.setTextData(textData);
}
else {
/* anything other is binary data */
msg.setMsgType(BridgeMsg.TYPE_BYTES);
int len = mqMsg.getDataLength();
byte[] data = new byte[len];
mqMsg.readFully(data);
msg.setByteData(data);
}
/* message headers */
msg.setMessageId(createBridgeMessageId(mqMsg.messageId));
msg.setPersistence(createBridgePersistence(mqMsg.persistence));