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(); }
/** * 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(); }
final ProtonConnection connectionToClose = connection; connectionToClose.closeHandler(closedCon -> { if (closedCon.succeeded()) { log.info("closed connection to server [{}:{}]", connectionFactory.getHost(),
conn.closeHandler(result -> { if (result.failed()) { conn.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()); } }); }
Optional.ofNullable(getConnectionLossHandler(con)).ifPresent(handler -> handler.handle(null)); }); con.closeHandler(remoteClose -> { handleRemoteConnectionClose(con, remoteClose); Optional.ofNullable(getConnectionLossHandler(con)).ifPresent(handler -> handler.handle(null));
clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort()); downstreamConnection.disconnectHandler(disconnectHandler); downstreamConnection.closeHandler(closeHandler); connectionResultHandler.handle(Future.succeededFuture(downstreamConnection)); } else {
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)); }
private void setRemoteConnectionOpenHandler(final ProtonConnection connection) { connection.sessionOpenHandler(remoteOpenSession -> handleSessionOpen(connection, remoteOpenSession)); connection.receiverOpenHandler(remoteOpenReceiver -> handleReceiverOpen(connection, remoteOpenReceiver)); connection.senderOpenHandler(remoteOpenSender -> handleSenderOpen(connection, remoteOpenSender)); connection.disconnectHandler(this::handleRemoteDisconnect); connection.closeHandler(remoteClose -> handleRemoteConnectionClose(connection, remoteClose)); connection.openHandler(remoteOpen -> { LOG.info("client [container: {}, user: {}] connected", connection.getRemoteContainer(), getUserFromConnection(connection)); connection.open(); // attach an ID so that we can later inform downstream components when connection is closed connection.attachments().set(Constants.KEY_CONNECTION_ID, String.class, UUID.randomUUID().toString()); }); }
}).closeHandler(conn -> { LOG.info("Received close - disconnecting"); connection.close();
}); connection.disconnectHandler(this::handleRemoteDisconnect); connection.closeHandler(remoteClose -> handleRemoteConnectionClose(connection, remoteClose)); connection.openHandler(remoteOpen -> { if (remoteOpen.failed()) {
}); connection.disconnectHandler(this::handleRemoteDisconnect); connection.closeHandler(remoteClose -> handleRemoteConnectionClose(connection, remoteClose)); connection.openHandler(remoteOpen -> { if (remoteOpen.failed()) {
/** * 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); } } }
/** * 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); } } }
/** * Process a connection request accepted by the Proton server or * open the connection if it's working as client * * @param connection Proton connection accepted instance */ private void processConnection(ProtonConnection connection) { connection .openHandler(this::processOpenConnection) .closeHandler(this::processCloseConnection) .disconnectHandler(this::processDisconnection) .sessionOpenHandler(this::processOpenSession) .receiverOpenHandler(receiver -> { this.processOpenReceiver(connection, receiver); }) .senderOpenHandler(sender -> { this.processOpenSender(connection, sender); }); if (this.bridgeConfigProperties.getEndpointConfigProperties().getMode() == AmqpMode.CLIENT) { connection.open(); } }
LOG.trace("Server connection open"); serverConnection.closeHandler(x -> { serverConnection.close(); });
Async asyncShutdown = context.async(); MockServer server = new MockServer(vertx, serverConnection -> { serverConnection.closeHandler(x -> { serverConnection.close(); });
serverConnection.open(); }); serverConnection.closeHandler(x -> { serverConnection.close(); });
serverConnection.closeHandler(x -> { serverConnection.close(); });
LOG.trace("Server connection open"); serverConnection.closeHandler(x -> { serverConnection.close(); });