Java Code Examples for io.vertx.proton.ProtonConnection#openHandler()
The following examples show how to use
io.vertx.proton.ProtonConnection#openHandler() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleAuthenticationServer.java From hono with Eclipse Public License 2.0 | 6 votes |
@Override protected void setRemoteConnectionOpenHandler(final ProtonConnection connection) { connection.sessionOpenHandler(remoteOpenSession -> handleSessionOpen(connection, remoteOpenSession)); connection.senderOpenHandler(remoteOpenSender -> handleSenderOpen(connection, remoteOpenSender)); // no receiverOpenHandler set here 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()); } }); }
Example 2
Source File: AmqpAdapterTestBase.java From hono with Eclipse Public License 2.0 | 6 votes |
private Future<ProtonConnection> handleConnectAttempt(final ProtonConnection unopenedConnection) { final Promise<ProtonConnection> result = Promise.promise(); unopenedConnection.openHandler(result); unopenedConnection.closeHandler(remoteClose -> { unopenedConnection.close(); }); unopenedConnection.open(); return result.future() .map(con -> { assertThat(unopenedConnection.getRemoteOfferedCapabilities()).contains(Constants.CAP_ANONYMOUS_RELAY); this.context = Vertx.currentContext(); this.connection = unopenedConnection; return con; }) .recover(t -> { return Optional.ofNullable(unopenedConnection.getRemoteCondition()) .map(condition -> Future.<ProtonConnection>failedFuture(StatusCodeMapper.from(condition))) .orElse(Future.failedFuture(t)); }); }
Example 3
Source File: AmqpServiceBase.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Sets default handlers on a connection that has been opened * by a peer. * <p> * This method registers the following handlers * <ul> * <li>sessionOpenHandler - {@link #handleSessionOpen(ProtonConnection, ProtonSession)}</li> * <li>receiverOpenHandler - {@link #handleReceiverOpen(ProtonConnection, ProtonReceiver)}</li> * <li>senderOpenHandler - {@link #handleSenderOpen(ProtonConnection, ProtonSender)}</li> * <li>disconnectHandler - {@link #handleRemoteDisconnect(ProtonConnection)}</li> * <li>closeHandler - {@link #handleRemoteConnectionClose(ProtonConnection, AsyncResult)}</li> * <li>openHandler - {@link #processRemoteOpen(ProtonConnection)}</li> * </ul> * <p> * Subclasses should override this method in order to register service * specific handlers and/or to prevent registration of default handlers. * * @param connection The connection. */ protected void setRemoteConnectionOpenHandler(final ProtonConnection connection) { log.debug("received connection request from client"); connection.sessionOpenHandler(session -> { HonoProtonHelper.setDefaultCloseHandler(session); handleSessionOpen(connection, session); }); connection.receiverOpenHandler(receiver -> { HonoProtonHelper.setDefaultCloseHandler(receiver); handleReceiverOpen(connection, receiver); }); connection.senderOpenHandler(sender -> { HonoProtonHelper.setDefaultCloseHandler(sender); handleSenderOpen(connection, sender); }); connection.disconnectHandler(this::handleRemoteDisconnect); connection.closeHandler(remoteClose -> handleRemoteConnectionClose(connection, remoteClose)); connection.openHandler(remoteOpen -> { if (remoteOpen.failed()) { log.debug("ignoring peer's open frame containing error", remoteOpen.cause()); } else { processRemoteOpen(remoteOpen.result()); } }); }
Example 4
Source File: VertxBasedAmqpProtocolAdapter.java From hono with Eclipse Public License 2.0 | 4 votes |
/** * Handles a remote peer's request to open a connection. * * @param con The connection to be opened. */ protected void onConnectRequest(final ProtonConnection con) { con.disconnectHandler(lostConnection -> { log.debug("lost connection to device [container: {}]", con.getRemoteContainer()); onConnectionLoss(con); decrementConnectionCount(con); }); con.closeHandler(remoteClose -> { handleRemoteConnectionClose(con, remoteClose); onConnectionLoss(con); decrementConnectionCount(con); }); // when a begin frame is received con.sessionOpenHandler(session -> { HonoProtonHelper.setDefaultCloseHandler(session); handleSessionOpen(con, session); }); // when the device wants to open a link for // uploading messages con.receiverOpenHandler(receiver -> { HonoProtonHelper.setDefaultCloseHandler(receiver); receiver.setMaxMessageSize(UnsignedLong.valueOf(getConfig().getMaxPayloadSize())); handleRemoteReceiverOpen(con, receiver); }); // when the device wants to open a link for // receiving commands con.senderOpenHandler(sender -> { handleRemoteSenderOpenForCommands(con, sender); }); con.openHandler(remoteOpen -> { final Device authenticatedDevice = getAuthenticatedDevice(con); if (authenticatedDevice == null) { metrics.incrementUnauthenticatedConnections(); } else { metrics.incrementConnections(authenticatedDevice.getTenantId()); } if (remoteOpen.failed()) { log.debug("ignoring device's open frame containing error", remoteOpen.cause()); } else { processRemoteOpen(remoteOpen.result()); } }); }