use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class AbstractLinkEndpoint method receiveAttach.
@Override
public void receiveAttach(final Attach attach) throws AmqpErrorException {
_errored = false;
boolean isAttachingRemoteTerminusNull = (attach.getRole() == Role.SENDER ? attach.getSource() == null : attach.getTarget() == null);
boolean isAttachingLocalTerminusNull = (attach.getRole() == Role.SENDER ? attach.getTarget() == null : attach.getSource() == null);
boolean isLocalTerminusNull = (attach.getRole() == Role.SENDER ? getTarget() == null : getSource() == null);
if (isAttachingRemoteTerminusNull) {
throw new AmqpErrorException(AmqpError.INVALID_FIELD, "received Attach with remote null terminus.");
}
if (isAttachingLocalTerminusNull) {
recoverLink(attach);
} else if (isLocalTerminusNull) {
establishLink(attach);
} else if (attach.getUnsettled() != null) {
// TODO: QPID-7845 : Functionality for resuming links is not fully implemented
if (attach.getUnsettled().isEmpty()) {
resumeLink(attach);
} else {
throw new AmqpErrorException(new Error(AmqpError.NOT_IMPLEMENTED, "Resuming link is not implemented."));
}
} else {
reattachLink(attach);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class LinkImpl method attach.
@Override
public final synchronized ListenableFuture<? extends LinkEndpoint<S, T>> attach(final Session_1_0 session, final Attach attach) {
try {
if (_role == attach.getRole()) {
throw new AmqpErrorException(new Error(AmqpError.ILLEGAL_STATE, "Cannot switch SendingLink to ReceivingLink and vice versa"));
}
if (_linkEndpoint != null && !session.equals(_linkEndpoint.getSession())) {
SettableFuture<LinkEndpoint<S, T>> future = SettableFuture.create();
_thiefQueue.add(new ThiefInformation(session, attach, future));
startLinkStealingIfNecessary();
return future;
} else {
if (_linkEndpoint == null) {
_linkEndpoint = createLinkEndpoint(session, attach);
}
_linkEndpoint.receiveAttach(attach);
_linkRegistry.linkChanged(this);
return Futures.immediateFuture(_linkEndpoint);
}
} catch (Exception e) {
LOGGER.debug("Error attaching link", e);
return rejectLink(session, e);
}
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class LinkImpl method doStealLink.
private ListenableFuture<LinkEndpoint<S, T>> doStealLink(final Session_1_0 session, final Attach attach) {
final SettableFuture<LinkEndpoint<S, T>> returnFuture = SettableFuture.create();
LinkEndpoint<S, T> linkEndpoint = _linkEndpoint;
// check whether linkEndpoint has been closed in the mean time
if (linkEndpoint != null) {
linkEndpoint.getSession().doOnIOThreadAsync(() -> {
// check whether linkEndpoint has been closed in the mean time
if (_linkEndpoint != null) {
_linkEndpoint.close(new Error(LinkError.STOLEN, String.format("Link is being stolen by connection '%s'", session.getConnection())));
}
doLinkStealAndHandleExceptions(session, attach, returnFuture);
});
} else {
doLinkStealAndHandleExceptions(session, attach, returnFuture);
}
return returnFuture;
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class SendingLinkEndpoint method resumeLink.
@Override
protected void resumeLink(final Attach attach) throws AmqpErrorException {
if (getSource() == null) {
throw new IllegalStateException("Terminus should be set when resuming a Link.");
}
if (attach.getSource() == null) {
throw new IllegalStateException("Attach.getSource should not be null when resuming a Link. That would be recovering the Link.");
}
Source newSource = (Source) attach.getSource();
Source oldSource = getSource();
final SendingDestination destination = getSession().getSendingDestination(getLink(), oldSource);
prepareConsumerOptionsAndFilters(destination);
if (getDestination() instanceof ExchangeSendingDestination && !Boolean.TRUE.equals(newSource.getDynamic())) {
final SendingDestination newDestination = getSession().getSendingDestination(getLink(), newSource);
if (getSession().updateSourceForSubscription(this, newSource, newDestination)) {
setDestination(newDestination);
}
}
attachReceived(attach);
}
use of org.apache.qpid.server.protocol.v1_0.type.transport.Attach in project qpid-broker-j by apache.
the class StandardReceivingLinkEndpoint method recoverLink.
@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
if (getTarget() == null) {
throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, String.format("Link '%s' not found", getLinkName())));
}
attach.setTarget(getTarget());
receiveAttach(attach);
}
Aggregations