if (connection.isDisconnected()) { vertx.cancelTimer(t); } else {
/** * Checks if this client is currently connected to the server. * <p> * Note that the result returned by this method is only meaningful * if running on the vert.x event loop context that this client has been * created on. * * @return {@code true} if the connection is established. */ protected boolean isConnectedInternal() { return connection != null && !connection.isDisconnected(); }
@Override public void createSender( final ProtonConnection connection, final String address, final ProtonQoS qos, final Handler<ProtonSender> sendQueueDrainHandler, final Future<ProtonSender> result) { Objects.requireNonNull(connection); Objects.requireNonNull(address); Objects.requireNonNull(result); if (connection.isDisconnected()) { result.fail("connection is disconnected"); } else { newSession(connection, remoteOpen -> { if (remoteOpen.succeeded()) { newSender(connection, remoteOpen.result(), address, qos, sendQueueDrainHandler, result); } else { result.fail(remoteOpen.cause()); } }); } }
/** * 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(); }
private void createSender( final String targetAddress, final Handler<ProtonSender> sendQueueDrainHandler, final Handler<AsyncResult<ProtonSender>> handler) { Future<ProtonSender> result = Future.future(); result.setHandler(handler); if (downstreamConnection == null || downstreamConnection.isDisconnected()) { result.fail("downstream connection must be opened before creating sender"); } else { String tenantOnlyTargetAddress = getTenantOnlyTargetAddress(targetAddress); String address = tenantOnlyTargetAddress.replace(Constants.DEFAULT_PATH_SEPARATOR, honoConfig.getPathSeparator()); senderFactory.createSender(downstreamConnection, address, getDownstreamQos(), sendQueueDrainHandler, result); } }
/** * Processes the AMQP <em>open</em> frame received from a peer. * <p> * Checks if the open frame contains a desired <em>ADDRESS_AUTHZ</em> capability and if so, * adds the authenticated clients' authorities to the properties of the open frame sent * to the peer in response. * * @param connection The connection opened by the peer. */ @Override protected void processRemoteOpen(final ProtonConnection connection) { final boolean isAddressAuthz = Arrays.stream(connection.getRemoteDesiredCapabilities()) .anyMatch(symbol -> symbol.equals(CAPABILITY_ADDRESS_AUTHZ)); if (isAddressAuthz) { LOG.debug("client [container: {}] requests transfer of authenticated user's authorities in open frame", connection.getRemoteContainer()); processAddressAuthzCapability(connection); } connection.open(); vertx.setTimer(5000, closeCon -> { if (!connection.isDisconnected()) { LOG.debug("connection with client [{}] timed out after 5 seconds, closing connection", connection.getRemoteContainer()); connection.setCondition(ProtonHelper.condition(Constants.AMQP_ERROR_INACTIVITY, "client must retrieve token within 5 secs after opening connection")).close(); } }); }
vertx.setTimer(10000, l -> { connectionContext.runOnContext(x -> { if(!connection.isDisconnected()) { LOG.info("Closing connection which has not disconnected after 10s" + userData); connection.disconnect();
/** * 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); } } }