Search in sources :

Example 6 with Handle

use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle 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 7 with Handle

use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-ce by iitsoftware.

the class SessionHandler method doSendOneMessage.

private void doSendOneMessage(SourceMessageProcessor sourceMessageProcessor, SourceLink sourceLink, Delivery delivery, boolean restart) throws EndWithErrorException {
    try {
        if (remoteIncomingWindow > 0 && outgoingWindow > 0) {
            do {
                boolean wasFirstPacket = false;
                delivery.setMaxFrameSize(amqpHandler.getMaxFrameSize());
                TransferFrame frame = new TransferFrame(channel);
                frame.setHandle(new Handle(sourceLink.getHandle()));
                frame.setSettled(new AMQPBoolean(sourceLink.getSndSettleMode() == SenderSettleMode.SETTLED.getValue()));
                if (delivery.getCurrentPacketNumber() == 0) {
                    if (ctx.traceSpace.enabled)
                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, amqpMessage=" + delivery.getAmqpMessage());
                    long totalSize = delivery.getSize();
                    wasFirstPacket = true;
                    sourceLink.incDeliveryCountSnd();
                    long dId = nextDeliveryId();
                    frame.setDeliveryId(new DeliveryNumber(dId));
                    frame.setDeliveryTag(createDeliveryTag(delivery));
                    TxnIdIF currentTx = sourceLink.getCurrentTx();
                    if (currentTx != null) {
                        TransactionalState tState = new TransactionalState();
                        tState.setTxnId(currentTx);
                        frame.setState(tState);
                        transactionRegistry.addToTransaction(currentTx, sourceLink, dId, delivery.getMessageIndex(), totalSize);
                        totalSize = 0;
                    }
                    if (!frame.getSettled().getValue()) {
                        unsettledOutgoingDeliveries.put(dId, sourceLink);
                        if (totalSize > 0)
                            sourceLink.addUnsettled(dId, delivery.getMessageIndex(), totalSize);
                        else
                            sourceLink.addUnsettled(dId, delivery.getMessageIndex());
                    } else {
                        sourceLink.autoack(delivery.getMessageIndex());
                    }
                    incMsgsSent(1);
                }
                delivery.getNextPacket(frame);
                // We may increase the outgoing window and send a flow before
                if (wasFirstPacket && outgoingWindow - delivery.getPredictedNumberPackets() < 0) {
                    outgoingWindow += delivery.getPredictedNumberPackets();
                    sendFlow();
                    windowChanged = true;
                }
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", sending message, wasFirstPacket=" + wasFirstPacket + ", maxSize=" + delivery.getMaxPayloadLength() + ", packetSize=" + frame.getPayload().length + ", predictedNumberPackets=" + delivery.getPredictedNumberPackets() + ", currentPacket=" + delivery.getCurrentPacketNumber() + ", hasMore=" + delivery.hasMore());
                versionedConnection.send(frame);
                if (!frame.getSettled().getValue())
                    outgoingWindow--;
                nextOutgoingId++;
                remoteIncomingWindow--;
                if (!delivery.hasMore()) {
                    if (restart) {
                        if (sourceLink.getLinkCredit() > 0)
                            sourceLink.startMessageProcessor(sourceMessageProcessor);
                        else
                            sourceLink.clearMessageProcessor();
                    }
                    // If that was the last packet and outgoing window was increased for this message, we need to reset it and send another flow
                    if (windowChanged) {
                        outgoingWindow = initialOutgoingWindow;
                        sendFlow();
                    }
                    break;
                }
            } while (remoteIncomingWindow > 0 && outgoingWindow > 0);
            if (delivery.hasMore()) {
                if (ctx.traceSpace.enabled)
                    ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, remoteIncomingWindows=" + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", has more but no window, storing message");
                outboundDeliveries.add(new OutboundDelivery(sourceMessageProcessor, sourceLink, delivery, restart));
            }
        } else {
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + ", doSendOneMessage, no remote incoming window = " + remoteIncomingWindow + ", outgoingWindow=" + outgoingWindow + ", store for later transfer");
            outboundDeliveries.add(new OutboundDelivery(sourceMessageProcessor, sourceLink, delivery, restart));
        }
    } catch (IOException e) {
        throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("IOException during outbound send: " + e.getMessage()));
    } catch (QueueException e) {
        throw new ConnectionEndException(AmqpError.INTERNAL_ERROR, new AMQPString("QueueException during outbound send: " + e.getMessage()));
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) IOException(java.io.IOException) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState) QueueException(com.swiftmq.swiftlet.queue.QueueException)

Example 8 with Handle

use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.

the class FlowFrame method decode.

private void decode() throws Exception {
    List l = body.getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            nextIncomingId = new TransferNumber(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'nextIncomingId' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'incomingWindow' in 'Flow' frame is NULL");
    try {
        incomingWindow = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'incomingWindow' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'nextOutgoingId' in 'Flow' frame is NULL");
    try {
        nextOutgoingId = new TransferNumber(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'nextOutgoingId' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'outgoingWindow' in 'Flow' frame is NULL");
    try {
        outgoingWindow = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'outgoingWindow' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            handle = new Handle(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'handle' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            deliveryCount = new SequenceNo(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'deliveryCount' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            linkCredit = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'linkCredit' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            available = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'available' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            drain = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'drain' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            echo = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'echo' in 'Flow' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            properties = new Fields(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'properties' in 'Flow' frame: " + e);
    }
}
Also used : SequenceNo(com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo) Fields(com.swiftmq.amqp.v100.generated.transport.definitions.Fields) TransferNumber(com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Handle(com.swiftmq.amqp.v100.generated.transport.definitions.Handle)

Example 9 with Handle

use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.

the class BeginFrame method decode.

private void decode() throws Exception {
    List l = body.getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            remoteChannel = (AMQPUnsignedShort) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'remoteChannel' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'nextOutgoingId' in 'Begin' frame is NULL");
    try {
        nextOutgoingId = new TransferNumber(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'nextOutgoingId' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'incomingWindow' in 'Begin' frame is NULL");
    try {
        incomingWindow = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'incomingWindow' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'outgoingWindow' in 'Begin' frame is NULL");
    try {
        outgoingWindow = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'outgoingWindow' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            handleMax = new Handle(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'handleMax' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            offeredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'offeredCapabilities' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            desiredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'desiredCapabilities' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            properties = new Fields(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'properties' in 'Begin' frame: " + e);
    }
}
Also used : Fields(com.swiftmq.amqp.v100.generated.transport.definitions.Fields) TransferNumber(com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Handle(com.swiftmq.amqp.v100.generated.transport.definitions.Handle)

Example 10 with Handle

use of com.swiftmq.amqp.v100.generated.transport.definitions.Handle in project swiftmq-client by iitsoftware.

the class DetachFrame method decode.

private void decode() throws Exception {
    List l = body.getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'handle' in 'Detach' frame is NULL");
    try {
        handle = new Handle(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'handle' in 'Detach' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            closed = (AMQPBoolean) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'closed' in 'Detach' frame: " + e);
    }
    // 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 'Detach' frame: " + e);
    }
}
Also used : Error(com.swiftmq.amqp.v100.generated.transport.definitions.Error) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Handle(com.swiftmq.amqp.v100.generated.transport.definitions.Handle)

Aggregations

IOException (java.io.IOException)9 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)3 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)3 Handle (com.swiftmq.amqp.v100.generated.transport.definitions.Handle)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 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)2 Error (com.swiftmq.amqp.v100.generated.transport.definitions.Error)2 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)2 TransferNumber (com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 Coordinator (com.swiftmq.amqp.v100.generated.transactions.coordination.Coordinator)1 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)1 Packager (com.swiftmq.amqp.v100.transport.Packager)1 QueueException (com.swiftmq.swiftlet.queue.QueueException)1