當前位置: 首頁>>代碼示例>>Java>>正文


Java Tuple.getValue方法代碼示例

本文整理匯總了Java中backtype.storm.tuple.Tuple.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Tuple.getValue方法的具體用法?Java Tuple.getValue怎麽用?Java Tuple.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在backtype.storm.tuple.Tuple的用法示例。


在下文中一共展示了Tuple.getValue方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convert

import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void convert(Object from, BytesArray to) {
    Assert.isTrue(from == null || from instanceof Tuple,
            String.format("Unexpected object type, expecting [%s], given [%s]", Tuple.class, from.getClass()));

    // handle common cases
    Tuple tuple = (Tuple) from;

    if (tuple == null || tuple.size() == 0) {
        to.bytes("{}");
        return;
    }
    Assert.isTrue(tuple.size() == 1, "When using JSON input, only one field is expected");

    super.convert(tuple.getValue(0), to);
}
 
開發者ID:xushjie1987,項目名稱:es-hadoop-v2.2.0,代碼行數:17,代碼來源:StormTupleBytesConverter.java

示例2: execute

import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
@Override
public void execute(Tuple tuple, BasicOutputCollector basicOutputCollector) {
    String line = (String)tuple.getValue(0);
    if(!line.isEmpty()){
        String[] elements = line.split(",");
        // we are interested in speed and the car registration number
        int speed = Integer.valueOf((elements[1]).trim());
        String car = elements[0];
        if(speed > SPEED_THRESHOLD){
            TreeMap<String, Integer> carValue = new TreeMap<String, Integer>();
            carValue.put(car, speed);
            basicOutputCollector.emit(new Values(carValue));
            LOGGER.info("Speed violation found:"+ car + " speed:" + speed);
        }
    }
}
 
開發者ID:srecon,項目名稱:ignite-book-code-samples,代碼行數:17,代碼來源:SpeedLimitBolt.java

示例3: execute

import backtype.storm.tuple.Tuple; //導入方法依賴的package包/類
public void execute(Tuple tuple, BasicOutputCollector collector) {
        /* 這個初始化能不能放在prepare方法裏麵? */
        ru = new RedisUtil("127.0.0.1",6379,"password", 0);
        jedis = ru.getJedisInstance();
        String global_info = (String) tuple.getValue(0);
        String download_url= (String) tuple.getValue(1);
        /* delay_time需要從上一個得到 */
        int delay_time=2*1000;
        String workspace_id= get_workspace_id(global_info);
//        System.err.println("WID "+workspace_id);

        /* ------加入workspace的setting------ */
        if(!workspace_setting.containsKey(workspace_id)){
            workspace_setting.put(workspace_id,new ProxySetting(delay_time));
            /*-----IMPORTANT!!! 這裏記錄了使用代理的所有workspace------*/
            jedis.sadd("workspace_pool",workspace_id);
        }
        ProxySetting current_workspace_setting=workspace_setting.get(workspace_id);
//        System.err.println(current_workspace_setting==null);
        /* ----更新當前workspace的IP pool---- */
        Long last_update_time = current_workspace_setting.get_last_update_time();
        /* 暫且設置成10秒更新一次
         * 也可以強製每次都更新
         * */
        if(System.currentTimeMillis()-last_update_time>1000*10){
            refresh_workspace_proxy_pool(workspace_id);
            current_workspace_setting.set_last_update_time(System.currentTimeMillis());
        }

        String proxy=null;
        do{
            /* ----------更新黑白名單------------ */
            Set<String> black_set = jedis.smembers(workspace_id+"_black_set");
            Iterator<String> it=black_set.iterator();
            while (it.hasNext()){
                String tmp_ele=it.next();
                String[] tmp=tmp_ele.split("_");
                Long now=System.currentTimeMillis();
                if(now-Long.parseLong(tmp[1])>current_workspace_setting.get_delay_time()) {
                    jedis.srem(workspace_id+"_black_set", tmp_ele);
                    jedis.sadd(workspace_id+"_white_set",tmp[0]);
                }
            }
            /* -------------查詢--------------- */
            proxy=ru.pick(jedis,workspace_id+"_white_set");
        } while(proxy==null||proxy.equals(""));
        ru.add(jedis, workspace_id + "_black_set", proxy + "_" + System.currentTimeMillis());
        current_workspace_setting.set_last_action_time(System.currentTimeMillis());
        /* -------------回收--------------- */
        for(Map.Entry<String,ProxySetting> entry:workspace_setting.entrySet()) {
            String key=entry.getKey();
            ProxySetting tps=entry.getValue();
            Long last_action_time = tps.get_last_action_time();
            Long elapse_time = System.currentTimeMillis() - last_action_time;
            int dead_time = tps.get_dead_time();
            if (elapse_time > dead_time) {
                /* 在Redis中刪除這個set */
                ru.clean_set(jedis, key + "_white_set");
                ru.clean_set(jedis, key + "_black_set");
                workspace_setting.remove(key);
                /* 在這裏也要刪除workspace_id */
                jedis.srem("workspace_pool",workspace_id);
            }
        }
        collector.emit(new Values(global_info, download_url,proxy));
    }
 
開發者ID:cutoutsy,項目名稱:miner,代碼行數:67,代碼來源:ProxyBolt.java


注:本文中的backtype.storm.tuple.Tuple.getValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。