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