use of org.apache.qpid.server.protocol.v1_0.type.transport.End in project qpid-broker-j by apache.
the class AttachTest method attachReceiverWithNullTarget.
@Test
@SpecificationTest(section = "2.6.3", description = "Note that if the application chooses not to create a terminus, the session endpoint will" + " still create a link endpoint and issue an attach indicating that the link endpoint has" + " no associated local terminus. In this case, the session endpoint MUST immediately" + " detach the newly created link endpoint.")
public void attachReceiverWithNullTarget() throws Exception {
String queueName = "testQueue";
getBrokerAdmin().createQueue(queueName);
final InetSocketAddress addr = getBrokerAdmin().getBrokerAddress(BrokerAdmin.PortType.ANONYMOUS_AMQP);
try (FrameTransport transport = new FrameTransport(addr).connect()) {
Interaction interaction = transport.newInteraction();
final Attach responseAttach = interaction.negotiateProtocol().consumeResponse().open().consumeResponse(Open.class).begin().consumeResponse(Begin.class).attachRole(Role.RECEIVER).attachSourceAddress(queueName).attachTarget(null).attach().consumeResponse().getLatestResponse(Attach.class);
assertThat(responseAttach.getName(), is(notNullValue()));
assertThat(responseAttach.getHandle().longValue(), is(both(greaterThanOrEqualTo(0L)).and(lessThan(UnsignedInteger.MAX_VALUE.longValue()))));
assertThat(responseAttach.getRole(), is(Role.SENDER));
assertThat(responseAttach.getSource(), is(nullValue()));
assertThat(responseAttach.getTarget(), is(nullValue()));
final Detach responseDetach = interaction.consumeResponse().getLatestResponse(Detach.class);
assertThat(responseDetach.getClosed(), is(true));
assertThat(responseDetach.getError(), is(notNullValue()));
assertThat(responseDetach.getError().getCondition(), is(equalTo(AmqpError.INVALID_FIELD)));
final End endResponse = interaction.flowHandleFromLinkHandle().flowEcho(true).flow().consumeResponse().getLatestResponse(End.class);
assertThat(endResponse.getError(), is(notNullValue()));
// QPID-7954
// assertThat(endResponse.getError().getCondition(), is(equalTo(SessionError.ERRANT_LINK)));
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.End in project qpid-broker-j by apache.
the class AbstractReceivingLinkEndpoint method receiveTransfer.
void receiveTransfer(final Transfer transfer) {
if (!isErrored()) {
Error error = validateTransfer(transfer);
if (error != null) {
transfer.dispose();
if (_currentDelivery != null) {
_currentDelivery.discard();
_currentDelivery = null;
}
close(error);
return;
}
if (_currentDelivery == null) {
error = validateNewTransfer(transfer);
if (error != null) {
transfer.dispose();
close(error);
return;
}
_currentDelivery = new Delivery(transfer, this);
setLinkCredit(getLinkCredit().subtract(UnsignedInteger.ONE));
getDeliveryCount().incr();
getSession().getIncomingDeliveryRegistry().addDelivery(transfer.getDeliveryId(), new UnsettledDelivery(transfer.getDeliveryTag(), this));
} else {
error = validateSubsequentTransfer(transfer);
if (error != null) {
transfer.dispose();
_currentDelivery.discard();
_currentDelivery = null;
close(error);
return;
}
_currentDelivery.addTransfer(transfer);
}
if (_currentDelivery.getTotalPayloadSize() > getSession().getConnection().getMaxMessageSize()) {
error = new Error(LinkError.MESSAGE_SIZE_EXCEEDED, String.format("delivery '%s' exceeds max-message-size %d", _currentDelivery.getDeliveryTag(), getSession().getConnection().getMaxMessageSize()));
_currentDelivery.discard();
_currentDelivery = null;
close(error);
return;
}
if (!_currentDelivery.getResume()) {
_unsettled.put(_currentDelivery.getDeliveryTag(), _currentDelivery.getState());
}
if (_currentDelivery.isAborted() || (_currentDelivery.getResume() && !_unsettled.containsKey(_currentDelivery.getDeliveryTag()))) {
_unsettled.remove(_currentDelivery.getDeliveryTag());
getSession().getIncomingDeliveryRegistry().removeDelivery(_currentDelivery.getDeliveryId());
_currentDelivery = null;
setLinkCredit(getLinkCredit().add(UnsignedInteger.ONE));
getDeliveryCount().decr();
} else if (_currentDelivery.isComplete()) {
try {
if (_currentDelivery.isSettled()) {
_unsettled.remove(_currentDelivery.getDeliveryTag());
getSession().getIncomingDeliveryRegistry().removeDelivery(_currentDelivery.getDeliveryId());
}
error = receiveDelivery(_currentDelivery);
if (error != null) {
close(error);
}
} finally {
_currentDelivery = null;
}
}
} else {
End end = new End();
end.setError(new Error(SessionError.ERRANT_LINK, String.format("Received TRANSFER for link handle %s which is in errored state.", transfer.getHandle())));
getSession().end(end);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.End in project qpid-broker-j by apache.
the class Session_1_0 method updateDisposition.
private void updateDisposition(final Role role, final UnsignedInteger first, final UnsignedInteger last, final DeliveryState state, final boolean settled) {
Disposition disposition = new Disposition();
disposition.setRole(role);
disposition.setFirst(first);
disposition.setLast(last);
disposition.setSettled(settled);
disposition.setState(state);
if (settled) {
final DeliveryRegistry deliveryRegistry = role == Role.RECEIVER ? _incomingDeliveryRegistry : _outgoingDeliveryRegistry;
SequenceNumber pos = new SequenceNumber(first.intValue());
SequenceNumber end = new SequenceNumber(last.intValue());
while (pos.compareTo(end) <= 0) {
deliveryRegistry.removeDelivery(UnsignedInteger.valueOf(pos.intValue()));
pos.incr();
}
}
send(disposition);
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.End in project qpid-broker-j by apache.
the class Session_1_0 method end.
public void end(final End end) {
switch(_sessionState) {
case BEGIN_SENT:
_connection.sendEnd(_sendingChannel, end, false);
_sessionState = SessionState.END_PIPE;
break;
case ACTIVE:
detachLinks();
_connection.sendEnd(_sendingChannel, end, true);
_sessionState = SessionState.END_SENT;
break;
default:
End reply = new End();
Error error = new Error();
error.setCondition(AmqpError.ILLEGAL_STATE);
error.setDescription("END called on Session which has not been opened");
reply.setError(error);
_connection.sendEnd(_sendingChannel, reply, true);
break;
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.End 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;
}
Aggregations