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(); }
/** * Gets the name of the downstream AMQP 1.0 container this adapter is forwarding messages to. * * @return The name or {@code null} if this adapter is currently not connected. */ protected final String getDownstreamContainer() { if (downstreamConnection != null) { return downstreamConnection.getRemoteContainer(); } else { return null; } }
public String getRemoteContainer() { return connection.getRemoteContainer(); }
/** * Invoked when a client initiates a session (which is then opened in this method). * <p> * Subclasses should override this method if other behaviour shall be implemented on session open. * * @param con The connection of the session. * @param session The session that is initiated. */ protected void handleSessionOpen(final ProtonConnection con, final ProtonSession session) { LOG.debug("opening new session with client [container: {}]", con.getRemoteContainer()); session.open(); }
/** * Invoked when a client initiates a session (which is then opened in this method). * <p> * Subclasses should override this method if other behaviour shall be implemented on session open. * * @param con The connection of the session. * @param session The session that is initiated. */ protected void handleSessionOpen(final ProtonConnection con, final ProtonSession session) { LOG.debug("opening new session with client [container: {}]", con.getRemoteContainer()); session.open(); }
private void onRemoteClose(final AsyncResult<ProtonConnection> remoteClose) { logger.info("connection to downstream container [{}] is closed", downstreamConnection.getRemoteContainer()); downstreamConnection.close(); }
/** * Handler for connection closed by remote * * @param ar async result with info on related Proton connection */ private void processCloseConnection(AsyncResult<ProtonConnection> ar) { if (ar.succeeded()) { log.info("Connection closed by {} {}", ar.result().getRemoteHostname(), ar.result().getRemoteContainer()); this.closeConnectionEndpoint(ar.result()); } }
/** * 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. * * @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); }
/** * 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); }
/** * 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); }
private void handleRemoteDisconnect(final ProtonConnection connection) { LOG.info("client [{}] disconnected", connection.getRemoteContainer()); connection.disconnect(); publishConnectionClosedEvent(connection); }
/** * Handler for disconnection from the remote * * @param connection related Proton connection closed */ private void processDisconnection(ProtonConnection connection) { log.info("Disconnection from {} {}", connection.getRemoteHostname(), connection.getRemoteContainer()); this.closeConnectionEndpoint(connection); }
/** * Handler for connection opened by remote * * @param ar async result with info on related Proton connection */ private void processOpenConnection(AsyncResult<ProtonConnection> ar) { if (ar.succeeded()) { log.info("Connection opened by {} {}", ar.result().getRemoteHostname(), ar.result().getRemoteContainer()); ProtonConnection connection = ar.result(); connection.open(); // new connection, preparing for hosting related sink/source endpoints if (!this.endpoints.containsKey(connection)) { this.endpoints.put(connection, new ConnectionEndpoint()); } } }
private void handleSessionOpen(final ProtonConnection con, final ProtonSession session) { LOG.info("opening new session with client [{}]", con.getRemoteContainer()); session.closeHandler(sessionResult -> { if (sessionResult.succeeded()) { sessionResult.result().close(); } }).open(); }
/** * 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()); } }
private static void handleUnknownEndpoint(final ProtonConnection con, final ProtonLink<?> link, final ResourceIdentifier address) { LOG.info("client [{}] wants to establish link for unknown endpoint [address: {}]", con.getRemoteContainer(), address); link.setCondition( condition(AmqpError.NOT_FOUND.toString(), String.format("no endpoint registered for address %s", address))); link.close(); }
/** * This method is called when an AMQP BEGIN frame is received from a remote client. This method sets the incoming * capacity in its BEGIN Frame to be communicated to the remote peer * */ private void handleSessionOpen(final ProtonConnection conn, final ProtonSession session) { LOG.debug("opening new session with client [container: {}, session window size: {}]", conn.getRemoteContainer(), getConfig().getMaxSessionWindowSize()); session.setIncomingCapacity(getConfig().getMaxSessionWindowSize()); session.open(); }
private static ProtonConnection newConnection(final HonoUser user) { final Record attachments = new RecordImpl(); attachments.set(Constants.KEY_CONNECTION_ID, String.class, CON_ID); attachments.set(Constants.KEY_CLIENT_PRINCIPAL, HonoUser.class, user); final ProtonConnection con = mock(ProtonConnection.class); when(con.attachments()).thenReturn(attachments); when(con.getRemoteContainer()).thenReturn("test-client"); return con; }
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()); }); }