Search in sources :

Example 6 with DeliveryStateIF

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

use of com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF 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)

Example 8 with DeliveryStateIF

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

the class Producer method send.

/**
 * Send a message to the target. For transactional sends the method returns after settlement has been finished, otherwise when the message has been sent.
 *
 * @param msg        message
 * @param persistent whether the message should send/stored durable
 * @param priority   message priority (default is 5)
 * @param ttl        time to live (expiration) in milliseconds, default no expiration
 * @return delivery state of the message
 * @throws AMQPException on error
 */
public DeliveryStateIF send(AMQPMessage msg, boolean persistent, int priority, long ttl) throws AMQPException {
    verifyState();
    Header header = msg.getHeader();
    if (header == null) {
        header = new Header();
        msg.setHeader(header);
    }
    header.setDurable(new AMQPBoolean(persistent));
    header.setPriority(new AMQPUnsignedByte(priority));
    if (ttl >= 0)
        header.setTtl(new Milliseconds(ttl));
    Properties props = msg.getProperties();
    if (props == null) {
        props = new Properties();
        msg.setProperties(props);
    }
    if (props.getMessageId() == null)
        props.setMessageId(new MessageIdString(nextMsgId()));
    props.setTo(new AddressString(target));
    String userName = mySession.myConnection.getUserName();
    if (userName != null)
        props.setUserId(new AMQPBinary(userName.getBytes()));
    Semaphore sem = new Semaphore();
    try {
        POSendMessage po = new POSendMessage(sem, this, msg, msg.getTxnIdIF(), msg.getDeliveryTag());
        mySession.dispatch(po);
        sem.waitHere();
        if (!po.isSuccess())
            throw new AMQPException(po.getException());
        return po.getDeliveryState();
    } catch (Exception e) {
        e.printStackTrace();
        throw new AMQPException(e.toString());
    }
}
Also used : AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) POSendMessage(com.swiftmq.amqp.v100.client.po.POSendMessage) MessageIdString(com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString) MessageIdString(com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString) AddressString(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString) Semaphore(com.swiftmq.tools.concurrent.Semaphore) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) Milliseconds(com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds) IOException(java.io.IOException) Header(com.swiftmq.amqp.v100.generated.messaging.message_format.Header)

Example 9 with DeliveryStateIF

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

the class TargetLink method getLastDeliveryState.

public DeliveryStateIF getLastDeliveryState() {
    if (coordinator) {
        DeliveryStateIF ds = lastDeliveryState;
        lastDeliveryState = null;
        return ds;
    }
    return new Accepted();
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) Accepted(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)

Example 10 with DeliveryStateIF

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

the class TargetLink method addTransferFrame.

public boolean addTransferFrame(TransferFrame frame) throws EndWithErrorException {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addTransferFrame, frame=" + frame);
    if (currentMessage == null)
        currentMessage = frame;
    else {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addTransferFrame, frame=" + frame + ", add payload to currentMessage");
        currentMessage.addMorePayload(frame.getPayload());
        if (frame.getSettled() != null)
            currentMessage.setSettled(frame.getSettled());
    }
    if (frame.getMore() != null && frame.getMore().getValue())
        return false;
    boolean settled = false;
    if (currentMessage.getSettled() != null)
        settled = currentMessage.getSettled().getValue();
    lastDeliveryId = currentMessage.getDeliveryId();
    DeliveryStateIF state = currentMessage.getState();
    if (settled || rcvSettleMode == ReceiverSettleMode.FIRST.getValue() || state != null && state instanceof TransactionalState)
        transformAndStore(currentMessage);
    else
        unsettledFrames.put(currentMessage.getDeliveryId().getValue(), currentMessage);
    deliveryCount++;
    currentLinkCredit--;
    nmsgs++;
    boolean needMore = currentLinkCredit == 0;
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.amqpSwiftlet.getName(), toString() + "/addTransferFrame, frame=" + frame + ", currentLinkCredit=" + currentLinkCredit + ", needMore=" + needMore);
    if (needMore)
        currentLinkCredit = linkCredit;
    currentMessage = null;
    return needMore;
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)

Aggregations

DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)7 IOException (java.io.IOException)4 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)3 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)3 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)2 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)2 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2 AuthenticationException (com.swiftmq.swiftlet.auth.AuthenticationException)2 TopicException (com.swiftmq.swiftlet.topic.TopicException)2 HashMap (java.util.HashMap)2 InvalidSelectorException (javax.jms.InvalidSelectorException)2 POSendMessage (com.swiftmq.amqp.v100.client.po.POSendMessage)1 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)1 Header (com.swiftmq.amqp.v100.generated.messaging.message_format.Header)1 MessageIdString (com.swiftmq.amqp.v100.generated.messaging.message_format.MessageIdString)1 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)1 Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)1 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)1 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)1