Search in sources :

Example 1 with POSendResumedTransfer

use of com.swiftmq.amqp.v100.client.po.POSendResumedTransfer in project swiftmq-client by iitsoftware.

the class Producer method recover.

protected void recover(AMQPMap remoteUnsettled) {
    try {
        if (remoteUnsettled != null) {
            Map<AMQPType, AMQPType> map = remoteUnsettled.getValue();
            for (Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) {
                Map.Entry entry = (Map.Entry) iter.next();
                final DeliveryTag deliveryTag = new DeliveryTag(((AMQPBinary) entry.getKey()).getValue());
                final AMQPList deliveryState = (AMQPList) entry.getValue();
                if (deliveryState != null) {
                    try {
                        DeliveryStateFactory.create(deliveryState).accept(new DeliveryStateVisitorAdapter() {

                            public void visit(Accepted impl) {
                                deliveryMemory.deliverySettled(deliveryTag);
                                mySession.dispatch(new POSendResumedTransfer(Producer.this, deliveryTag));
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        if (deliveryMemory.getNumberUnsettled() > 0) {
            Collection<UnsettledDelivery> unsettled = deliveryMemory.getUnsettled();
            for (Iterator<UnsettledDelivery> iter = unsettled.iterator(); iter.hasNext(); ) {
                UnsettledDelivery unsettledDelivery = iter.next();
                if (unsettledDelivery.getMessage() != null) {
                    AMQPMessage msg = unsettledDelivery.getMessage();
                    if (msg.getTxnIdIF() == null) {
                        POSendMessage po = new POSendMessage(null, this, msg, null, unsettledDelivery.getDeliveryTag());
                        po.setRecovery(true);
                        mySession.dispatch(po);
                    }
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DeliveryStateVisitorAdapter(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateVisitorAdapter) POSendResumedTransfer(com.swiftmq.amqp.v100.client.po.POSendResumedTransfer) POSendMessage(com.swiftmq.amqp.v100.client.po.POSendMessage) IOException(java.io.IOException) DeliveryTag(com.swiftmq.amqp.v100.generated.transport.definitions.DeliveryTag) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted) IOException(java.io.IOException) Iterator(java.util.Iterator) Map(java.util.Map)

Example 2 with POSendResumedTransfer

use of com.swiftmq.amqp.v100.client.po.POSendResumedTransfer in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POSendResumedTransfer po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    TransferFrame frame = new TransferFrame(mySession.getChannel());
    frame.setHandle(new Handle(po.getProducer().getHandle()));
    frame.setSettled(new AMQPBoolean(true));
    frame.setResume(new AMQPBoolean(true));
    frame.setDeliveryId(new DeliveryNumber(nextOutgoingId++));
    frame.setDeliveryTag(po.getDeliveryTag());
    frame.setState(new Accepted());
    outboundHandler.send(frame);
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)

Aggregations

Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)2 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 POSendResumedTransfer (com.swiftmq.amqp.v100.client.po.POSendResumedTransfer)1 DeliveryStateVisitorAdapter (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateVisitorAdapter)1 DeliveryTag (com.swiftmq.amqp.v100.generated.transport.definitions.DeliveryTag)1 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)1 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1