Search in sources :

Example 1 with POAttachDurableConsumer

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

the class SessionDispatcher method visit.

public void visit(POAttachDurableConsumer po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    DeliveryMemory deliveryMemory = po.getDeliveryMemory();
    if (deliveryMemory.getLinkName() != null)
        deliveryMemory.setLinkName(po.getLinkName());
    DurableConsumer consumer = new DurableConsumer(mySession, po.getSource(), po.getLinkName(), po.getLinkCredit(), po.getQoS(), deliveryMemory);
    int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
    consumer.setHandle(handle);
    po.setLink(consumer);
    waitingPO.put(po.getLinkName(), po);
    try {
        AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
        attachFrame.setName(new AMQPString(po.getLinkName()));
        attachFrame.setHandle(new Handle(handle));
        attachFrame.setRole(Role.RECEIVER);
        if (consumer.getQoS() == QoS.AT_MOST_ONCE)
            attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
        Source source = new Source();
        String s = po.getSource();
        if (s != null)
            source.setAddress(new AddressString(s));
        else
            source.setDynamic(AMQPBoolean.TRUE);
        // This identifies a durable
        source.setDurable(TerminusDurability.CONFIGURATION);
        source.setExpiryPolicy(po.getExpiryPolicy());
        source.setTimeout(new Seconds(0));
        Map m = null;
        if (po.isNoLocal()) {
            m = new HashMap();
            m.put(new AMQPSymbol("no-local-filter"), new NoLocalFilter());
        }
        if (po.getSelector() != null) {
            if (m == null)
                m = new HashMap();
            m.put(new AMQPSymbol("jms-selector-filter"), new SelectorFilter(po.getSelector()));
        }
        if (m != null)
            source.setFilter(new FilterSet(m));
        attachFrame.setSource(source);
        Target target = new Target();
        target.setAddress(new AddressString(uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++)));
        target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        target.setTimeout(new Seconds(0));
        attachFrame.setTarget(target);
        attachFrame.setUnsettled(getUnsettledMap(consumer.getDeliveryMemory()));
        outboundHandler.send(attachFrame);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) NoLocalFilter(com.swiftmq.amqp.v100.generated.filter.filter_types.NoLocalFilter) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) IOException(java.io.IOException) SelectorFilter(com.swiftmq.amqp.v100.generated.filter.filter_types.SelectorFilter)

Example 2 with POAttachDurableConsumer

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

the class DurableConsumer method unsubscribe.

/**
 * Unsubscribes the durable consumer and destroys the durable link.
 *
 * @throws AMQPException
 */
public void unsubscribe() throws AMQPException {
    if (!closed)
        close();
    Semaphore sem = new Semaphore();
    POAttachDurableConsumer po = new POAttachDurableConsumer(sem, name, source, linkCredit, qoS, false, null, TerminusExpiryPolicy.LINK_DETACH, deliveryMemory);
    mySession.getSessionDispatcher().dispatch(po);
    sem.waitHere();
    if (!po.isSuccess())
        throw new AMQPException(po.getException());
    DurableConsumer c = (DurableConsumer) po.getLink();
    c.close();
}
Also used : POAttachDurableConsumer(com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer) Semaphore(com.swiftmq.tools.concurrent.Semaphore) POAttachDurableConsumer(com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)

Aggregations

POAttachDurableConsumer (com.swiftmq.amqp.v100.client.po.POAttachDurableConsumer)1 NoLocalFilter (com.swiftmq.amqp.v100.generated.filter.filter_types.NoLocalFilter)1 SelectorFilter (com.swiftmq.amqp.v100.generated.filter.filter_types.SelectorFilter)1 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 Semaphore (com.swiftmq.tools.concurrent.Semaphore)1 IOException (java.io.IOException)1