Search in sources :

Example 6 with AMQPType

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

the class Rejected method decode.

private void decode() throws Exception {
    List l = getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            error = new Error(((AMQPList) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'error' in 'Rejected' type: " + e);
    }
}
Also used : Error(com.swiftmq.amqp.v100.generated.transport.definitions.Error) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 7 with AMQPType

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

the class Header method decode.

private void decode() throws Exception {
    List l = getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            durable = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'durable' in 'Header' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            priority = (AMQPUnsignedByte) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'priority' in 'Header' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            ttl = new Milliseconds(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'ttl' in 'Header' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            firstAcquirer = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'firstAcquirer' in 'Header' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            deliveryCount = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'deliveryCount' in 'Header' type: " + e);
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) IOException(java.io.IOException)

Example 8 with AMQPType

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

the class SessionDispatcher method visit.

public void visit(POAttachProducer 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.getTarget() + "/" + (nextLinkId++);
        deliveryMemory.setLinkName(name);
    }
    Producer producer = new Producer(mySession, po.getTarget(), name, po.getQoS(), deliveryMemory);
    int handle = ArrayListTool.setFirstFreeOrExpand(handles, producer);
    producer.setHandle(handle);
    po.setLink(producer);
    waitingPO.put(name, po);
    try {
        AttachFrame attachFrame = new AttachFrame(mySession.getChannel());
        attachFrame.setName(new AMQPString(name));
        attachFrame.setHandle(new Handle(handle));
        attachFrame.setRole(Role.SENDER);
        switch(producer.getQoS()) {
            case QoS.AT_LEAST_ONCE:
                attachFrame.setRcvSettleMode(ReceiverSettleMode.FIRST);
                break;
            case QoS.AT_MOST_ONCE:
                attachFrame.setSndSettleMode(SenderSettleMode.SETTLED);
                break;
            case QoS.EXACTLY_ONCE:
                attachFrame.setRcvSettleMode(ReceiverSettleMode.SECOND);
                break;
        }
        Source source = new Source();
        source.setAddress(new AddressString(name));
        source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
        source.setTimeout(new Seconds(0));
        attachFrame.setSource(source);
        String t = po.getTarget();
        if (t.equals(Coordinator.DESCRIPTOR_NAME)) {
            Coordinator coordinator = new Coordinator();
            coordinator.setCapabilities(new AMQPArray(AMQPTypeDecoder.SYM8, new AMQPType[] { TxnCapability.LOCAL_TRANSACTIONS }));
            attachFrame.setTarget(coordinator);
        } else {
            Target target = new Target();
            target.setAddress(new AddressString(t));
            target.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
            target.setTimeout(new Seconds(0));
            attachFrame.setTarget(target);
        }
        attachFrame.setInitialDeliveryCount(new SequenceNo(producer.getDeliveryCountSnd()));
        attachFrame.setUnsettled(getUnsettledMap(producer.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) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) Coordinator(com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator) IOException(java.io.IOException)

Example 9 with AMQPType

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

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

the class Source method decode.

private void decode() throws Exception {
    List l = getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : AddressFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        address = AddressFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            durable = new TerminusDurability(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'durable' in 'Source' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            expiryPolicy = new TerminusExpiryPolicy(((AMQPSymbol) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'expiryPolicy' in 'Source' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            timeout = new Seconds(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'timeout' in 'Source' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            dynamic = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'dynamic' in 'Source' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            dynamicNodeProperties = new NodeProperties(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'dynamicNodeProperties' in 'Source' type: " + e);
    }
    // Factory  : DistributionModeFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        distributionMode = DistributionModeFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            filter = new FilterSet(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'filter' in 'Source' type: " + e);
    }
    // Factory  : OutcomeFactory
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() != AMQPTypeDecoder.NULL)
        defaultOutcome = OutcomeFactory.create(t);
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            outcomes = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'outcomes' in 'Source' type: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            capabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'capabilities' in 'Source' type: " + e);
    }
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) Seconds(com.swiftmq.amqp.v100.generated.transport.definitions.Seconds) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)20 List (java.util.List)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)6 Iterator (java.util.Iterator)5 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)4 Error (com.swiftmq.amqp.v100.generated.transport.definitions.Error)4 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)4 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)4 Handle (com.swiftmq.amqp.v100.generated.transport.definitions.Handle)3 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)3 AMQPType (com.swiftmq.amqp.v100.types.AMQPType)3 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)2 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)2 Coordinator (com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator)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 TransferNumber (com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber)2 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2