本文整理匯總了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);
}
}