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


Java TridentTuple類代碼示例

本文整理匯總了Java中storm.trident.tuple.TridentTuple的典型用法代碼示例。如果您正苦於以下問題:Java TridentTuple類的具體用法?Java TridentTuple怎麽用?Java TridentTuple使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: updateState

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
    String topic = null;
    for (TridentTuple tuple : tuples) {
        try {
            topic = topicSelector.getTopic(tuple);

            if(topic != null) {
                producer.send(new KeyedMessage(topic, mapper.getKeyFromTuple(tuple),
                        mapper.getMessageFromTuple(tuple)));
            } else {
                LOG.warn("skipping key = " + mapper.getKeyFromTuple(tuple) + ", topic selector returned null.");
            }
        } catch (Exception ex) {
            String errorMsg = "Could not send message with key = " + mapper.getKeyFromTuple(tuple)
                    + " to topic = " + topic;
            LOG.warn(errorMsg, ex);
            throw new FailedException(errorMsg, ex);
        }
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:21,代碼來源:TridentKafkaState.java

示例2: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
/**
 * <p>This function get the radius client from radius event.</p>
 * @author Andres Gomez
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String, Object> radiusData = (Map<String, Object>) tuple.getValue(0);

    String clientMac = radiusData.get("Calling-Station-Id").toString();
    clientMac = clientMac.replace("-", ":");
    
    Map<String, Object> radiusMap = new HashMap<>();
    
    radiusMap.put("client_mac", clientMac);
    
    if (_debug) {
        System.out.println(GetRadiusClient.class +" - Radius client to query: " + clientMac);
    }
    
    collector.emit(new Values(radiusMap));
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:22,代碼來源:GetRadiusClient.java

示例3: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
/**
 * <p>This function converts a JSON events to JAVA Map.</p>
 */
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String jsonEvent = tuple.getString(0);
    if (jsonEvent != null && jsonEvent.length() > 0) {
        Map<String, Object> event = null;
        try {
            event = _mapper.readValue(jsonEvent, Map.class);
            _metric.incrEvent();
        } catch (IOException | NullPointerException ex) {
            Logger.getLogger(MapperFunction.class.getName()).log(Level.SEVERE, "Failed converting a JSON tuple to a Map class [ " + _metricName + " ] \n"
                    + " JSON tuple: " + jsonEvent, ex);
        }
        if (event != null)
            collector.emit(new Values(event));
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:20,代碼來源:MapperFunction.java

示例4: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Map<String , Object> mseData = (Map<String, Object>) tuple.get(0);
    List<Map<String, Object>> notifications = (List<Map<String, Object>>) mseData.get("notifications");

    for (Map<String, Object> notification : notifications){
        if(notification.get("notificationType").equals("association")){
            logger.fine("Mse10 event this event is a association, emitting: [" + notification.size() + ", " + "null]");
            collector.emit(new Values(notification, null));
        }else if(notification.get("notificationType").equals("locationupdate")){
            logger.fine("Mse10 event this event is a locationupdate, emitting: [null" + ", " + notification.size() + "]");
            collector.emit(new Values(null, notification));
        }else{
            Logger.getLogger(SplitMSE10Data.class.getName()).log(Level.WARNING, "MSE version 10 notificationType is unknown: " + notification.get("notificationType"));
        }
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:18,代碼來源:SplitMSE10Data.java

示例5: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, Map<String, Object> result, TridentCollector collector) {
    if (result == null) {
        Map<String, Object> empty = new HashMap<>();
        collector.emit(new Values(empty));
    } else {
        result.remove("client_rssi");
        result.remove("client_rssi_num");
        result.remove("client_snr");
        result.remove("client_snr_num");
        result.remove("dot11_status");
        result.remove("wireless_id");

        collector.emit(new Values(result));
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:17,代碼來源:MemcachedEventsLocationMseQuery.java

示例6: updateState

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void updateState(MapState<Map<String, Object>> state, List<TridentTuple> tuples, TridentCollector collector) {
    List<Map<String, Object>> events = Lists.newArrayList();
    List<List<Object>> keys = Lists.newArrayList();
    for (TridentTuple t : tuples) {
        if(t!=null) {
            List<Object> l = Lists.newArrayList();
            l.add(_generalKey + t.getValueByField(_key));
            keys.add(l);
            events.add((Map<String, Object>) t.getValueByField(_value));

            //System.out.println("SAVED TO MEMCACHED KEY: " + _generalKey +t.getValueByField(_key) +
            //      " VALUE: " + t.getValueByField(_value));
        }
    }
    
    try {
        state.multiPut(keys, events);
    } catch (ReportedFailedException e) {
        Logger.getLogger(MemcachedUpdater.class.getName()).log(Level.WARNING, null, e);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:23,代碼來源:MemcachedUpdater.java

示例7: updateState

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void updateState(MapState<Map<String, Object>> state, List<TridentTuple> tuples, TridentCollector collector) {
    List<Map<String, Object>> events = new ArrayList<>();
    List<List<Object>> keys = new ArrayList<>();
    for (TridentTuple t : tuples) {
        if (t != null) {
            List<Object> l = new ArrayList<>();
            l.add(_generalKey + t.getValueByField(_key));
            keys.add(l);
            if (t.getValueByField(_value) != null)
                events.add((Map<String, Object>) t.getValueByField(_value));

            if (_debug) {
                System.out.println("SAVED TO RIAK KEY: " + _generalKey + t.getValueByField(_key)
                        + " VALUE: " + t.getValueByField(_value));
            }
        }
    }

    try {
        if (!events.isEmpty())
            state.multiPut(keys, events);
    } catch (ReportedFailedException e) {
        Logger.getLogger(RiakUpdater.class.getName()).log(Level.WARNING, null, e);
    }
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:27,代碼來源:RiakUpdater.java

示例8: isKeep

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public boolean isKeep(TridentTuple tuple) {
    String mac = tuple.getStringByField("src_mac");
    boolean status = true;

    if(mac!=null) {
        String macSplit[] = mac.split(":");
        String macHex = macSplit[0];

        // if (_debug)
        //    System.out.println("HEX: " + macHex);

        String binary = hexToBin(macHex);

        if (binary.endsWith("10") || binary.endsWith("11"))
            status = false;

        // if (_debug) {
        //     System.out.println("BIN: " + binary);
        //     System.out.println("TRUE/FALSE: " + status);
        // }
    }
    return status;
}
 
開發者ID:redBorder,項目名稱:rb-bi,代碼行數:25,代碼來源:MacLocallyAdministeredFilter.java

示例9: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String currentValue;
    int newHashModValue;
    String newValue;
    int currentTry;

    currentTry = 0;
    currentValue = tuple.getString(0);
    newHashModValue = (currentValue.hashCode() % this.numPartitions) + 1;
    newHashModValue = newHashModValue % this.numPartitions;  // rotate back to 0 if necessary

    do {
        newValue = UUID.randomUUID().toString();

        if (currentTry++ >= maxTry) {
            throw new RuntimeException("Couldn't find a value for hash/mod " + newHashModValue +
                    " in " + maxTry + " attempts. Current value is " + newValue +
                    " Number of partitions: " + this.numPartitions);
        }

    } while ((newValue.hashCode() % this.numPartitions) != newHashModValue);

    collector.emit(new Values(newValue));
}
 
開發者ID:uzh,項目名稱:storm-scheduler,代碼行數:26,代碼來源:IncreaseHashByOneFunction.java

示例10: updateState

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
public void updateState(List<TridentTuple> tuples, TridentCollector collector) {
    List<Mutation> mutations = Lists.newArrayList();

    for (TridentTuple tuple : tuples) {
        byte[] rowKey = options.mapper.rowKey(tuple);
        ColumnList cols = options.mapper.columns(tuple);
        mutations.addAll(hBaseClient.constructMutationReq(rowKey, cols, options.durability));
    }

    try {
        hBaseClient.batchMutate(mutations);
    } catch (Exception e) {
        LOG.warn("Batch write failed but some requests might have succeeded. Triggering replay.", e);
        throw new FailedException(e);
    }
}
 
開發者ID:mengzhiyi,項目名稱:storm-hbase-1.0.x,代碼行數:17,代碼來源:HBaseState.java

示例11: batchRetrieve

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
public List<List<Values>> batchRetrieve(List<TridentTuple> tridentTuples) {
    List<List<Values>> batchRetrieveResult = Lists.newArrayList();
    List<Get> gets = Lists.newArrayList();
    for (TridentTuple tuple : tridentTuples) {
        byte[] rowKey = options.mapper.rowKey(tuple);
        gets.add(hBaseClient.constructGetRequests(rowKey, options.projectionCriteria));
    }

    try {
        Result[] results = hBaseClient.batchGet(gets);
        for(Result result : results) {
            List<Values> values = options.rowToStormValueMapper.toValues(result);
            batchRetrieveResult.add(values);
        }
    } catch (Exception e) {
        LOG.warn("Batch get operation failed. Triggering replay.", e);
        throw new FailedException(e);
    }
    return batchRetrieveResult;
}
 
開發者ID:mengzhiyi,項目名稱:storm-hbase-1.0.x,代碼行數:21,代碼來源:HBaseState.java

示例12: finishBatch

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void finishBatch(ProcessorContext processorContext) {
    BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
    if (!state.tuples.isEmpty()) {
        List<Object> results = _function.batchRetrieve(_state, state.args);
        if (results.size() != state.tuples.size()) {
            throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
        }
        for (int i = 0; i < state.tuples.size(); i++) {
            TridentTuple tuple = state.tuples.get(i);
            Object result = results.get(i);
            _collector.setContext(processorContext, tuple);
            _function.execute(_projection.create(tuple), result, _collector);
        }
    }
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:17,代碼來源:StateQueryProcessor.java

示例13: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
    String url = tridentTuple.getString(0);

    Readability readability = null;
    Integer timeoutMillis = 5000;

    try {
        readability = new Readability(new URL(url), timeoutMillis);  // URL
        readability.init();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        return;
    }

    String webPageString = readability.content; //readability.outerHtml();
    String webPageTitle = readability.title;
    String hrefString = readability.hrefString.toString();

    //System.out.println("GetAdFreeWebPage: hrefString: \""+ hrefString+"\"");
    tridentCollector.emit(new Values(webPageString, webPageTitle, hrefString));
}
 
開發者ID:preems,項目名稱:realtime-event-processing,代碼行數:23,代碼來源:GetAdFreeWebPage.java

示例14: execute

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
    public void execute(TridentTuple tridentTuple, TridentCollector tridentCollector) {
        String hrefList = tridentTuple.getString(0);
        Integer depth = Integer.parseInt(tridentTuple.getString(1));

        if(hrefList == null || hrefList.trim().length() == 0 || depth == 0)
            return;
        depth--;

//        System.out.println("PrepareHrefKafka: \""+hrefList+"\"");

        String[] hrefArray = hrefList.split(" ");
        for(String href : hrefArray) {
            tridentCollector.emit(new Values(href, depth.toString()));
        }
    }
 
開發者ID:preems,項目名稱:realtime-event-processing,代碼行數:17,代碼來源:PrepareHrefKafka.java

示例15: finishBatch

import storm.trident.tuple.TridentTuple; //導入依賴的package包/類
@Override
public void finishBatch(ProcessorContext processorContext) {
    BatchState state = (BatchState) processorContext.state[_context.getStateIndex()];
    if(!state.tuples.isEmpty()) {
        List<Object> results = _function.batchRetrieve(_state, state.args);
        if(results.size()!=state.tuples.size()) {
            throw new RuntimeException("Results size is different than argument size: " + results.size() + " vs " + state.tuples.size());
        }
        for(int i=0; i<state.tuples.size(); i++) {
            TridentTuple tuple = state.tuples.get(i);
            Object result = results.get(i);
            _collector.setContext(processorContext, tuple);
            _function.execute(_projection.create(tuple), result, _collector);            
        }
    }
}
 
開發者ID:greeenSY,項目名稱:Tstream,代碼行數:17,代碼來源:StateQueryProcessor.java


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