Java源码示例:org.apache.qpid.proton.amqp.transport.ConnectionError
示例1
@Override
public void closed(TransportException error)
{
if (!_closeReceived || error != null) {
// Set an error condition, but only if one was not already set
if(!_conditionSet) {
if(error instanceof TransportDecodeException) {
setCondition(new ErrorCondition(AmqpError.DECODE_ERROR, error.getMessage()));
} else {
String description = error == null ? "connection aborted" : error.toString();
setCondition(new ErrorCondition(ConnectionError.FRAMING_ERROR, description));
}
}
_head_closed = true;
}
if (_conditionSet && !postedTransportError) {
put(Event.Type.TRANSPORT_ERROR, this);
postedTransportError = true;
}
if (!postedTailClosed) {
put(Event.Type.TRANSPORT_TAIL_CLOSED, this);
postedTailClosed = true;
maybePostClosed();
}
}
示例2
/**
* Given an ErrorCondition instance create a new Exception that best matches
* the error type that indicates the connection creation failed for some reason.
*
* @param provider
* the AMQP provider instance that originates this exception
* @param endpoint
* The target of the error.
* @param errorCondition
* The ErrorCondition returned from the remote peer.
*
* @return a new Exception instance that best matches the ErrorCondition value.
*/
public static ProviderConnectionRemotelyClosedException convertToConnectionClosedException(AmqpProvider provider, Endpoint endpoint, ErrorCondition errorCondition) {
ProviderConnectionRemotelyClosedException remoteError = null;
if (errorCondition != null && errorCondition.getCondition() != null) {
Symbol error = errorCondition.getCondition();
String message = extractErrorMessage(errorCondition);
if (error.equals(AmqpError.UNAUTHORIZED_ACCESS)) {
remoteError = new ProviderConnectionSecurityException(message);
} else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
remoteError = new ProviderConnectionResourceAllocationException(message);
} else if (error.equals(ConnectionError.CONNECTION_FORCED)) {
remoteError = new ProviderConnectionRemotelyClosedException(message);
} else if (error.equals(AmqpError.NOT_FOUND)) {
remoteError = new ProviderConnectionResourceNotFoundException(message);
} else if (error.equals(ConnectionError.REDIRECT)) {
remoteError = createRedirectException(provider, error, message, errorCondition);
} else if (error.equals(AmqpError.INVALID_FIELD)) {
Map<?, ?> info = errorCondition.getInfo();
if (info != null && CONTAINER_ID.equals(info.get(INVALID_FIELD))) {
remoteError = new ProviderInvalidClientIDException(message);
} else {
remoteError = new ProviderConnectionRemotelyClosedException(message);
}
} else {
remoteError = new ProviderConnectionRemotelyClosedException(message);
}
} else if (remoteError == null) {
remoteError = new ProviderConnectionRemotelyClosedException("Unknown error from remote peer");
}
return remoteError;
}
示例3
@Override
public void handleAttach(Attach attach, Binary payload, Integer channel)
{
TransportSession transportSession = _remoteSessions.get(channel);
if(transportSession == null)
{
// TODO - fail due to attach on non-begun session
}
else
{
SessionImpl session = transportSession.getSession();
final UnsignedInteger handle = attach.getHandle();
if (handle.compareTo(transportSession.getHandleMax()) > 0) {
// The handle-max value is the highest handle value that can be used on the session. A peer MUST
// NOT attempt to attach a link using a handle value outside the range that its partner can handle.
// A peer that receives a handle outside the supported range MUST close the connection with the
// framing-error error-code.
ErrorCondition condition =
new ErrorCondition(ConnectionError.FRAMING_ERROR,
"handle-max exceeded");
_connectionEndpoint.setCondition(condition);
_connectionEndpoint.setLocalState(EndpointState.CLOSED);
if (!_isCloseSent) {
Close close = new Close();
close.setError(condition);
_isCloseSent = true;
writeFrame(0, close, null, null);
}
close_tail();
return;
}
TransportLink<?> transportLink = transportSession.getLinkFromRemoteHandle(handle);
LinkImpl link = null;
if(transportLink != null)
{
// TODO - fail - attempt attach on a handle which is in use
}
else
{
transportLink = transportSession.resolveHalfOpenLink(attach.getName());
if(transportLink == null)
{
link = (attach.getRole() == Role.RECEIVER)
? session.sender(attach.getName())
: session.receiver(attach.getName());
transportLink = getTransportState(link);
}
else
{
link = transportLink.getLink();
}
if(attach.getRole() == Role.SENDER)
{
transportLink.setDeliveryCount(attach.getInitialDeliveryCount());
}
link.setRemoteState(EndpointState.ACTIVE);
link.setRemoteSource(attach.getSource());
link.setRemoteTarget(attach.getTarget());
link.setRemoteReceiverSettleMode(attach.getRcvSettleMode());
link.setRemoteSenderSettleMode(attach.getSndSettleMode());
link.setRemoteProperties(attach.getProperties());
link.setRemoteDesiredCapabilities(attach.getDesiredCapabilities());
link.setRemoteOfferedCapabilities(attach.getOfferedCapabilities());
link.setRemoteMaxMessageSize(attach.getMaxMessageSize());
transportLink.setName(attach.getName());
transportLink.setRemoteHandle(handle);
transportSession.addLinkRemoteHandle(transportLink, handle);
}
_connectionEndpoint.put(Event.Type.LINK_REMOTE_OPEN, link);
}
}
示例4
@Test
public void testErrorConditionAfterTransportClosed() {
Symbol condition = Symbol.getSymbol("some-error");
String description = "some-error-description";
ErrorCondition origErrorCondition = new ErrorCondition();
origErrorCondition.setCondition(condition);
origErrorCondition.setDescription(description);
assertNotNull("Expected a Condition", origErrorCondition.getCondition());
// Set an error condition, then call 'closed' specifying an error.
// Expect the original condition which was set to remain.
TransportImpl transport = new TransportImpl();
transport.setCondition(origErrorCondition);
transport.closed(new TransportException("my-ignored-exception"));
assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
assertEquals("Unexpected ErrorCondition returned", origErrorCondition, transport.getCondition());
// ---------------------------------------------------------------- //
// Set an error condition, then call 'closed' without an error.
// Expect the original condition which was set to remain.
transport = new TransportImpl();
transport.setCondition(origErrorCondition);
transport.closed(null);
assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
assertEquals("Unexpected ErrorCondition returned", origErrorCondition, transport.getCondition());
// ---------------------------------------------------------------- //
// Without having set an error condition, call 'closed' specifying an error.
// Expect a condition to be set.
transport = new TransportImpl();
transport.closed(new TransportException(description));
assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
assertEquals("Unexpected condition returned", ConnectionError.FRAMING_ERROR, transport.getCondition().getCondition());
assertEquals("Unexpected description returned", "org.apache.qpid.proton.engine.TransportException: " + description, transport.getCondition().getDescription());
// ---------------------------------------------------------------- //
// Without having set an error condition, call 'closed' without an error.
// Expect a condition to be set.
transport = new TransportImpl();
transport.closed(null);
assertNotNull("Expected an ErrorCondition to be returned", transport.getCondition());
assertEquals("Unexpected ErrorCondition returned", ConnectionError.FRAMING_ERROR, transport.getCondition().getCondition());
assertEquals("Unexpected description returned", "connection aborted", transport.getCondition().getDescription());
}