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(); }
private void handleRemoteDisconnect(final ProtonConnection connection) { LOG.info("client [{}] disconnected", connection.getRemoteContainer()); connection.disconnect(); publishConnectionClosedEvent(connection); }
/** * 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 the client's transport connection is disconnected from this server. * * @param con The connection that was disconnected. */ protected void handleRemoteDisconnect(final ProtonConnection con) { LOG.debug("client [container: {}] disconnected", con.getRemoteContainer()); con.disconnect(); publishConnectionClosedEvent(con); }
/** * Handles unexpected disconnection from downstream container. * * @param con the failed connection */ private void onDisconnectFromDownstreamContainer(final ProtonConnection con) { // all links to downstream host will now be stale and unusable logger.warn("lost connection to downstream container [{}], closing upstream receivers ...", con.getRemoteContainer()); for (UpstreamReceiver client : activeSenders.keySet()) { client.close(ErrorConditions.ERROR_NO_DOWNSTREAM_CONSUMER); } sendersPerConnection.clear(); activeSenders.clear(); con.disconnectHandler(null); con.disconnect(); final ProtonClientOptions clientOptions = createClientOptions(); if (clientOptions.getReconnectAttempts() != 0) { vertx.setTimer(300, reconnect -> { logger.info("attempting to re-connect to downstream container"); connectToDownstream(clientOptions); }); } }
/** * Invoked when the client's transport connection is disconnected from this server. * * @param con The connection that was disconnected. */ protected void handleRemoteDisconnect(final ProtonConnection con) { LOG.debug("client [container: {}] disconnected", con.getRemoteContainer()); con.disconnect(); publishConnectionClosedEvent(con); }
@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()); } }); }
private void handleConnectionLoss(final Handler<ProtonConnection> connectionLossHandler) { if (isConnectedInternal()) { connection.disconnect(); } final ProtonConnection failedConnection = this.connection; clearState(); if (connectionLossHandler != null) { connectionLossHandler.handle(failedConnection); } else { reconnect(attempt -> {}, null); } }
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)); }
/** * Handler disconnection with remote AMQP container * * @param connection current ProtonConnection instance */ private void handleRemoteDisconnect(ProtonConnection connection) { LOG.info("AMQP disconnection with {}", connection.getRemoteContainer()); connection.disconnect(); try { this.mqttEndpoint.close(); } catch (IllegalStateException e) { LOG.warn("MQTT endpoint for client {} already closed", this.mqttEndpoint.clientIdentifier()); } }
connectionFactory.getPort(), closedCon.cause()); connectionToClose.disconnect(); }); connectionToClose.close();
/** * 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); }
/** * 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); } } }
/** * 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); }
/** * 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); } } }
/** * 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); }
if(!connection.isDisconnected()) { LOG.info("Closing connection which has not disconnected after 10s" + userData); connection.disconnect(); LOG.info("Received close - disconnecting"); connection.close(); connection.disconnect(); }).disconnectHandler(protonConnection -> { LOG.info("Disconnecting"); connection.disconnect(); });
conn.disconnect(); }).close(); }).open();
conn.disconnect(); }).close();
if (disconnect) { LOG.trace("Disconnecting server connection"); serverConnection.disconnect(); } else { LOG.trace("Closing server connection");