}
private Exchange receive(KeyedDataQueue queue, long timeout) throws Exception {
String key = endpoint.getSearchKey();
String searchType = endpoint.getSearchType().name();
KeyedDataQueueEntry entry;
if (timeout >= 0) {
int seconds = (int) timeout / 1000;
log.trace("Reading from data queue: {} with {} seconds timeout", queue.getName(), seconds);
entry = queue.read(key, seconds, searchType);
} else {
log.trace("Reading from data queue: {} with no timeout", queue.getName());
entry = queue.read(key, -1, searchType);
}
Exchange exchange = new DefaultExchange(endpoint.getCamelContext());
if (entry != null) {
exchange.getIn().setHeader(Jt400DataQueueEndpoint.SENDER_INFORMATION, entry.getSenderInformation());
if (endpoint.getFormat() == Format.binary) {
exchange.getIn().setBody(entry.getData());
exchange.getIn().setHeader(Jt400DataQueueEndpoint.KEY, entry.getKey());
} else {
exchange.getIn().setBody(entry.getString());
exchange.getIn().setHeader(Jt400DataQueueEndpoint.KEY, entry.getKeyString());
}
return exchange;
}
return null;