当前位置: 首页>>代码示例>>Java>>正文


Java ProtonSender.setCondition方法代码示例

本文整理汇总了Java中io.vertx.proton.ProtonSender.setCondition方法的典型用法代码示例。如果您正苦于以下问题:Java ProtonSender.setCondition方法的具体用法?Java ProtonSender.setCondition怎么用?Java ProtonSender.setCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.proton.ProtonSender的用法示例。


在下文中一共展示了ProtonSender.setCondition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleSenderOpen

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
/**
 * Handles a request from a client to establish a link for receiving messages from this server.
 *
 * @param con the connection to the client.
 * @param sender the sender created for the link.
 */
protected void handleSenderOpen(final ProtonConnection con, final ProtonSender sender) {
    final Source remoteSource = sender.getRemoteSource();
    LOG.debug("client [container: {}] wants to open a link [address: {}] for receiving messages",
            con.getRemoteContainer(), remoteSource);
    try {
        final ResourceIdentifier targetResource = getResourceIdentifier(remoteSource.getAddress());
        final AmqpEndpoint endpoint = getEndpoint(targetResource);
        if (endpoint == null) {
            handleUnknownEndpoint(con, sender, targetResource);
        } else {
            final HonoUser user = Constants.getClientPrincipal(con);
            getAuthorizationService().isAuthorized(user, targetResource, Activity.READ).setHandler(authAttempt -> {
                if (authAttempt.succeeded() && authAttempt.result()) {
                    Constants.copyProperties(con, sender);
                    sender.setSource(sender.getRemoteSource());
                    endpoint.onLinkAttach(con, sender, targetResource);
                } else {
                    LOG.debug("subject [{}] is not authorized to READ from [{}]", user.getName(), targetResource);
                    sender.setCondition(ProtonHelper.condition(AmqpError.UNAUTHORIZED_ACCESS.toString(), "unauthorized"));
                    sender.close();
                }
            });
        }
    } catch (final IllegalArgumentException e) {
        LOG.debug("client has provided invalid resource identifier as target address", e);
        sender.setCondition(ProtonHelper.condition(AmqpError.NOT_FOUND, "no such address"));
        sender.close();
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:36,代码来源:AmqpServiceBase.java

示例2: onLinkAttach

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
/**
 * Configure and check the sender link of the endpoint.
 * The sender link is used for the response to a received request and is driven by the vertx event bus.
 * It listens to the provided resource identifier of the endpoint as vertx event address and then sends the
 * constructed response.
 * Since the response is endpoint specific, it is an abstract method {@link #getAmqpReply(io.vertx.core.eventbus.Message)} and needs to be implemented
 * by the subclass.
 *
 * @param con The AMQP connection that the link is part of.
 * @param sender The ProtonSender that has already been created for this endpoint.
 * @param replyToAddress The resource identifier for the responses of this endpoint (see {@link ResourceIdentifier} for details).
 *                      Note that the reply address is different for each client and is passed in during link creation.
 */
@Override
public final void onLinkAttach(final ProtonConnection con, final ProtonSender sender, final ResourceIdentifier replyToAddress) {
    if (replyToAddress.getResourceId() == null) {
        logger.debug("client [{}] provided invalid reply-to address", sender.getName());
        sender.setCondition(ProtonHelper.condition(AmqpError.INVALID_FIELD,
                String.format("reply-to address must have the following format %s/<tenant>/<reply-address>", getName())));
        sender.close();
    } else {
        logger.debug("establishing sender link with client [{}]", sender.getName());
        final MessageConsumer<JsonObject> replyConsumer = vertx.eventBus().consumer(replyToAddress.toString(), message -> {
            // TODO check for correct session here...?
            logger.trace("forwarding reply to client [{}]: {}", sender.getName(), message.body());
            final Message amqpReply = getAmqpReply(message);
            sender.send(amqpReply);
        });

        sender.setQoS(ProtonQoS.AT_LEAST_ONCE);
        sender.closeHandler(senderClosed -> {
            logger.debug("client [{}] closed sender link, removing associated event bus consumer [{}]", sender.getName(), replyConsumer.address());
            replyConsumer.unregister();
            if (senderClosed.succeeded()) {
                senderClosed.result().close();
            }
        });
        sender.open();
    }
}
 
开发者ID:eclipse,项目名称:hono,代码行数:41,代码来源:RequestResponseEndpoint.java

示例3: onLinkAttach

import io.vertx.proton.ProtonSender; //导入方法依赖的package包/类
@Override
public void onLinkAttach(final ProtonConnection con, final ProtonSender sender, final ResourceIdentifier targetResource) {
    logger.info("Endpoint [{}] does not support data retrieval, closing link.", getName());
    sender.setCondition(ProtonHelper.condition(AmqpError.NOT_IMPLEMENTED, "resource cannot be read from"));
    sender.close();
}
 
开发者ID:eclipse,项目名称:hono,代码行数:7,代码来源:AbstractAmqpEndpoint.java


注:本文中的io.vertx.proton.ProtonSender.setCondition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。