Java Code Examples for io.vertx.proton.ProtonSender#closeHandler()
The following examples show how to use
io.vertx.proton.ProtonSender#closeHandler() .
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: AbstractSender.java From enmasse with Apache License 2.0 | 6 votes |
@Override public void connectionOpened(ProtonConnection connection) { ProtonSender sender = connection.createSender(linkOptions.getTarget().getAddress()); sender.setTarget(linkOptions.getTarget()); sender.setQoS(clientOptions.getQos()); sender.openHandler(result -> { if (result.succeeded()) { log.info("Sender link '" + sender.getTarget().getAddress() + "' opened, sending messages"); connectPromise.complete(null); sendMessages(connection, sender); } else { handleError(connection, sender.getRemoteCondition()); } }); sender.closeHandler(result -> handleError(connection, sender.getRemoteCondition())); sender.open(); }
Example 2
Source File: PubSubBroker.java From enmasse with Apache License 2.0 | 4 votes |
private void senderOpenHandler(ProtonConnection connection, ProtonSender sender) { Source source = (Source) sender.getRemoteSource(); sender.setSource(source); log.info("[{}]: Got subscription request from {} on {}", containerId, connection.getRemoteContainer(), source.getAddress()); Context senderContext = vertx.getOrCreateContext(); sender.closeHandler(handle -> { vertx.executeBlocking(promise -> { synchronized (this) { subscribers.remove(source.getAddress()); } promise.complete(); }, result -> { sender.close(); }); }); vertx.executeBlocking(promise -> { try { synchronized (this) { if (queues.get(source.getAddress()) == null || subscribers.get(source.getAddress()) != null) { senderContext.runOnContext(id -> sender.close()); } subscribers.put(source.getAddress(), new SenderInfo(sender, senderContext)); if (queues.get(source.getAddress()) != null) { checkQueue(senderContext, sender); } } promise.complete(); } catch (Exception e) { promise.fail(e); } }, result -> { if (result.succeeded()) { sender.open(); log.info("[{}]: Opened sender for subscriber {} for address {}", containerId, connection.getRemoteContainer(), sender.getRemoteSource().getAddress()); } else { sender.close(); log.info("[{}]: Failed creating subscriber {} for address {}", containerId, connection.getRemoteContainer(), sender.getRemoteSource().getAddress(), result.cause()); } }); }