private static void initConnection(Vertx vertx, ProtonConnection connection) { connection.openHandler(res -> { System.out.println("Client connection opened, container-id: " + connection.getRemoteContainer()); connection.open(); }); connection.closeHandler(c -> { System.out.println("Client closing connection, container-id: " + connection.getRemoteContainer()); connection.close(); connection.disconnect(); }); connection.disconnectHandler(c -> { System.out.println("Client socket disconnected, container-id: " + connection.getRemoteContainer()); connection.disconnect(); }); connection.sessionOpenHandler(session -> { session.closeHandler(x -> { session.close(); session.free(); }); session.open(); }); connection.senderOpenHandler(sender -> { initSender(vertx, connection, sender); }); connection.receiverOpenHandler(receiver -> { initReceiver(receiver); }); connection.open(); }
/** * Close the endpoint, closing the connection */ public void close() { // TODO : check what to close other than connection while this class evolves if (this.connection != null) { this.connection.close(); } } }
/** * Closes the connection with the downstream container. * * @param stopFuture Always succeeds. */ @Override public final void stop(final Future<Void> stopFuture) { if (running) { if (downstreamConnection != null && !downstreamConnection.isDisconnected()) { final String container = downstreamConnection.getRemoteContainer(); logger.info("closing connection to downstream container [{}]", container); downstreamConnection.closeHandler(null).disconnectHandler(null).close(); } else { logger.debug("downstream connection already closed"); } running = false; } stopFuture.complete(); }
/** * Close the endpoint, closing the connection */ public void close() { // TODO : check what to close other than connection while this class evolves if (this.connection != null) { this.connection.close(); } }
@Override protected void setRemoteConnectionOpenHandler(final ProtonConnection connection) { connection.sessionOpenHandler(remoteOpenSession -> handleSessionOpen(connection, remoteOpenSession)); connection.senderOpenHandler(remoteOpenSender -> handleSenderOpen(connection, remoteOpenSender)); connection.disconnectHandler(con -> { con.close(); con.disconnect(); }); connection.closeHandler(remoteClose -> { connection.close(); connection.disconnect(); }); connection.openHandler(remoteOpen -> { if (remoteOpen.failed()) { LOG.debug("ignoring peer's open frame containing error", remoteOpen.cause()); } else { processRemoteOpen(remoteOpen.result()); } }); }
@Override protected void connectionClosed(ProtonConnection conn) { conn.close(); resultPromise.completeExceptionally(new RuntimeException("Connection closed (" + messages.size() + " messages received")); connectPromise.completeExceptionally(new RuntimeException("Connection closed (" + messages.size() + " messages received")); }
private void connectHandler(ProtonConnection connection) { connection.setContainer(containerId); connection.openHandler(conn -> { log.info("[{}]: Connection opened", containerId); }).closeHandler(conn -> { connection.close(); connection.disconnect(); log.info("[{}]: Connection closed", containerId); }).disconnectHandler(protonConnection -> { connection.disconnect(); log.debug("Disconnected"); }).open(); connection.sessionOpenHandler(ProtonSession::open); connection.senderOpenHandler(sender -> senderOpenHandler(connection, sender)); connection.receiverOpenHandler(receiver -> receiverOpenHandler(connection, receiver)); }
@Override protected void connectionClosed(ProtonConnection conn) { conn.close(); resultPromise.completeExceptionally(new RuntimeException("Connection closed after " + numSent.get() + " messages sent")); connectPromise.completeExceptionally(new RuntimeException("Connection closed after " + numSent.get() + " messages sent")); }
/** * Closes an expired client connection. * <p> * A connection is considered expired if the {@link HonoUser#isExpired()} method * of the user principal attached to the connection returns {@code true}. * * @param con The client connection. */ protected final void closeExpiredConnection(final ProtonConnection con) { if (!con.isDisconnected()) { final HonoUser clientPrincipal = Constants.getClientPrincipal(con); if (clientPrincipal != null) { LOG.debug("client's [{}] access token has expired, closing connection", clientPrincipal.getName()); con.disconnectHandler(null); con.closeHandler(null); con.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS, "access token expired")); con.close(); con.disconnect(); publishConnectionClosedEvent(con); } } }
@Override protected void connectionDisconnected(ProtonConnection conn) { conn.close(); resultPromise.completeExceptionally(new RuntimeException("Connection disconnected after " + numSent.get() + " messages sent")); connectPromise.completeExceptionally(new RuntimeException("Connection disconnected after " + numSent.get() + " messages sent")); }
@Override protected void connectionDisconnected(ProtonConnection conn) { conn.close(); resultPromise.completeExceptionally(new RuntimeException("Connection disconnected (" + messages.size() + " messages received")); connectPromise.completeExceptionally(new RuntimeException("Connection disconnected (" + messages.size() + " messages received")); }
private void onRemoteClose(final AsyncResult<ProtonConnection> remoteClose) { logger.info("connection to downstream container [{}] is closed", downstreamConnection.getRemoteContainer()); downstreamConnection.close(); }
private void sendNext(ProtonConnection connection, ProtonSender sender, Queue<Message> messageQueue, CountDownLatch latch) { Message message = messageQueue.poll(); if (message == null) { connection.close(); latch.countDown(); } else { sender.send(message, protonDelivery -> sendNext(connection, sender, messageQueue, latch)); } }
/** * Invoked when a client closes the connection with this server. * * @param con The connection to close. * @param res The client's close frame. */ private void handleRemoteConnectionClose(final ProtonConnection con, final AsyncResult<ProtonConnection> res) { if (res.succeeded()) { LOG.info("client [{}] closed connection", con.getRemoteContainer()); } else { LOG.info("client [{}] closed connection with error", con.getRemoteContainer(), res.cause()); } con.close(); con.disconnect(); publishConnectionClosedEvent(con); }
private void onRemoteClose(final AsyncResult<ProtonConnection> remoteClose, final Handler<ProtonConnection> connectionLossHandler) { if (remoteClose.failed()) { log.info("remote server [{}:{}] closed connection with error condition: {}", connectionFactory.getHost(), connectionFactory.getPort(), remoteClose.cause().getMessage()); } else { log.info("remote server [{}:{}] closed connection", connectionFactory.getHost(), connectionFactory.getPort()); } connection.disconnectHandler(null); connection.close(); handleConnectionLoss(connectionLossHandler); }
/** * Invoked when a client closes the connection with this server. * <p> * This implementation closes and disconnects the connection. * * @param con The connection to close. * @param res The client's close frame. */ protected void handleRemoteConnectionClose(final ProtonConnection con, final AsyncResult<ProtonConnection> res) { if (res.succeeded()) { LOG.debug("client [container: {}] closed connection", con.getRemoteContainer()); } else { LOG.debug("client [container: {}] closed connection with error", con.getRemoteContainer(), res.cause()); } con.close(); con.disconnect(); publishConnectionClosedEvent(con); }
/** * Invoked when a client closes the connection with this server. * * @param con The connection to close. * @param res The client's close frame. */ private void handleRemoteConnectionClose(final ProtonConnection con, final AsyncResult<ProtonConnection> res) { if (res.succeeded()) { LOG.debug("client [container: {}] closed connection", con.getRemoteContainer()); } else { LOG.debug("client [container: {}] closed connection with error", con.getRemoteContainer(), res.cause()); } con.disconnectHandler(null); con.close(); con.disconnect(); }
/** * Invoked when a client closes the connection with this server. * <p> * This implementation closes and disconnects the connection. * * @param con The connection to close. * @param res The client's close frame. */ protected void handleRemoteConnectionClose(final ProtonConnection con, final AsyncResult<ProtonConnection> res) { if (res.succeeded()) { LOG.debug("client [container: {}] closed connection", con.getRemoteContainer()); } else { LOG.debug("client [container: {}] closed connection with error", con.getRemoteContainer(), res.cause()); } con.close(); con.disconnect(); publishConnectionClosedEvent(con); }
protected void handleError(ProtonConnection connection, ErrorCondition error) { if (error == null || error.getCondition() == null) { log.info("{}: link closed without error", containerId); } else { log.info("{}: link closed with error {}", containerId, error); connection.close(); if (unauthorizedAccess.equals(error.getCondition()) || error.getDescription().contains("not authorized")) { resultPromise.completeExceptionally(new UnauthorizedAccessException(error.getDescription())); connectPromise.completeExceptionally(new UnauthorizedAccessException(error.getDescription())); } else { resultPromise.completeExceptionally(new RuntimeException(error.getDescription())); connectPromise.completeExceptionally(new RuntimeException(error.getDescription())); } } } }
/** * Close a connection endpoint and before that all the related sink/source endpoints * * @param connection connection for which closing related endpoint */ private void closeConnectionEndpoint(ProtonConnection connection) { // closing connection, but before closing all sink/source endpoints if (this.endpoints.containsKey(connection)) { ConnectionEndpoint endpoint = this.endpoints.get(connection); if (endpoint.getSource() != null) { endpoint.getSource().close(); } if (!endpoint.getSinks().isEmpty()) { endpoint.getSinks().stream().forEach(sink -> sink.close()); } connection.close(); this.endpoints.remove(connection); } }