use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.
the class ClientLinkType method handleEngineShutdown.
protected final void handleEngineShutdown(Engine engine) {
if (!isDynamic() && !session.getConnection().getEngine().isShutdown()) {
recreateLinkForReconnect();
open();
} else {
final Connection connection = engine.connection();
final ClientException failureCause;
if (connection.getRemoteCondition() != null) {
failureCause = ClientExceptionSupport.convertToConnectionClosedException(connection.getRemoteCondition());
} else if (engine.failureCause() != null) {
failureCause = ClientExceptionSupport.convertToConnectionClosedException(engine.failureCause());
} else if (!isClosed()) {
failureCause = new ClientConnectionRemotelyClosedException("Remote closed without a specific error condition");
} else {
failureCause = null;
}
immediateLinkShutdown(failureCause);
}
}
use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.
the class ClientLocalTransactionContext method handleTransactionDischargeFailed.
private void handleTransactionDischargeFailed(Transaction<TransactionController> transaction) {
ClientFuture<Session> future = transaction.getAttachments().get(DISCHARGE_FUTURE_NAME);
LOG.trace("Discharge of transaction:{} failed", transaction);
ClientException cause = ClientExceptionSupport.convertToNonFatalException(transaction.getCondition());
future.failed(new ClientTransactionRolledBackException(cause.getMessage(), cause));
}
use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.
the class ClientMessageSupport method convertFromOutsideMessage.
// ----- Internal Implementation
private static <E> ClientMessage<E> convertFromOutsideMessage(Message<E> source) throws ClientException {
Header header = new Header();
header.setDurable(source.durable());
header.setPriority(source.priority());
header.setTimeToLive(source.timeToLive());
header.setFirstAcquirer(source.firstAcquirer());
header.setDeliveryCount(source.deliveryCount());
Properties properties = new Properties();
properties.setMessageId(source.messageId());
properties.setUserId(source.userId() != null ? new Binary(source.userId()) : null);
properties.setTo(source.to());
properties.setSubject(source.subject());
properties.setReplyTo(source.replyTo());
properties.setCorrelationId(source.correlationId());
properties.setContentType(source.contentType());
properties.setContentEncoding(source.contentEncoding());
properties.setAbsoluteExpiryTime(source.absoluteExpiryTime());
properties.setCreationTime(source.creationTime());
properties.setGroupId(source.groupId());
properties.setGroupSequence(source.groupSequence());
properties.setReplyToGroupId(source.replyToGroupId());
final MessageAnnotations messageAnnotations;
if (source.hasAnnotations()) {
messageAnnotations = new MessageAnnotations(new LinkedHashMap<>());
source.forEachAnnotation((key, value) -> {
messageAnnotations.getValue().put(Symbol.valueOf(key), value);
});
} else {
messageAnnotations = null;
}
final ApplicationProperties applicationProperties;
if (source.hasProperties()) {
applicationProperties = new ApplicationProperties(new LinkedHashMap<>());
source.forEachProperty((key, value) -> {
applicationProperties.getValue().put(key, value);
});
} else {
applicationProperties = null;
}
final Footer footer;
if (source.hasFooters()) {
footer = new Footer(new LinkedHashMap<>());
source.forEachFooter((key, value) -> {
footer.getValue().put(Symbol.valueOf(key), value);
});
} else {
footer = null;
}
ClientMessage<E> message = new ClientMessage<>(createSectionFromValue(source.body()));
message.header(header);
message.properties(properties);
message.annotations(messageAnnotations);
message.applicationProperties(applicationProperties);
message.footer(footer);
return message;
}
use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.
the class ClientReceiver method drain.
@Override
public Future<Receiver> drain() throws ClientException {
checkClosedOrFailed();
final ClientFuture<Receiver> drainComplete = session.getFutureFactory().createFuture();
executor.execute(() -> {
if (notClosedOrFailed(drainComplete)) {
if (protonReceiver.isDraining()) {
drainComplete.failed(new ClientIllegalStateException("Receiver is already draining"));
return;
}
try {
if (protonReceiver.drain()) {
drainingFuture = drainComplete;
drainingTimeout = session.scheduleRequestTimeout(drainingFuture, options.drainTimeout(), () -> new ClientOperationTimedOutException("Timed out waiting for remote to respond to drain request"));
} else {
drainComplete.complete(this);
}
} catch (Exception ex) {
drainComplete.failed(ClientExceptionSupport.createNonFatalOrPassthrough(ex));
}
}
});
return drainComplete;
}
use of org.apache.qpid.protonj2.client.exceptions.ClientException in project qpid-protonj2 by apache.
the class ClientReceiver method tryReceive.
@Override
public Delivery tryReceive() throws ClientException {
checkClosedOrFailed();
Delivery delivery = messageQueue.dequeueNoWait();
if (delivery != null) {
if (options.autoAccept()) {
delivery.disposition(org.apache.qpid.protonj2.client.DeliveryState.accepted(), options.autoSettle());
} else {
asyncReplenishCreditIfNeeded();
}
} else {
checkClosedOrFailed();
}
return delivery;
}
Aggregations