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);
}
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);
}
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);
}
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);
}
}
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"));
}
}
Aggregations