public void close(final OperationResult<Void, Exception> onGraceFullClose) { this.onGraceFullClose = onGraceFullClose; this.sendLink.close(); this.receiveLink.close(); }
/** * Close the links */ public synchronized void closeLinks() { if (this.receiverLink != null) { this.receiverLink.close(); } if (this.senderLink != null) { this.senderLink.close(); } }
@Override public void onEvent() { if (sendLink != null && sendLink.getLocalState() != EndpointState.CLOSED) { sendLink.close(); } else if (sendLink == null || sendLink.getRemoteState() == EndpointState.CLOSED) { if (closeTimer != null && !closeTimer.isCancelled()) { closeTimer.cancel(false); } linkClose.complete(null); } } });
@Override public void close(ErrorCondition condition) throws ActiveMQAMQPException { closed = true; if (condition != null) { sender.setCondition(condition); } protonSession.removeSender(sender); connection.runLater(() -> { sender.close(); try { sessionSPI.closeSender(brokerConsumer); } catch (Exception e) { log.warn(e.getMessage(), e); } sender.close(); connection.flush(); }); }
@Override public void close(boolean linkRemoteClose) throws ActiveMQAMQPException { closed = true; protonSession.removeSender(sender); synchronized (connection.getLock()) { sender.close(); } connection.flush(); }
@Override public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException { if (response.isException()) { Throwable exception = ((ExceptionResponse) response).getException(); exception.printStackTrace(); getEndpoint().close(); } else { delivery.settle(); } session.pumpProtonToSocket(); } });
@Override public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException { if (response.isException()) { Throwable exception = ((ExceptionResponse) response).getException(); exception.printStackTrace(); getEndpoint().close(); } else { delivery.settle(); } session.pumpProtonToSocket(); } });
@Override public void onError(Exception exception) { if(!this.openFuture.isDone()) { this.onOpenComplete(exception); } if(this.getIsClosingOrClosed()) { if(!this.closeFuture.isDone()) { TRACE_LOGGER.error("Closing internal receive link '{}' of requestresponselink to {} failed.", this.receiveLink.getName(), this.parent.linkPath, exception); AsyncUtil.completeFutureExceptionally(this.closeFuture, exception); } } else { TRACE_LOGGER.warn("Internal receive link '{}' of requestresponselink to '{}' encountered error.", this.receiveLink.getName(), this.parent.linkPath, exception); this.parent.underlyingFactory.deregisterForConnectionError(this.receiveLink); this.matchingSendLink.close(); this.parent.underlyingFactory.deregisterForConnectionError(this.matchingSendLink); this.parent.onInnerLinksClosed(this.linkGeneration, exception); } }
@Override public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException { if (response.isException()) { if (response.isException()) { Throwable exception = ((ExceptionResponse) response).getException(); exception.printStackTrace(); getEndpoint().close(); } } else { delivery.settle(); } session.pumpProtonToSocket(); } });
@Override public void onResponse(AmqpProtocolConverter converter, Response response) throws IOException { if (response.isException()) { if (response.isException()) { Throwable exception = ((ExceptionResponse) response).getException(); exception.printStackTrace(); getEndpoint().close(); } } else { delivery.settle(); } session.pumpProtonToSocket(); } });
@Override public void close(ErrorCondition condition) throws ActiveMQAMQPException { closed = true; if (condition != null) { sender.setCondition(condition); } protonSession.removeSender(sender); connection.lock(); try { sender.close(); } finally { connection.unlock(); } connection.flush(); try { sessionSPI.closeSender(brokerConsumer); } catch (Exception e) { log.warn(e.getMessage(), e); throw new ActiveMQAMQPInternalErrorException(e.getMessage()); } }
@Override public void onEvent() { if (InternalSender.this.sendLink != null && InternalSender.this.sendLink.getLocalState() != EndpointState.CLOSED) { TRACE_LOGGER.debug("Closing internal send link of requestresponselink to {}", RequestResponseLink.this.linkPath); InternalSender.this.sendLink.close(); InternalSender.this.parent.underlyingFactory.deregisterForConnectionError(InternalSender.this.sendLink); if(waitForCloseCompletion) { RequestResponseLink.scheduleLinkCloseTimeout(InternalSender.this.closeFuture, InternalSender.this.parent.underlyingFactory.getOperationTimeout(), InternalSender.this.sendLink.getName()); } else { AsyncUtil.completeFuture(InternalSender.this.closeFuture, null); } } } });
@Override public void remotelyClosed(AmqpConnection connection) { Exception txnError = AmqpSupport.convertToException(getEndpoint().getRemoteCondition()); // Alert any pending operation that the link failed to complete the pending // begin / commit / rollback operation. for (AsyncResult pendingRequest : pendingRequests.values()) { pendingRequest.onFailure(txnError); } // Purge linkages to pending operations. pendingDeliveries.clear(); pendingRequests.clear(); // Override the base class version because we do not want to propagate // an error up to the client if remote close happens as that is an // acceptable way for the remote to indicate the discharge could not // be applied. if (getEndpoint() != null) { getEndpoint().close(); getEndpoint().free(); } LOG.debug("Transaction Coordinator link {} was remotely closed", getEndpoint()); }
private void closeAsync() { // Codes_SRS_AMQPSIOTHUBCONNECTION_15_048 [If the AMQPS connection is already closed, the function shall do nothing.] // Codes_SRS_AMQPSIOTHUBCONNECTION_15_012: [The function shall set the status of the AMQPS connection to CLOSED.] this.state = State.CLOSED; // Codes_SRS_AMQPSIOTHUBCONNECTION_15_013: [The function shall close the AMQPS sender and receiver links, // the AMQPS session and the AMQPS connection.] if (this.sender != null) this.sender.close(); if (this.receiver != null) this.receiver.close(); if (this.session != null) this.session.close(); if (this.connection != null) this.connection.close(); // Codes_SRS_AMQPSIOTHUBCONNECTION_15_014: [The function shall stop the Proton reactor.] this.reactor.stop(); }
public void addSender(Sender sender) throws Exception { ProtonServerSenderContext protonSender = new ProtonServerSenderContext(connection, sender, this, sessionSPI); try { protonSender.initialise(); senders.put(sender, protonSender); serverSenders.put(protonSender.getBrokerConsumer(), protonSender); sender.setContext(protonSender); sender.open(); protonSender.start(); } catch (ActiveMQAMQPException e) { senders.remove(sender); sender.setSource(null); sender.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); sender.close(); } }
/** * Closes receiver and sender link if they are not null */ protected void closeLinks() { logger.LogDebug("Entered in method %s", logger.getMethodName()); // Codes_SRS_AMQPSDEVICEOPERATIONS_12_011: [If the sender link is not null the function shall close it and sets it to null.] if (this.senderLink != null) { this.senderLink.close(); this.senderLink = null; } // Codes_SRS_AMQPSDEVICEOPERATIONS_12_012: [If the receiver link is not null the function shall close it and sets it to null.] if (this.receiverLink != null) { this.receiverLink.close(); this.receiverLink = null; } this.amqpsSendLinkState = AmqpsDeviceOperationLinkState.CLOSED; this.amqpsRecvLinkState = AmqpsDeviceOperationLinkState.CLOSED; logger.LogDebug("Exited from method %s", logger.getMethodName()); }
public void addSender(Sender sender) throws Exception { // TODO: Remove this check when we have support for global link names boolean outgoing = (sender.getContext() != null && sender.getContext().equals(true)); ProtonServerSenderContext protonSender = outgoing ? new ProtonClientSenderContext(connection, sender, this, sessionSPI) : new ProtonServerSenderContext(connection, sender, this, sessionSPI); try { protonSender.initialise(); senders.put(sender, protonSender); serverSenders.put(protonSender.getBrokerConsumer(), protonSender); sender.setContext(protonSender); connection.runNow(() -> { sender.open(); connection.flush(); }); protonSender.start(); } catch (ActiveMQAMQPException e) { senders.remove(sender); sender.setSource(null); sender.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage())); connection.runNow(() -> { sender.close(); connection.flush(); }); } }
@Override public void onDelivery(Event event) { //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_023: [ The event handler shall get the Delivery from the event only if the event type is DELIVERY **]** if(event.getType() == Event.Type.DELIVERY) { // Codes_SRS_AMQPSIOTHUBCONNECTION_15_038: [If this link is the Sender link and the event type is DELIVERY, the event handler shall get the Delivery (Proton) object from the event.] Delivery d = event.getDelivery(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_024: [ The event handler shall get the Delivery remote state from the delivery **]** DeliveryState remoteState = d.getRemoteState(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_025: [ The event handler shall verify the Amqp response and add the response to a queue. **]** sendStatusQueue.add(new AmqpResponseVerification(remoteState)); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_026: [ The event handler shall settle the delivery. **]** d.settle(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_027: [ The event handler shall get the Sender (Proton) object from the event **]** Sender snd = event.getSender(); //Codes_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_25_028: [ The event handler shall close the Sender, Session and Connection **]** snd.close(); snd.getSession().close(); snd.getSession().getConnection().close(); isConnected = false; } }
@Override public void closeResource(AmqpProvider provider, Throwable cause, boolean localClose) { // Alert any pending operation that the link failed to complete the pending // begin / commit / rollback operation. Delivery pending = getEndpoint().head(); while (pending != null) { Delivery nextPending = pending.next(); if (pending.getContext() != null && pending.getContext() instanceof OperationContext) { OperationContext context = (OperationContext) pending.getContext(); context.request.onFailure(cause); } pending = nextPending; } // Override the base class version because we do not want to propagate // an error up to the client if remote close happens as that is an // acceptable way for the remote to indicate the discharge could not // be applied. if (getParent() != null) { getParent().removeChildResource(this); } if (getEndpoint() != null) { getEndpoint().close(); getEndpoint().free(); } LOG.debug("Transaction Coordinator link {} was remotely closed", getResourceInfo()); }
@Override public void closeResource(AmqpProvider provider, Throwable cause, boolean localClose) { // Alert any pending operation that the link failed to complete the pending // begin / commit / rollback operation. Delivery pending = getEndpoint().head(); while (pending != null) { Delivery nextPending = pending.next(); if (pending.getContext() != null && pending.getContext() instanceof OperationContext) { OperationContext context = (OperationContext) pending.getContext(); context.request.onFailure(cause); } pending = nextPending; } // Override the base class version because we do not want to propagate // an error up to the client if remote close happens as that is an // acceptable way for the remote to indicate the discharge could not // be applied. if (getParent() != null) { getParent().removeChildResource(this); } if (getEndpoint() != null) { getEndpoint().close(); getEndpoint().free(); } LOG.debug("Transaction Coordinator link {} was remotely closed", getResourceInfo()); }