use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach 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.transport.Attach in project qpid-broker-j by apache.
the class AbstractLinkEndpoint method sendAttach.
@Override
public void sendAttach() {
Attach attachToSend = new Attach();
attachToSend.setName(getLinkName());
attachToSend.setRole(getRole());
attachToSend.setHandle(getLocalHandle());
attachToSend.setSource(getSource());
attachToSend.setTarget(getTarget());
attachToSend.setSndSettleMode(getSendingSettlementMode());
attachToSend.setRcvSettleMode(getReceivingSettlementMode());
attachToSend.setUnsettled(getLocalUnsettled());
attachToSend.setProperties(_properties);
attachToSend.setOfferedCapabilities(_capabilities);
if (getRole() == Role.SENDER) {
attachToSend.setInitialDeliveryCount(_deliveryCount.unsignedIntegerValue());
} else {
final long maxMessageSize = getSession().getConnection().getMaxMessageSize();
if (maxMessageSize != Long.MAX_VALUE) {
attachToSend.setMaxMessageSize(UnsignedLong.valueOf(maxMessageSize));
}
}
attachToSend = handleOversizedUnsettledMapIfNecessary(attachToSend);
switch(_state) {
case DETACHED:
_state = State.ATTACH_SENT;
break;
case ATTACH_RECVD:
_state = State.ATTACHED;
break;
default:
throw new UnsupportedOperationException(_state.toString());
}
getSession().sendAttach(attachToSend);
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class ErrantLinkEndpoint method sendAttach.
@Override
public void sendAttach() {
Attach attachToSend = new Attach();
attachToSend.setName(_link.getName());
attachToSend.setRole(getRole());
attachToSend.setHandle(getLocalHandle());
attachToSend.setSource(getSource());
attachToSend.setTarget(getTarget());
_session.sendAttach(attachToSend);
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class Session_1_0Test method testReceiveAttachTopicNonDurableWithContainer.
public void testReceiveAttachTopicNonDurableWithContainer() throws Exception {
final String linkName = "testLink";
final String address = "amq.direct/" + TOPIC_NAME;
Attach attach = createTopicAttach(false, linkName, address, false);
_session.receiveAttach(attach);
assertAttachSent(_connection, _session, attach);
assertQueues(TOPIC_NAME, LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS);
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class Session_1_0Test method createAttach.
private Attach createAttach(final boolean durable, final String linkName, final String address, final Symbol destinationTypeCapability, final boolean isGlobal, final boolean isShared) {
Attach attach = new Attach();
Source source = new Source();
List<Symbol> capabilities = new ArrayList<>();
if (isGlobal) {
capabilities.add(Symbol.getSymbol("global"));
}
if (isShared) {
capabilities.add(Symbol.getSymbol("shared"));
}
capabilities.add(destinationTypeCapability);
source.setCapabilities(capabilities.toArray(new Symbol[capabilities.size()]));
if (durable) {
source.setDurable(TerminusDurability.CONFIGURATION);
source.setExpiryPolicy(TerminusExpiryPolicy.NEVER);
} else {
source.setDurable(TerminusDurability.NONE);
source.setExpiryPolicy(TerminusExpiryPolicy.LINK_DETACH);
}
attach.setSource(source);
Target target = new Target();
attach.setTarget(target);
attach.setHandle(new UnsignedInteger(_handle++));
attach.setIncompleteUnsettled(false);
attach.setName(linkName);
attach.setRole(Role.RECEIVER);
source.setAddress(address);
return attach;
}
Aggregations