本文整理汇总了Java中org.apache.edgent.function.Predicate类的典型用法代码示例。如果您正苦于以下问题:Java Predicate类的具体用法?Java Predicate怎么用?Java Predicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Predicate类属于org.apache.edgent.function包,在下文中一共展示了Predicate类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.edgent.function.Predicate; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
GenericSensor sensor = new GenericSensor();
DirectProvider dp = new DirectProvider();
Topology topology = dp.newTopology();
TStream<String> tempReadings = topology.poll(sensor, 1, TimeUnit.MILLISECONDS);
String condition = "@.d.temp>=60 || @.d.temp<=20";
Predicate<String> p = new SamplePredicate(condition);
// TStream<Double> filteredReadings = tempReadings.filter(reading -> reading <
// 50 || reading > 80);
TStream<String> filteredReadings = tempReadings.filter(p);
filteredReadings.print();
dp.submit(topology);
}
示例2: traceTuplesFn
import org.apache.edgent.function.Predicate; //导入依赖的package包/类
private <T> Predicate<T> traceTuplesFn(String label) {
return tuple -> true; // TODO make dynamic config; affected by "label" value
// check label for match against csv or regex from props
}
示例3: onTrigger
import org.apache.edgent.function.Predicate; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
// TODO Auto-generated method stub
resultMap = new HashMap<String,String>();
System.out.println("Started Nifi");
FlowFile flowfile = session.get();
String jsonDir = flowfile.getAttribute("sourceDir");
String batchID = flowfile.getAttribute("batchID");
// why are they being removed?
//if(batchMap.containsKey(batchID)) {
// session.remove(flowfile);
// return;
//}
batchMap.put(batchID, 1);
DirectProvider dp = new DirectProvider();
Topology topology = dp.newTopology("Edgent Application");
String objectClass = context.getProperty(OBJECT_CLASS).getValue();
getLogger().info("Created Edgent Topology: "+topology.getName());
TempSource source = new TempSource(jsonDir +"/out");
TStream<Pair<String,String>> sourceStream = topology.source(source);
TStream<Pair<String,String>> filteredStream = sourceStream.filter(new Predicate<Pair<String,String>>() {
@Override
public boolean test(Pair<String,String> map) {
boolean isValid = false;
String jsonString = map.getRight();
JsonArray jsonArray = (new Gson()).fromJson(jsonString, JsonArray.class);
for(int i=0;i<jsonArray.size();i++)
{
JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
if(jsonObject.get("label").getAsString().equals(objectClass)) {
isValid = true;
break;
}
}
return isValid;
}
});
filteredStream.sink(tuple -> update(tuple));
dp.submit(topology);
System.out.println("Submitted Topology");
// Why are we sleeping here?
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(resultMap.size());
// To write the results back out ot flow file
session.remove(flowfile);
//for(Map.Entry<String, String> entry:resultMap.entrySet())
if(resultMap.size()>0){
FlowFile flowFile = session.create();
flowFile = session.putAttribute(flowFile, "batchID", batchID);
// should imageID be a NULL string?
flowFile = session.putAttribute(flowFile, "imageID", "");
flowFile = session.putAttribute(flowFile, "fromEdgent", "1");
session.transfer(flowFile,REL_SUCCESS);
}
}