use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class MessageFormat_1_0 method createMessageMetaData.
private MessageMetaData_1_0 createMessageMetaData(final List<EncodingRetainingSection<?>> allSections, final List<EncodingRetainingSection<?>> dataSections) {
long contentSize = 0L;
HeaderSection headerSection = null;
PropertiesSection propertiesSection = null;
DeliveryAnnotationsSection deliveryAnnotationsSection = null;
MessageAnnotationsSection messageAnnotationsSection = null;
ApplicationPropertiesSection applicationPropertiesSection = null;
FooterSection footerSection = null;
Iterator<EncodingRetainingSection<?>> iter = allSections.iterator();
EncodingRetainingSection<?> s = iter.hasNext() ? iter.next() : null;
if (s instanceof HeaderSection) {
headerSection = (HeaderSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof DeliveryAnnotationsSection) {
deliveryAnnotationsSection = (DeliveryAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof MessageAnnotationsSection) {
messageAnnotationsSection = (MessageAnnotationsSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof PropertiesSection) {
propertiesSection = (PropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof ApplicationPropertiesSection) {
applicationPropertiesSection = (ApplicationPropertiesSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s instanceof AmqpValueSection) {
contentSize = s.getEncodedSize();
dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} else if (s instanceof DataSection) {
do {
contentSize += s.getEncodedSize();
dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof DataSection);
} else if (s instanceof AmqpSequenceSection) {
do {
contentSize += s.getEncodedSize();
dataSections.add(s);
s = iter.hasNext() ? iter.next() : null;
} while (s instanceof AmqpSequenceSection);
}
if (s instanceof FooterSection) {
footerSection = (FooterSection) s;
s = iter.hasNext() ? iter.next() : null;
}
if (s != null) {
throw new ConnectionScopedRuntimeException(String.format("Encountered unexpected section '%s'", s.getClass().getSimpleName()));
}
return new MessageMetaData_1_0(headerSection, deliveryAnnotationsSection, messageAnnotationsSection, propertiesSection, applicationPropertiesSection, footerSection, System.currentTimeMillis(), contentSize);
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class Message_1_0 method getContent.
@Override
public QpidByteBuffer getContent(final int offset, final int length) {
if (getMessageMetaData().getVersion() == 0) {
SectionDecoder sectionDecoder = new SectionDecoderImpl(DESCRIBED_TYPE_REGISTRY.getSectionDecoderRegistry());
try {
List<EncodingRetainingSection<?>> sections;
// not just #getSize()
try (QpidByteBuffer allSectionsContent = super.getContent(0, Integer.MAX_VALUE)) {
sections = sectionDecoder.parseAll(allSectionsContent);
}
List<QpidByteBuffer> bodySectionContent = new ArrayList<>();
for (final EncodingRetainingSection<?> section : sections) {
if (section instanceof DataSection || section instanceof AmqpValueSection || section instanceof AmqpSequenceSection) {
bodySectionContent.add(section.getEncodedForm());
}
section.dispose();
}
try (QpidByteBuffer bodyContent = QpidByteBuffer.concatenate(bodySectionContent)) {
bodySectionContent.forEach(QpidByteBuffer::dispose);
return bodyContent.view(offset, length);
}
} catch (AmqpErrorException e) {
throw new ConnectionScopedRuntimeException(e);
}
} else {
return super.getContent(offset, length);
}
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class AMQPConnection_0_8Impl method closed.
@Override
public void closed() {
try {
try {
if (!_orderlyClose.get()) {
completeAndCloseAllChannels();
}
} finally {
performDeleteTasks();
final NamedAddressSpace virtualHost = getAddressSpace();
if (virtualHost != null) {
virtualHost.deregisterConnection(this);
}
}
} catch (ConnectionScopedRuntimeException | TransportException e) {
LOGGER.error("Could not close protocol engine", e);
} finally {
markTransportClosed();
}
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException in project qpid-broker-j by apache.
the class Session_1_0 method receiveAttach.
public void receiveAttach(final Attach attach) {
receivedComplete();
if (_sessionState == SessionState.ACTIVE) {
UnsignedInteger inputHandle = attach.getHandle();
if (_inputHandleToEndpoint.containsKey(inputHandle)) {
String errorMessage = String.format("Input Handle '%d' already in use", inputHandle.intValue());
getConnection().close(new Error(SessionError.HANDLE_IN_USE, errorMessage));
throw new ConnectionScopedRuntimeException(errorMessage);
} else {
final Link_1_0<? extends BaseSource, ? extends BaseTarget> link;
if (attach.getRole() == Role.RECEIVER) {
link = getAddressSpace().getSendingLink(getConnection().getRemoteContainerId(), attach.getName());
} else {
link = getAddressSpace().getReceivingLink(getConnection().getRemoteContainerId(), attach.getName());
}
final ListenableFuture<? extends LinkEndpoint<?, ?>> future = link.attach(this, attach);
addFutureCallback(future, new EndpointCreationCallback(attach), MoreExecutors.directExecutor());
}
}
}
use of org.apache.qpid.server.util.ConnectionScopedRuntimeException 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);
}
Aggregations