当前位置: 首页>>代码示例>>Java>>正文


Java ProcessSession.remove方法代码示例

本文整理汇总了Java中org.apache.nifi.processor.ProcessSession.remove方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessSession.remove方法的具体用法?Java ProcessSession.remove怎么用?Java ProcessSession.remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.nifi.processor.ProcessSession的用法示例。


在下文中一共展示了ProcessSession.remove方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
	public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
		// TODO Auto-generated method stub
		FlowFile flowfile = session.get();
		Map<String,String> attr =flowfile.getAttributes();
		String batchID = flowfile.getAttribute("batchID");
		if(attr.containsKey("fromEdgent")) {
			//String imageId = flowfile.getAttribute("imageID");
			if(batchMap.containsKey(batchID)) {
				session.transfer(flowfile, REL_SUCCESS);
				batchMap.put(batchID, "");
			} else {
				session.remove(flowfile);
            }
		}
		else {
            batchMap.put(batchID, "");
            session.remove(flowfile);
        }
        session.commit();
//		else
//		{
//			String url = flowfile.getAttribute("URL");
//			urlMap.put(batchID,url);
//			if(imageMap.containsKey(batchID)) {
//				flowfile = session.putAttribute(flowfile, "imageID",imageMap.get(batchID));
//				session.transfer(flowfile, REL_SUCCESS);
//				imageMap.remove(batchID);
//				batchMap.put(batchID, "");
//			}
//			else
//				session.remove(flowfile);
//		}
	}
 
开发者ID:dream-lab,项目名称:echo,代码行数:35,代码来源:JoinTF.java

示例2: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的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);
    }
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:70,代码来源:FilterImagesEdgent.java

示例3: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public final void onTrigger(ProcessContext context, ProcessSession session) {
    List<FlowFile> incoming = session.get(batchSize);
    if (incoming.isEmpty()) {
        return;
    }

    final long currentTimestamp = System.currentTimeMillis();

    List<FlowFile> outgoing = new ArrayList<>();

    Map<String, String> attributes;
    for (FlowFile flowFile : incoming) {
        attributes = flowFile.getAttributes();
        String key = StringUtils.isEmpty(correlationKey) ? DEFAULT_MOMENT_AGGREGATOR_KEY : correlationKey;
        String correlationAttr = attributes.getOrDefault(key, DEFAULT_MOMENT_AGGREGATOR_KEY);
        MomentAggregator aggregator = momentsMap.get(correlationAttr);
        if (null == aggregator) {
            aggregator = new MomentAggregator();
            momentsMap.put(correlationAttr, aggregator);
        }

        try {
            updateStats(flowFile, aggregator, currentTimestamp);
        } catch (Exception e) {
            getLogger().warn("Unable to update statistics", e);
            session.remove(flowFile);
            continue;
        }

        Optional<Map<String, String>> stats = latestStats.get(correlationAttr);
        if (null == stats) {
            stats = Optional.of(new ConcurrentHashMap<>());
            latestStats.put(correlationAttr, stats);
        }

        if (stats.isPresent()) {
            flowFile = session.putAllAttributes(flowFile, stats.get());
            session.getProvenanceReporter().modifyAttributes(flowFile);
        }
        outgoing.add(flowFile);
    }

    if (!outgoing.isEmpty()) {
        session.transfer(outgoing, REL_ORIGINAL);
    }

    sendStatsIfPresent(session, currentTimestamp);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:50,代码来源:AbstractStatsProcessor.java

示例4: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
    session.remove(session.get(batchSize));
    session.commit();
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:6,代码来源:AutoTerminator.java

示例5: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
    FlowFile flowFile = session.get();
    if (flowFile == null) {
        return;
    }

    ComponentLog logger = this.getLogger();

    // Evaluate expression language and create BSON Documents
    Document query = (queryProperty.isSet()) ? Document.parse(queryProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
    Document projection = (projectionProperty.isSet()) ? Document.parse(projectionProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;
    Document sort = (sortProperty.isSet()) ? Document.parse(sortProperty.evaluateAttributeExpressions(flowFile).getValue()) : null;

    try {
        FindIterable<Document> it = (query != null) ? collection.find(query) : collection.find();

        // Apply projection if needed
        if (projection != null) {
            it.projection(projection);
        }

        // Apply sort if needed
        if (sort != null) {
            it.sort(sort);
        }

        // Apply limit if set
        if (limit != null) {
            it.limit(limit.intValue());
        }

        // Iterate and create flowfile for each result
        final MongoCursor<Document> cursor = it.iterator();
        try {
            while (cursor.hasNext()) {
                // Create new flowfile with all parent attributes
                FlowFile ff = session.clone(flowFile);
                ff = session.write(ff, new OutputStreamCallback() {
                    @Override
                    public void process(OutputStream outputStream) throws IOException {
                        IOUtils.write(cursor.next().toJson(), outputStream);
                    }
                });

                session.transfer(ff, REL_SUCCESS);
            }
        } finally {
            cursor.close();
            session.remove(flowFile);
        }

    } catch (Exception e) {
        logger.error("Failed to execute query {} due to {}.", new Object[]{query, e}, e);
        flowFile = session.putAttribute(flowFile, "mongo.exception", e.getMessage());
        session.transfer(flowFile, REL_FAILURE);
    }
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:59,代码来源:QueryMongo.java

示例6: onTrigger

import org.apache.nifi.processor.ProcessSession; //导入方法依赖的package包/类
/**
 *
 */
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
	final ProcessorLog log = this.getLogger();
	long executionCompletionTimeout = Long.parseLong(context.getProperty(EXECUTION_COMPLETION_TIMEOUT).getValue());

	FlowFile flowFile = session.get();
	if (flowFile != null){
		try {
			String configurationName = flowFile.getAttribute("filename");
			Assert.isTrue(configurationName.endsWith(".cfg"), "Received invalid configuration file '" +
					configurationName + "'. DStream configuration file must end with '.cfg'.");

			log.info("Recieved configuration '" + configurationName + "'");
			AtomicReference<String> outputPathRef = new AtomicReference<String>();
			session.read(flowFile, new InputStreamCallback() {
				@Override
				public void process(InputStream confFileInputStream) throws IOException {
					outputPathRef.set(installConfiguration(configurationName, confFileInputStream));
				}
			});
			String executionName = configurationName.split("\\.")[0];

			DStream<?> dstream = this.getDStream(executionName);
			if (dstream != null){
				log.info("Executing DStream for '" + executionName + "'");
				this.postProcessResults(this.executeDStream(dstream, executionName, executionCompletionTimeout));
				FlowFile resultFlowFile = session.create();
				resultFlowFile = session.putAttribute(resultFlowFile, CoreAttributes.FILENAME.key(), outputPathRef.get());
				session.getProvenanceReporter().receive(resultFlowFile, outputPathRef.get());
				session.transfer(resultFlowFile, OUTPUT);
			} else {
				log.warn("Failed to locate DStream for execution '" + executionName + "'"
						+ ". Nothing was executed. Possible reasons: " + this.getClass().getSimpleName()
						+ " may not have provided a DStream for '" + executionName + "'");
			}
		}
		catch (Exception e) {
			throw new IllegalStateException("Failed DStream execution with unexpected exception ", e);
		}
		finally {
			session.remove(flowFile);
			session.commit();
		}
	}
}
 
开发者ID:hortonworks,项目名称:dstream,代码行数:49,代码来源:AbstractDStreamProcessor.java


注:本文中的org.apache.nifi.processor.ProcessSession.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。