Search in sources :

Example 1 with Declared

use of com.swiftmq.amqp.v100.generated.transactions.coordination.Declared 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 2 with Declared

use of com.swiftmq.amqp.v100.generated.transactions.coordination.Declared 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 3 with Declared

use of com.swiftmq.amqp.v100.generated.transactions.coordination.Declared in project swiftmq-client by iitsoftware.

the class TransactionController method createTxnId.

/**
 * Creates a new transaction id.
 *
 * @return transaction id
 * @throws AMQPException on error
 */
public synchronized TxnIdIF createTxnId() throws AMQPException {
    if (producer == null) {
        producer = mySession.createProducer(Coordinator.DESCRIPTOR_NAME, QoS.AT_LEAST_ONCE);
        producer.setTransactionController(true);
        Set capa = producer.getDestinationCapabilities();
        if (capa != null) {
            if (capa.contains(TxnCapability.LOCAL_TRANSACTIONS.getValue()))
                supportLocalTransactions = true;
            supportDistributedTransactions = capa.contains(TxnCapability.DISTRIBUTED_TRANSACTIONS.getValue());
            supportPromotableTransactions = capa.contains(TxnCapability.PROMOTABLE_TRANSACTIONS.getValue());
            supportMultiTxnsPerSsn = capa.contains(TxnCapability.MULTI_TXNS_PER_SSN.getValue());
            supportMultiSsnsPerTxn = capa.contains(TxnCapability.MULTI_SSNS_PER_TXN.getValue());
        }
    }
    AMQPMessage msg = new AMQPMessage();
    msg.setAmqpValue(new AmqpValue(new Declare()));
    Declared declared = (Declared) producer.send(msg);
    return declared == null ? null : declared.getTxnId();
}
Also used : Set(java.util.Set) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Aggregations

Declared (com.swiftmq.amqp.v100.generated.transactions.coordination.Declared)2 IOException (java.io.IOException)2 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)1 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)1 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)1 Set (java.util.Set)1