use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class Interaction method handleCoordinatorResponse.
private DeliveryState handleCoordinatorResponse() throws Exception {
final Set<Class<?>> expected = new HashSet<>(Collections.singletonList(Disposition.class));
if (_coordinatorCredits.decrementAndGet() == 0) {
expected.add(Flow.class);
}
final Map<Class<?>, ?> responses = consumeResponses(expected, Collections.singleton(Flow.class));
final Disposition disposition = (Disposition) responses.get(Disposition.class);
if (expected.contains(Flow.class)) {
Flow flow = (Flow) responses.get(Flow.class);
if (flow.getHandle().equals(getCoordinatorHandle())) {
final UnsignedInteger linkCredit = flow.getLinkCredit();
if (linkCredit != null) {
_coordinatorCredits.set(linkCredit.longValue());
}
}
}
if (!Boolean.TRUE.equals(disposition.getSettled())) {
throw new IllegalStateException("Coordinator disposition is not settled");
}
return disposition.getState();
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class Session_1_0 method updateDisposition.
void updateDisposition(final Role role, final Set<Binary> deliveryTags, final DeliveryState state, final boolean settled) {
final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
SortedSet<UnsignedInteger> deliveryIds = deliveryTags.stream().map(deliveryRegistry::getDeliveryIdByTag).collect(Collectors.toCollection(TreeSet::new));
final Iterator<UnsignedInteger> iterator = deliveryIds.iterator();
if (iterator.hasNext()) {
UnsignedInteger begin = iterator.next();
UnsignedInteger end = begin;
while (iterator.hasNext()) {
final UnsignedInteger deliveryId = iterator.next();
if (!end.add(UnsignedInteger.ONE).equals(deliveryId)) {
updateDisposition(role, begin, end, state, settled);
begin = deliveryId;
end = begin;
} else {
end = deliveryId;
}
}
updateDisposition(role, begin, end, state, settled);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class Session_1_0 method updateDisposition.
void updateDisposition(final Role role, final Binary deliveryTag, final DeliveryState state, final boolean settled) {
final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
UnsignedInteger deliveryId = deliveryRegistry.getDeliveryIdByTag(deliveryTag);
if (deliveryId == null) {
throw new ConnectionScopedRuntimeException(String.format("Delivery with tag '%s' is not found in unsettled deliveries", deliveryTag));
}
updateDisposition(role, deliveryId, deliveryId, state, settled);
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class AbstractLinkEndpoint method handleOversizedUnsettledMapIfNecessary.
private Attach handleOversizedUnsettledMapIfNecessary(final Attach attachToSend) {
final AMQPDescribedTypeRegistry describedTypeRegistry = getSession().getConnection().getDescribedTypeRegistry();
final ValueWriter<Attach> valueWriter = describedTypeRegistry.getValueWriter(attachToSend);
if (valueWriter.getEncodedSize() + 8 > getSession().getConnection().getMaxFrameSize()) {
_localIncompleteUnsettled = true;
attachToSend.setIncompleteUnsettled(true);
final int targetSize = getSession().getConnection().getMaxFrameSize();
int lowIndex = 0;
Map<Binary, DeliveryState> localUnsettledMap = attachToSend.getUnsettled();
if (localUnsettledMap == null) {
localUnsettledMap = Collections.emptyMap();
}
int highIndex = localUnsettledMap.size();
int currentIndex = (highIndex - lowIndex) / 2;
int oldIndex;
HashMap<Binary, DeliveryState> unsettledMap = null;
int totalSize;
do {
HashMap<Binary, DeliveryState> partialUnsettledMap = new HashMap<>(currentIndex);
final Iterator<Map.Entry<Binary, DeliveryState>> iterator = localUnsettledMap.entrySet().iterator();
for (int i = 0; i < currentIndex; ++i) {
final Map.Entry<Binary, DeliveryState> entry = iterator.next();
partialUnsettledMap.put(entry.getKey(), entry.getValue());
}
attachToSend.setUnsettled(partialUnsettledMap);
totalSize = describedTypeRegistry.getValueWriter(attachToSend).getEncodedSize() + FRAME_HEADER_SIZE;
if (totalSize > targetSize) {
highIndex = currentIndex;
} else if (totalSize < targetSize) {
lowIndex = currentIndex;
unsettledMap = partialUnsettledMap;
} else {
lowIndex = highIndex = currentIndex;
unsettledMap = partialUnsettledMap;
}
oldIndex = currentIndex;
currentIndex = lowIndex + (highIndex - lowIndex) / 2;
} while (oldIndex != currentIndex);
if (unsettledMap == null || unsettledMap.isEmpty()) {
final End endWithError = new End();
endWithError.setError(new Error(AmqpError.FRAME_SIZE_TOO_SMALL, "Cannot fit a single unsettled delivery into Attach frame."));
getSession().end(endWithError);
}
attachToSend.setUnsettled(unsettledMap);
} else {
_localIncompleteUnsettled = false;
}
return attachToSend;
}
use of org.apache.qpid.server.protocol.v1_0.type.DeliveryState in project qpid-broker-j by apache.
the class Delivery method addTransfer.
final void addTransfer(Transfer transfer) {
if (_aborted) {
throw new IllegalStateException(String.format("Delivery '%s/%d' is already aborted", _deliveryTag, _deliveryId.intValue()));
}
if (_complete) {
throw new IllegalStateException(String.format("Delivery '%s/%d' is already completed", _deliveryTag, _deliveryId.intValue()));
}
_transfers.add(transfer);
if (Boolean.TRUE.equals(transfer.getAborted())) {
_aborted = true;
discard();
}
if (!Boolean.TRUE.equals(transfer.getMore())) {
_complete = true;
}
if (Boolean.TRUE.equals(transfer.getSettled())) {
_settled = true;
}
if (Boolean.TRUE.equals(transfer.getResume())) {
_resume = true;
}
if (transfer.getState() != null) {
DeliveryState currentState;
if (_state instanceof TransactionalState) {
currentState = ((TransactionalState) _state).getOutcome();
} else {
currentState = _state;
}
if (!(currentState instanceof Outcome)) {
_state = transfer.getState();
}
}
if (transfer.getRcvSettleMode() != null) {
if (_receiverSettleMode == null) {
_receiverSettleMode = transfer.getRcvSettleMode();
}
}
try (QpidByteBuffer payload = transfer.getPayload()) {
if (payload != null) {
_totalPayloadSize += (long) payload.remaining();
}
}
}
Aggregations