Search in sources :

Example 1 with Accepted

use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted in project swiftmq-client by iitsoftware.

the class AMQPMessage method accept.

/**
 * Accepts delivery of this message. This is part of settlement with QoS modes at-least-once and exactly-once.
 *
 * @throws InvalidStateException If the state is invalid to perform this operation
 */
public void accept() throws InvalidStateException {
    if (consumer == null)
        throw new InvalidStateException("Message not associated with a consumer");
    if (settled && txnIdIF == null)
        throw new InvalidStateException("Accept not required; message has already been settled");
    DeliveryStateIF deliveryStateIF = null;
    if (txnIdIF == null)
        deliveryStateIF = new Accepted();
    else {
        TransactionalState transactionalState = new TransactionalState();
        transactionalState.setTxnId(txnIdIF);
        transactionalState.setOutcome(new Accepted());
        deliveryStateIF = transactionalState;
    }
    consumer.sendDisposition(this, deliveryStateIF);
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) InvalidStateException(com.swiftmq.amqp.v100.client.InvalidStateException) Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)

Example 2 with Accepted

use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted in project swiftmq-ce by iitsoftware.

the class SourceLink method verifyLocalAddress.

public void verifyLocalAddress() throws AuthenticationException, QueueException, TopicException, InvalidSelectorException {
    if (!dynamic) {
        // This is for the case of reconnecting to a Durable Subscriber without specifying a Source in the attach frame.
        if (localAddress == null) {
            String topicName = ctx.topicManager.getDurableTopicName(getName(), mySessionHandler.getVersionedConnection().getActiveLogin());
            if (topicName != null)
                localAddress = new AddressString(topicName);
            durability = TerminusDurability.CONFIGURATION;
        }
        super.verifyLocalAddress();
    }
    if (receiver == null) {
        MessageSelector msel = null;
        if (messageSelector != null) {
            msel = new MessageSelector(messageSelector);
            msel.compile();
        }
        if (dynamic) {
            expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
            durability = TerminusDurability.NONE;
            // sndSettleMode = SenderSettleMode.SETTLED.getValue();       // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
            queueName = ctx.queueManager.createTemporaryQueue();
            receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
        } else {
            if (isQueue) {
                expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
                durability = TerminusDurability.CONFIGURATION;
                // sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
                receiver = ctx.queueManager.createQueueReceiver(getLocalAddress().getValueString(), mySessionHandler.getVersionedConnection().getActiveLogin(), msel);
            } else {
                if (durability.getValue() == TerminusDurability.CONFIGURATION.getValue() || durability.getValue() == TerminusDurability.UNSETTLED_STATE.getValue()) {
                    if (!expiryPolicy.getValue().equals(TerminusExpiryPolicy.LINK_DETACH.getValue()))
                        expiryPolicy = TerminusExpiryPolicy.NEVER;
                    durability = TerminusDurability.CONFIGURATION;
                    // sndSettleMode = SenderSettleMode.UNSETTLED.getValue();
                    queueName = ctx.topicManager.subscribeDurable(name, (TopicImpl) getLocalDestination(), msel, noLocal, mySessionHandler.getVersionedConnection().getActiveLogin());
                } else {
                    expiryPolicy = TerminusExpiryPolicy.LINK_DETACH;
                    queueName = ctx.queueManager.createTemporaryQueue();
                    // sndSettleMode = SenderSettleMode.SETTLED.getValue(); // SETTLED is only possible with temp queues because bulk mode in message proc do not delete from persistent store
                    subscriberId = ctx.topicManager.subscribe((TopicImpl) localDestination, msel, noLocal, queueName, mySessionHandler.getVersionedConnection().getActiveLogin());
                }
                receiver = ctx.queueManager.createQueueReceiver(queueName, mySessionHandler.getVersionedConnection().getActiveLogin(), null);
            }
        }
    }
    if (remoteUnsettled != null) {
        final AbstractQueue aq = ctx.queueManager.getQueueForInternalUse(receiver.getQueueName());
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, abstractQueue=" + aq);
        DataByteArrayInputStream dbis = new DataByteArrayInputStream();
        for (Iterator iter = remoteUnsettled.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry entry = (Map.Entry) iter.next();
            AMQPBinary deliveryTag = (AMQPBinary) entry.getKey();
            DeliveryStateIF deliveryStateIF = null;
            try {
                deliveryStateIF = DeliveryStateFactory.create((AMQPList) entry.getValue());
            } catch (Exception e) {
                throw new QueueException("Unable to create delivery tag");
            }
            final MessageIndex messageIndex = new MessageIndex();
            dbis.setBuffer(deliveryTag.getValue());
            try {
                messageIndex.readContent(dbis);
            } catch (IOException e) {
                throw new QueueException("Unable to convert delivery tag into a message index");
            }
            if (ctx.traceSpace.enabled)
                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", deliveryStateIF=" + deliveryStateIF);
            if (deliveryStateIF != null) {
                deliveryStateIF.accept(new DeliveryStateVisitorAdapter() {

                    public void visit(Accepted accepted) {
                        try {
                            if (aq != null) {
                                MessageIndex indexEntry = aq.getIndexEntry(messageIndex);
                                if (indexEntry != null) {
                                    aq.removeMessageByIndex(indexEntry);
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + indexEntry + ", removed");
                                } else {
                                    if (ctx.traceSpace.enabled)
                                        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", NOT FOUND!");
                                }
                            }
                        } catch (QueueException e) {
                            e.printStackTrace();
                            if (ctx.traceSpace.enabled)
                                ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/recovery, messageIndex=" + messageIndex + ", exception=" + e);
                        }
                    }
                });
            }
        }
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) IOException(java.io.IOException) DataByteArrayInputStream(com.swiftmq.tools.util.DataByteArrayInputStream) IOException(java.io.IOException) AuthenticationException(com.swiftmq.swiftlet.auth.AuthenticationException) InvalidSelectorException(javax.jms.InvalidSelectorException) TopicException(com.swiftmq.swiftlet.topic.TopicException) Iterator(java.util.Iterator) MessageSelector(com.swiftmq.ms.MessageSelector) TopicImpl(com.swiftmq.jms.TopicImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Accepted

use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted in project swiftmq-client by iitsoftware.

the class DeliveryStateFactory method create.

/**
 * Creates a DeliveryStateIF object.
 *
 * @param bare the bare AMQP type
 * @return DeliveryStateIF
 */
public static DeliveryStateIF 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 == Received.DESCRIPTOR_CODE)
            return new Received(((AMQPList) bare).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());
        if (type == TransactionalState.DESCRIPTOR_CODE)
            return new TransactionalState(((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(Received.DESCRIPTOR_NAME))
            return new Received(((AMQPList) bare).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());
        if (type.equals(TransactionalState.DESCRIPTOR_NAME))
            return new TransactionalState(((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) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)

Example 4 with Accepted

use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted 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 5 with Accepted

use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted in project swiftmq-client by iitsoftware.

the class SessionDispatcher method settleOutbound.

private void settleOutbound(long from, long to, boolean settled, DeliveryStateIF deliveryState) {
    if (from <= to) {
        long current = from;
        while (current <= to) {
            DeliveryMapping deliveryMapping = unsettledOutgoingDeliveries.remove(current);
            if (deliveryMapping != null) {
                deliveryMapping.link.getDeliveryMemory().deliverySettled(deliveryMapping.deliveryTag);
                if (deliveryMapping.link.getWaitingPO() != null) {
                    POSendMessage po = (POSendMessage) deliveryMapping.link.getWaitingPO();
                    po.setSuccess(true);
                    po.setDeliveryState(deliveryState);
                    po.getSemaphore().notifySingleWaiter();
                    deliveryMapping.link.setWaitingPO(null);
                }
                // If there is a close waiting on that link, dispatch it when there are no more unsettled deliveries
                if (deliveryMapping.link.getDeliveryMemory().getNumberUnsettled() == 0 && deliveryMapping.link.getWaitingClosePO() != null) {
                    dispatch(deliveryMapping.link.getWaitingClosePO());
                    deliveryMapping.link.setWaitingClosePO(null);
                }
            }
            current++;
            outgoingWindow++;
        }
        if (deliveryState != null) {
            if (!settled && deliveryState instanceof Accepted) {
                DispositionFrame dispoFrame = new DispositionFrame(mySession.getChannel());
                dispoFrame.setRole(Role.SENDER);
                dispoFrame.setFirst(new DeliveryNumber(from));
                dispoFrame.setLast(new DeliveryNumber(to));
                dispoFrame.setSettled(AMQPBoolean.TRUE);
                dispoFrame.setState(new Accepted());
                outboundHandler.send(dispoFrame);
            }
        }
    } else {
    // TODO: error
    }
}
Also used : Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)

Aggregations

Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)5 IOException (java.io.IOException)4 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)2 Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)1 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 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)1 DeliveryTag (com.swiftmq.amqp.v100.generated.transport.definitions.DeliveryTag)1 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)1 TopicImpl (com.swiftmq.jms.TopicImpl)1 MessageSelector (com.swiftmq.ms.MessageSelector)1 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)1 TopicException (com.swiftmq.swiftlet.topic.TopicException)1 DataByteArrayInputStream (com.swiftmq.tools.util.DataByteArrayInputStream)1 HashMap (java.util.HashMap)1