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


Java InterceptHandler类代码示例

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


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


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