use of com.ibm.as400.access.DataQueue in project sirius-biz by scireum.
the class I5Connection method readQueue.
/**
* Reads all entries available in the given queue.
*
* @param queue the name of the queue to read
* @param timeoutSeconds the max timeout to wait for entries
* @return the list of entries read
* @throws Exception in case of a communication or host error
*/
@Nonnull
public List<DataQueueEntry> readQueue(String queue, int timeoutSeconds) throws Exception {
List<DataQueueEntry> result = new ArrayList<>();
DataQueue q = new DataQueue(i5, queue);
DataQueueEntry entry = q.read(timeoutSeconds);
while (entry != null) {
result.add(entry);
entry = q.read(timeoutSeconds);
}
return result;
}
use of com.ibm.as400.access.DataQueue in project camel by apache.
the class Jt400DataQueueConsumer method receive.
private Exchange receive(DataQueue queue, long timeout) throws Exception {
DataQueueEntry entry;
if (timeout >= 0) {
int seconds = (int) timeout / 1000;
log.trace("Reading from data queue: {} with {} seconds timeout", queue.getName(), seconds);
entry = queue.read(seconds);
} else {
log.trace("Reading from data queue: {} with no timeout", queue.getName());
entry = queue.read(-1);
}
Exchange exchange = getEndpoint().createExchange();
if (entry != null) {
exchange.getIn().setHeader(Jt400Endpoint.SENDER_INFORMATION, entry.getSenderInformation());
if (getEndpoint().getFormat() == Jt400Configuration.Format.binary) {
exchange.getIn().setBody(entry.getData());
} else {
exchange.getIn().setBody(entry.getString());
}
return exchange;
}
return null;
}
use of com.ibm.as400.access.DataQueue in project camel by apache.
the class Jt400DataQueueService method start.
@Override
public void start() throws Exception {
if (queue == null) {
AS400 system = endpoint.getSystem();
if (endpoint.isKeyed()) {
queue = new KeyedDataQueue(system, endpoint.getObjectPath());
} else {
queue = new DataQueue(system, endpoint.getObjectPath());
}
}
if (!queue.getSystem().isConnected(AS400.DATAQUEUE)) {
LOG.info("Connecting to {}", endpoint);
queue.getSystem().connectService(AS400.DATAQUEUE);
}
}
Aggregations