Search in sources :

Example 1 with DataQueueEntry

use of com.ibm.as400.access.DataQueueEntry 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;
}
Also used : DataQueue(com.ibm.as400.access.DataQueue) ArrayList(java.util.ArrayList) DataQueueEntry(com.ibm.as400.access.DataQueueEntry) Nonnull(javax.annotation.Nonnull)

Example 2 with DataQueueEntry

use of com.ibm.as400.access.DataQueueEntry 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;
}
Also used : Exchange(org.apache.camel.Exchange) KeyedDataQueueEntry(com.ibm.as400.access.KeyedDataQueueEntry) DataQueueEntry(com.ibm.as400.access.DataQueueEntry)

Aggregations

DataQueueEntry (com.ibm.as400.access.DataQueueEntry)2 DataQueue (com.ibm.as400.access.DataQueue)1 KeyedDataQueueEntry (com.ibm.as400.access.KeyedDataQueueEntry)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Exchange (org.apache.camel.Exchange)1