• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java InterceptHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.moquette.interception.InterceptHandler的典型用法代码示例。如果您正苦于以下问题:Java InterceptHandler类的具体用法?Java InterceptHandler怎么用?Java InterceptHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InterceptHandler类属于io.moquette.interception包,在下文中一共展示了InterceptHandler类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: start

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
/**
 * start simple mqtt server
 * @throws IOException throw at {@link io.moquette.server.netty.NettyAcceptor}
 */
public void start() {
    List<InterceptHandler> interceptHandlers = Collections.emptyList();

    boolean isVerbose = config.getConfiguration().getBoolean("verbose", false);
    if (isVerbose) {
        interceptHandlers = new ArrayList<>();
        interceptHandlers.add(new LogInterceptHandler());
    }

    try {
        mqttBroker.startServer(config, interceptHandlers);
    } catch (IOException e) {
        logger.error("Start mqtt broker.", e);
    }
    System.out.println("MQTT Broker started.");
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            logger.info("Stopping broker");
            mqttBroker.stopServer();
            logger.info("Broker stopped");
        }
    });
}
 
开发者ID:iot-labs,项目名称:communication,代码行数:29,代码来源:SimpleMqttBroker.java


示例2: notifyTopicPublished

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyTopicPublished(final MqttPublishMessage msg, final String clientID, final String username) {
    msg.retain();

    executor.execute(() -> {
            try {
                int messageId = msg.variableHeader().messageId();
                String topic = msg.variableHeader().topicName();
                for (InterceptHandler handler : handlers.get(InterceptPublishMessage.class)) {
                    LOG.debug("Notifying MQTT PUBLISH message to interceptor. CId={}, messageId={}, topic={}, "
                            + "interceptorId={}", clientID, messageId, topic, handler.getID());
                    handler.onPublish(new InterceptPublishMessage(msg, clientID, username));
                }
            } finally {
                ReferenceCountUtil.release(msg);
            }
    });
}
 
开发者ID:andsel,项目名称:moquette,代码行数:19,代码来源:BrokerInterceptor.java


示例3: testAddAndRemoveInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Test
public void testAddAndRemoveInterceptHandler() throws Exception {
    InterceptHandler interceptHandlerMock1 = mock(InterceptHandler.class);
    InterceptHandler interceptHandlerMock2 = mock(InterceptHandler.class);
    // add
    interceptor.addInterceptHandler(interceptHandlerMock1);
    interceptor.addInterceptHandler(interceptHandlerMock2);

    Subscription subscription = new Subscription("cli1", new Topic("o2"), MqttQoS.AT_MOST_ONCE);
    interceptor.notifyTopicSubscribed(subscription, "cli1234");
    interval();

    verify(interceptHandlerMock1).onSubscribe(refEq(new InterceptSubscribeMessage(subscription, "cli1234")));
    verify(interceptHandlerMock2).onSubscribe(refEq(new InterceptSubscribeMessage(subscription, "cli1234")));

    // remove
    interceptor.removeInterceptHandler(interceptHandlerMock1);

    interceptor.notifyTopicSubscribed(subscription, "cli1235");
    interval();
    // removeInterceptHandler() performs another interaction
    // TODO: fix this
    // verifyNoMoreInteractions(interceptHandlerMock1);
    verify(interceptHandlerMock2).onSubscribe(refEq(new InterceptSubscribeMessage(subscription, "cli1235")));
}
 
开发者ID:andsel,项目名称:moquette,代码行数:26,代码来源:BrokerInterceptorTest.java


示例4: main

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
public static void main(String[] args) throws InterruptedException, IOException {
        IResourceLoader classpathLoader = new ClasspathResourceLoader();
        final IConfig classPathConfig = new ResourceLoaderConfig(classpathLoader);

        final Server mqttBroker = new Server();
        List<? extends InterceptHandler> userHandlers = Collections.singletonList(new PublisherListener());
        mqttBroker.startServer(classPathConfig, userHandlers);

        System.out.println("Broker started press [CTRL+C] to stop");
        //Bind  a shutdown hook
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("Stopping broker");
            mqttBroker.stopServer();
            System.out.println("Broker stopped");
        }));

        Thread.sleep(20000);
        System.out.println("Before self publish");
        MqttPublishMessage message = MqttMessageBuilders.publish()
            .topicName("/exit")
            .retained(true)
//        qos(MqttQoS.AT_MOST_ONCE);
//        qQos(MqttQoS.AT_LEAST_ONCE);
            .qos(MqttQoS.EXACTLY_ONCE)
            .payload(Unpooled.copiedBuffer("Hello World!!".getBytes()))
            .build();

        mqttBroker.internalPublish(message, "INTRLPUB");
        System.out.println("After self publish");
    }
 
开发者ID:andsel,项目名称:moquette,代码行数:31,代码来源:EmbeddedLauncher.java


示例5: getInterceptorIds

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
public static <T extends InterceptHandler> Collection<String> getInterceptorIds(Collection<T> handlers) {
    Collection<String> result = new ArrayList<>(handlers.size());
    for (T handler : handlers) {
        result.add(handler.getID());
    }
    return result;
}
 
开发者ID:andsel,项目名称:moquette,代码行数:8,代码来源:LoggingUtils.java


示例6: BrokerInterceptor

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
private BrokerInterceptor(int poolSize, List<InterceptHandler> handlers) {
    LOG.info("Initializing broker interceptor. InterceptorIds={}", getInterceptorIds(handlers));
    this.handlers = new HashMap<>();
    for (Class<?> messageType : InterceptHandler.ALL_MESSAGE_TYPES) {
        this.handlers.put(messageType, new CopyOnWriteArrayList<InterceptHandler>());
    }
    for (InterceptHandler handler : handlers) {
        this.addInterceptHandler(handler);
    }
    executor = Executors.newFixedThreadPool(poolSize);
}
 
开发者ID:andsel,项目名称:moquette,代码行数:12,代码来源:BrokerInterceptor.java


示例7: notifyClientConnected

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyClientConnected(final MqttConnectMessage msg) {
    for (final InterceptHandler handler : this.handlers.get(InterceptConnectMessage.class)) {
        LOG.debug("Sending MQTT CONNECT message to interceptor. CId={}, interceptorId={}",
                msg.payload().clientIdentifier(), handler.getID());
        executor.execute(() -> handler.onConnect(new InterceptConnectMessage(msg)));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例8: notifyClientDisconnected

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyClientDisconnected(final String clientID, final String username) {
    for (final InterceptHandler handler : this.handlers.get(InterceptDisconnectMessage.class)) {
        LOG.debug("Notifying MQTT client disconnection to interceptor. CId={}, username={}, interceptorId={}",
            clientID, username, handler.getID());
        executor.execute(() -> handler.onDisconnect(new InterceptDisconnectMessage(clientID, username)));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例9: notifyClientConnectionLost

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyClientConnectionLost(final String clientID, final String username) {
    for (final InterceptHandler handler : this.handlers.get(InterceptConnectionLostMessage.class)) {
        LOG.debug("Notifying unexpected MQTT client disconnection to interceptor CId={}, username={}, " +
            "interceptorId={}", clientID, username, handler.getID());
        executor.execute(() -> handler.onConnectionLost(new InterceptConnectionLostMessage(clientID, username)));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例10: notifyTopicSubscribed

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyTopicSubscribed(final Subscription sub, final String username) {
    for (final InterceptHandler handler : this.handlers.get(InterceptSubscribeMessage.class)) {
        LOG.debug("Notifying MQTT SUBSCRIBE message to interceptor. CId={}, topicFilter={}, interceptorId={}",
            sub.getClientId(), sub.getTopicFilter(), handler.getID());
        executor.execute(() -> handler.onSubscribe(new InterceptSubscribeMessage(sub, username)));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例11: notifyTopicUnsubscribed

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyTopicUnsubscribed(final String topic, final String clientID, final String username) {
    for (final InterceptHandler handler : this.handlers.get(InterceptUnsubscribeMessage.class)) {
        LOG.debug("Notifying MQTT UNSUBSCRIBE message to interceptor. CId={}, topic={}, interceptorId={}", clientID,
            topic, handler.getID());
        executor.execute(() -> handler.onUnsubscribe(new InterceptUnsubscribeMessage(topic, clientID, username)));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例12: notifyMessageAcknowledged

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void notifyMessageAcknowledged(final InterceptAcknowledgedMessage msg) {
    for (final InterceptHandler handler : this.handlers.get(InterceptAcknowledgedMessage.class)) {
        LOG.debug("Notifying MQTT ACK message to interceptor. CId={}, messageId={}, topic={}, interceptorId={}",
            msg.getMsg().getClientID(), msg.getPacketID(), msg.getTopic(), handler.getID());
        executor.execute(() -> handler.onMessageAcknowledged(msg));
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:9,代码来源:BrokerInterceptor.java


示例13: addInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void addInterceptHandler(InterceptHandler interceptHandler) {
    Class<?>[] interceptedMessageTypes = getInterceptedMessageTypes(interceptHandler);
    LOG.info("Adding MQTT message interceptor. InterceptorId={}, handledMessageTypes={}",
        interceptHandler.getID(), interceptedMessageTypes);
    for (Class<?> interceptMessageType : interceptedMessageTypes) {
        this.handlers.get(interceptMessageType).add(interceptHandler);
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:10,代码来源:BrokerInterceptor.java


示例14: removeInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
@Override
public void removeInterceptHandler(InterceptHandler interceptHandler) {
    Class<?>[] interceptedMessageTypes = getInterceptedMessageTypes(interceptHandler);
    LOG.info("Removing MQTT message interceptor. InterceptorId={}, handledMessageTypes={}",
        interceptHandler.getID(), interceptedMessageTypes);
    for (Class<?> interceptMessageType : interceptedMessageTypes) {
        this.handlers.get(interceptMessageType).remove(interceptHandler);
    }
}
 
开发者ID:andsel,项目名称:moquette,代码行数:10,代码来源:BrokerInterceptor.java


示例15: getInterceptedMessageTypes

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
private static Class<?>[] getInterceptedMessageTypes(InterceptHandler interceptHandler) {
    Class<?>[] interceptedMessageTypes = interceptHandler.getInterceptedMessageTypes();
    if (interceptedMessageTypes == null) {
        return InterceptHandler.ALL_MESSAGE_TYPES;
    }
    return interceptedMessageTypes;
}
 
开发者ID:andsel,项目名称:moquette,代码行数:8,代码来源:BrokerInterceptor.java


示例16: startServer

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
public void startServer(IConfig config, List<? extends InterceptHandler> handlers, ISslContextCreator sslCtxCreator,
        IAuthenticator authenticator, IAuthorizator authorizator) throws IOException {
    if (handlers == null) {
        handlers = Collections.emptyList();
    }
    LOG.info("Starting Moquette Server. MQTT message interceptors={}", getInterceptorIds(handlers));

    scheduler = Executors.newScheduledThreadPool(1);

    final String handlerProp = System.getProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME);
    if (handlerProp != null) {
        config.setProperty(BrokerConstants.INTERCEPT_HANDLER_PROPERTY_NAME, handlerProp);
    }
    configureCluster(config);
    final String persistencePath = config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME);
    LOG.info("Configuring Using persistent store file, path={}", persistencePath);
    m_processorBootstrapper = new ProtocolProcessorBootstrapper();
    final ProtocolProcessor processor = m_processorBootstrapper.init(config, handlers, authenticator, authorizator,
        this);
    LOG.info("Initialized MQTT protocol processor");
    if (sslCtxCreator == null) {
        LOG.warn("Using default SSL context creator");
        sslCtxCreator = new DefaultMoquetteSslContextCreator(config);
    }

    LOG.info("Binding server to the configured ports");
    m_acceptor = new NettyAcceptor();
    m_acceptor.initialize(processor, config, sslCtxCreator);
    m_processor = processor;

    LOG.info("Moquette server has been initialized successfully");
    m_initialized = true;
}
 
开发者ID:andsel,项目名称:moquette,代码行数:34,代码来源:Server.java


示例17: addInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
/**
 * SPI method used by Broker embedded applications to add intercept handlers.
 *
 * @param interceptHandler
 *            the handler to add.
 */
public void addInterceptHandler(InterceptHandler interceptHandler) {
    if (!m_initialized) {
        LOG.error("Moquette is not started, MQTT message interceptor cannot be added. InterceptorId={}",
            interceptHandler.getID());
        throw new IllegalStateException("Can't register interceptors on a server that is not yet started");
    }
    LOG.info("Adding MQTT message interceptor. InterceptorId={}", interceptHandler.getID());
    m_processor.addInterceptHandler(interceptHandler);
}
 
开发者ID:andsel,项目名称:moquette,代码行数:16,代码来源:Server.java


示例18: removeInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
/**
 * SPI method used by Broker embedded applications to remove intercept handlers.
 *
 * @param interceptHandler
 *            the handler to remove.
 */
public void removeInterceptHandler(InterceptHandler interceptHandler) {
    if (!m_initialized) {
        LOG.error("Moquette is not started, MQTT message interceptor cannot be removed. InterceptorId={}",
            interceptHandler.getID());
        throw new IllegalStateException("Can't deregister interceptors from a server that is not yet started");
    }
    LOG.info("Removing MQTT message interceptor. InterceptorId={}", interceptHandler.getID());
    m_processor.removeInterceptHandler(interceptHandler);
}
 
开发者ID:andsel,项目名称:moquette,代码行数:16,代码来源:Server.java


示例19: addInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
public void addInterceptHandler(InterceptHandler interceptHandler) {
    this.m_interceptor.addInterceptHandler(interceptHandler);
}
 
开发者ID:andsel,项目名称:moquette,代码行数:4,代码来源:ProtocolProcessor.java


示例20: removeInterceptHandler

import io.moquette.interception.InterceptHandler; //导入依赖的package包/类
public void removeInterceptHandler(InterceptHandler interceptHandler) {
    this.m_interceptor.removeInterceptHandler(interceptHandler);
}
 
开发者ID:andsel,项目名称:moquette,代码行数:4,代码来源:ProtocolProcessor.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CacheEvictOperation类代码示例发布时间:2022-05-22
下一篇:
Java Organization类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap