zoukankan      html  css  js  c++  java
  • 引入其他类定义的静态变量

    1. 引入方式

      import  static  类路径.*;

    2. 示例

    2.1 需要被导入的类

    package com.streamax.s17.mcs.business.message;import javax.annotation.Resource;
    import java.util.Date;
    import java.util.Map;
    
    /**
     * @Describe:
     * @Author: chenfan
     * @Date: 2019/4/29 13:26
     */
    @Slf4j
    @Component
    public class MqttMessageListener implements IMqttMessageListener {
    
        public static final String TRANSFER_BEGIN = "s17/media/handout/op_session_client_pull_begin";
        public static final String TRANSFER_END = "s17/media/handout/op_session_client_pull_end";
        public static final String TRANSFER_CONTROL = "s17/media/op_session_control";
    }

    2.2 需要导入的类

    package com.streamax.s17.mcs.business.message;
    
    import lombok.extern.slf4j.Slf4j;
    import org.eclipse.paho.client.mqttv3.MqttClient;
    import org.eclipse.paho.client.mqttv3.MqttException;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Component;
    
    import static com.streamax.s17.mcs.business.message.MqttMessageListener.*;
    
    /**
     * @Describe:
     * @Author: chenfan
     * @Date: 2019/4/26 15:17
     */
    @Slf4j
    @Component
    public class MessageHandler {
    
        private MqttMessageListener listener;
    
        private MqttClient mqttClient;
    
        public static final String filter = "/#";
    
        @Autowired
        public MessageHandler(MqttClient mqttClient,MqttMessageListener listener ) {
            this.mqttClient = mqttClient;
            this.listener = listener;
            init();
        }
    
        /**
         * 订阅关心事件
         */
        public void init(){
            try {
           // 导入后即可通过变量名直接使用,不需要通过类名引用变量 mqttClient.subscribe(TRANSFER_BEGIN
    + filter, 1, listener); mqttClient.subscribe(TRANSFER_END + filter, 1, listener); mqttClient.subscribe(TRANSFER_CONTROL + filter, 1, listener); log.info("subscribe topics success"); } catch (MqttException e) { log.error("subscribe topics occur a exception:{ }",e); } } }

  • 相关阅读:
    flink on yarn部分源码解析 (FLIP-6 new mode)
    flink on yarn部分源码解析
    flink window的early计算
    【flink training】 打车热点区域实时统计PopularPlaces
    troubshooting-sqoop 导出 TiDB表数据报com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
    Hive2.0常用函数(对编辑器很无语😓)
    Hive正则表达式
    troubleshooting-Container 'PHYSICAL' memory limit
    Hive-查询结果导入到 MySQL
    Hive-复制表
  • 原文地址:https://www.cnblogs.com/virgosnail/p/10826870.html
Copyright © 2011-2022 走看看