Search in sources :

Example 1 with Rejected

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

the class AMQPMessage method reject.

/**
 * <p>Rejects delivery of this message. This is part of settlement with QoS modes at-least-once and exactly-once.
 * </p>
 * <p>
 * This operation causes the delivery count to be incremented and the message to be redelivered to this or other
 * competing consumers.
 * </p>
 *
 * @throws InvalidStateException If the state is invalid to perform this operation
 */
public void reject() throws InvalidStateException {
    if (consumer == null)
        throw new InvalidStateException("Message not associated with a consumer");
    if (settled && txnIdIF == null)
        throw new InvalidStateException("Reject not possible; message has already been settled");
    DeliveryStateIF deliveryStateIF = null;
    if (txnIdIF == null)
        deliveryStateIF = new Rejected();
    else {
        TransactionalState transactionalState = new TransactionalState();
        transactionalState.setTxnId(txnIdIF);
        transactionalState.setOutcome(new Rejected());
        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) Rejected(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected) TransactionalState(com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)

Example 2 with Rejected

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

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

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

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

the class TransactionController method discharge.

private synchronized void discharge(TxnIdIF txnId, boolean fail) throws AMQPException {
    AMQPMessage msg = new AMQPMessage();
    Discharge discharge = new Discharge();
    discharge.setTxnId(txnId);
    discharge.setFail(new AMQPBoolean(fail));
    msg.setAmqpValue(new AmqpValue(discharge));
    DeliveryStateIF deliveryState = producer.send(msg);
    if (deliveryState instanceof Rejected) {
        Rejected rejected = (Rejected) deliveryState;
        com.swiftmq.amqp.v100.generated.transport.definitions.Error error = rejected.getError();
        if (error != null)
            throw new AMQPException(error.getValueString());
        else
            throw new AMQPException(("Unknown transactiom error"));
    }
}
Also used : DeliveryStateIF(com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF) Rejected(com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Aggregations

IOException (java.io.IOException)3 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)2 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)2 Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)2 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)2 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)1 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)1 Error (com.swiftmq.amqp.v100.generated.transport.definitions.Error)1 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)1 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1