Search in sources :

Example 1 with DataQueue

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;
}
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 DataQueue

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

Example 3 with DataQueue

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);
    }
}
Also used : BaseDataQueue(com.ibm.as400.access.BaseDataQueue) DataQueue(com.ibm.as400.access.DataQueue) KeyedDataQueue(com.ibm.as400.access.KeyedDataQueue) AS400(com.ibm.as400.access.AS400) KeyedDataQueue(com.ibm.as400.access.KeyedDataQueue)

Aggregations

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