Search in sources :

Example 6 with AMQPSymbol

use of com.swiftmq.amqp.v100.types.AMQPSymbol in project swiftmq-client by iitsoftware.

the class OutcomeFactory method create.

/**
 * Creates a OutcomeIF object.
 *
 * @param bare the bare AMQP type
 * @return OutcomeIF
 */
public static OutcomeIF create(AMQPType bare) throws Exception {
    if (bare.getCode() == AMQPTypeDecoder.NULL)
        return null;
    AMQPDescribedConstructor constructor = bare.getConstructor();
    if (constructor == null)
        throw new IOException("Missing constructor: " + bare);
    AMQPType descriptor = constructor.getDescriptor();
    int code = descriptor.getCode();
    if (AMQPTypeDecoder.isULong(code)) {
        long type = ((AMQPUnsignedLong) descriptor).getValue();
        if (type == Accepted.DESCRIPTOR_CODE)
            return new Accepted(((AMQPList) bare).getValue());
        if (type == Rejected.DESCRIPTOR_CODE)
            return new Rejected(((AMQPList) bare).getValue());
        if (type == Released.DESCRIPTOR_CODE)
            return new Released(((AMQPList) bare).getValue());
        if (type == Modified.DESCRIPTOR_CODE)
            return new Modified(((AMQPList) bare).getValue());
        if (type == Declared.DESCRIPTOR_CODE)
            return new Declared(((AMQPList) bare).getValue());
        throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
    } else if (AMQPTypeDecoder.isSymbol(code)) {
        String type = ((AMQPSymbol) descriptor).getValue();
        if (type.equals(Accepted.DESCRIPTOR_NAME))
            return new Accepted(((AMQPList) bare).getValue());
        if (type.equals(Rejected.DESCRIPTOR_NAME))
            return new Rejected(((AMQPList) bare).getValue());
        if (type.equals(Released.DESCRIPTOR_NAME))
            return new Released(((AMQPList) bare).getValue());
        if (type.equals(Modified.DESCRIPTOR_NAME))
            return new Modified(((AMQPList) bare).getValue());
        if (type.equals(Declared.DESCRIPTOR_NAME))
            return new Declared(((AMQPList) bare).getValue());
        throw new Exception("Invalid descriptor type: " + type + ", bare=" + bare);
    } else
        throw new Exception("Invalid type of constructor descriptor (actual type=" + code + ", expected=symbold or ulong), bare= " + bare);
}
Also used : IOException(java.io.IOException) Declared(com.swiftmq.amqp.v100.generated.transactions.coordination.Declared) IOException(java.io.IOException)

Example 7 with AMQPSymbol

use of com.swiftmq.amqp.v100.types.AMQPSymbol 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 8 with AMQPSymbol

use of com.swiftmq.amqp.v100.types.AMQPSymbol in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POFillCache po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    Consumer c = po.getConsumer();
    FlowFrame flowFrame = new FlowFrame(mySession.getChannel());
    flowFrame.setHandle(new Handle(c.getHandle()));
    flowFrame.setAvailable(new AMQPUnsignedInt(0));
    flowFrame.setDrain(AMQPBoolean.FALSE);
    flowFrame.setNextIncomingId(new TransferNumber(nextIncomingId));
    flowFrame.setNextOutgoingId(new TransferNumber(nextOutgoingId));
    flowFrame.setLinkCredit(new AMQPUnsignedInt(po.getLinkCredit()));
    flowFrame.setIncomingWindow(new AMQPUnsignedInt(incomingWindow));
    flowFrame.setOutgoingWindow(new AMQPUnsignedInt(outgoingWindow));
    if (po.getLastDeliveryId() != -1)
        flowFrame.setDeliveryCount(new SequenceNo(po.getLastDeliveryId()));
    TxnIdIF txnIdIF = po.getTxnIdIF();
    if (txnIdIF != null) {
        Map map = new HashMap();
        map.put(new AMQPSymbol("txn-id"), txnIdIF);
        try {
            flowFrame.setProperties(new Fields(map));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    outboundHandler.send(flowFrame);
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " done");
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) IOException(java.io.IOException)

Example 9 with AMQPSymbol

use of com.swiftmq.amqp.v100.types.AMQPSymbol in project swiftmq-client by iitsoftware.

the class SessionDispatcher method visit.

public void visit(POAttachConsumer po) {
    if (pTracer.isEnabled())
        pTracer.trace(toString(), ", visit, po=" + po + " ...");
    String name = null;
    DeliveryMemory deliveryMemory = po.getDeliveryMemory();
    if (deliveryMemory.getLinkName() != null)
        name = deliveryMemory.getLinkName();
    else {
        name = uniqueSessionId + "/" + po.getSource() + "/" + (nextLinkId++);
        deliveryMemory.setLinkName(name);
    }
    Consumer consumer = null;
    if (po.getLinkCredit() == -1)
        consumer = new Consumer(mySession, po.getSource(), name, po.getQoS(), deliveryMemory);
    else
        consumer = new Consumer(mySession, po.getSource(), name, po.getLinkCredit(), po.getQoS(), deliveryMemory);
    int handle = ArrayListTool.setFirstFreeOrExpand(handles, consumer);
    consumer.setHandle(handle);
    po.setLink(consumer);
    waitingPO.put(name, po);
    try {
        AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
        attachFrame.setName(new AMQPString(name));
        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);
        source.setDurable(TerminusDurability.NONE);
        source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        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(name));
        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 10 with AMQPSymbol

use of com.swiftmq.amqp.v100.types.AMQPSymbol in project swiftmq-client by iitsoftware.

the class Connection method close.

protected void close(String condition, String description) {
    if (closed)
        return;
    if (condition == null) {
        Semaphore sem = new Semaphore();
        POSendClose po = new POSendClose(sem, condition == null ? null : new AMQPSymbol(condition), description == null ? null : new AMQPString(description));
        connectionDispatcher.dispatch(po);
        sem.waitHere();
    } else {
        POSendClose po = new POSendClose(null, condition == null ? null : new AMQPSymbol(condition), description == null ? null : new AMQPString(description));
        connectionDispatcher.dispatch(po);
    }
    cancel();
    if (exceptionListener != null && condition != null && description != null)
        exceptionListener.onException(new ConnectionClosedException(condition + " / " + description));
}
Also used : AMQPSymbol(com.swiftmq.amqp.v100.types.AMQPSymbol) Semaphore(com.swiftmq.tools.concurrent.Semaphore) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) POSendClose(com.swiftmq.amqp.v100.client.po.POSendClose)

Aggregations

IOException (java.io.IOException)14 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)4 Map (java.util.Map)4 JMSException (javax.jms.JMSException)4 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)3 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)3 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 NoLocalFilter (com.swiftmq.amqp.v100.generated.filter.filter_types.NoLocalFilter)2 SelectorFilter (com.swiftmq.amqp.v100.generated.filter.filter_types.SelectorFilter)2 Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)2 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)2 Seconds (com.swiftmq.amqp.v100.generated.transport.definitions.Seconds)2 Iterator (java.util.Iterator)2 StreamException (com.rabbitmq.stream.StreamException)1 com.rabbitmq.stream.amqp (com.rabbitmq.stream.amqp)1 POSendClose (com.swiftmq.amqp.v100.client.po.POSendClose)1 com.swiftmq.amqp.v100.generated.messaging.message_format (com.swiftmq.amqp.v100.generated.messaging.message_format)1 Coordinator (com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator)1