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


Java ProcessContext类代码示例

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


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

示例1: onScheduled

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@OnScheduled
public void onScheduled(final ProcessContext context) {
    try {
        topic = context.getProperty(TOPIC).getValue();
        groupName = context.getProperty(CONSUMER_GROUP_NAME).getValue();
        brokerIP = context.getProperty(BROKERIP).getValue();
        props = new Properties();
        props.put("bootstrap.servers", brokerIP);
        props.put("group.id", groupName);
        props.put("enable.auto.commit", "true");
        props.put("auto.commit.interval.ms", "1000");
        props.put("session.timeout.ms", "30000");
        props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("auto.offset.reset", "earliest");
        consumer = new KafkaConsumer<String, String>(props);
        consumer.subscribe(Arrays.asList(topic));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:22,代码来源:KafkaFlowFilesConsumer.java

示例2: onTrigger

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
    FlowFile original = session.get();

    FlowFile flowFile;
    if (original == null) {
        flowFile = session.create();
        session.getProvenanceReporter().create(flowFile);
    } else {
        flowFile = session.clone(original);
        session.transfer(original, REL_ORIGINAL);
    }

    final String updatedContent = StringFormatter.format(context.getProperty(CONTENT_FIELD).getValue(), flowFile.getAttributes());
    this.getLogger().debug("Created content: {}", new Object[]{updatedContent});

    flowFile = session.write(flowFile, outputStream -> outputStream.write(updatedContent.getBytes(StandardCharsets.UTF_8)));
    session.getProvenanceReporter().modifyContent(flowFile);
    session.transfer(flowFile, REL_SUCCESS);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:21,代码来源:CreateContent.java

示例3: setup

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
public void setup(ProcessContext context) 
{
	try {
		if(!doneSetup)
		{ 
			storageConnStr = context.getProperty(AZURE_STORAGE_CONN_STR).evaluateAttributeExpressions().getValue(); 
			tableName = context.getProperty(AZURE_TABLE_TABLE_NAME).evaluateAttributeExpressions().getValue();
			useMsgField = 0; 
			doneSetup=true;
		}
		table = connectToAzTable(storageConnStr,tableName );
		/* added for use in benchmarking task with sample data */
		sampleData = "024BE2DFD1B98AF1EA941DEDA63A15CB,9F5FE566E3EE57B85B723B71E370154C,2013-01-14 03:57:00,1358117580000,-1,0,-73.953178,40.776016,-73.779190,40.645145,CRD,52.00,11.00,0.50,13.00,4.80,70.30,uber,sam,Houston";
	
	}
	catch(Exception e) {
		getLogger().error("Error in Connecting to Azure: "+e.getStackTrace().toString());
	}
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:20,代码来源:InsertAzure.java

示例4: onScheduled

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@OnScheduled
public void onScheduled(final ProcessContext context) {
    try {
        topic = context.getProperty(TOPIC).getValue();
        brokerIP = context.getProperty(BROKERIP).getValue();
        props = new Properties();
        props.put("bootstrap.servers", brokerIP);
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 16384);
        props.put("linger.ms", 1);
        props.put("buffer.memory", 33554432);
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        producer = new KafkaProducer<>(props);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:20,代码来源:KafkaFlowFilesProducer.java

示例5: rendezvousWithJms

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
/**
 * Will construct JMS {@link Message} by extracting its body from the
 * incoming {@link FlowFile}. {@link FlowFile} attributes that represent
 * standard JMS headers will be extracted from the {@link FlowFile} and set
 * as JMS headers on the newly constructed message. For the list of
 * available message headers please see {@link JmsHeaders}. <br>
 * <br>
 * Upon success the incoming {@link FlowFile} is transferred to the'success'
 * {@link Relationship} and upon failure FlowFile is penalized and
 * transferred to the 'failure' {@link Relationship}
 *
 */
@Override
protected void rendezvousWithJms(ProcessContext context, ProcessSession processSession) throws ProcessException {
    FlowFile flowFile = processSession.get();
    if (flowFile != null) {
        try {
            String destinationName = context.getProperty(DESTINATION).evaluateAttributeExpressions(flowFile).getValue();
            this.targetResource.publish(destinationName, this.extractMessageBody(flowFile, processSession), flowFile.getAttributes());
            processSession.transfer(flowFile, REL_SUCCESS);
            processSession.getProvenanceReporter().send(flowFile, context.getProperty(DESTINATION).evaluateAttributeExpressions().getValue());
        } catch (Exception e) {
            processSession.transfer(flowFile, REL_FAILURE);
            this.getLogger().error("Failed while sending message to JMS via " + this.targetResource, e);
            context.yield();
        }
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:29,代码来源:PublishJMS.java

示例6: buildTargetResource

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
/**
 * This method essentially performs initialization of this Processor by
 * obtaining an instance of the {@link ConnectionFactory} from the
 * {@link JMSConnectionFactoryProvider} (ControllerService) and performing a
 * series of {@link ConnectionFactory} adaptations which eventually results
 * in an instance of the {@link CachingConnectionFactory} used to construct
 * {@link JmsTemplate} used by this Processor.
 */
private void buildTargetResource(ProcessContext context) {
    if (this.targetResource == null) {
        JMSConnectionFactoryProviderDefinition cfProvider = context.getProperty(CF_SERVICE).asControllerService(JMSConnectionFactoryProviderDefinition.class);
        ConnectionFactory connectionFactory = cfProvider.getConnectionFactory();

        UserCredentialsConnectionFactoryAdapter cfCredentialsAdapter = new UserCredentialsConnectionFactoryAdapter();
        cfCredentialsAdapter.setTargetConnectionFactory(connectionFactory);
        cfCredentialsAdapter.setUsername(context.getProperty(USER).getValue());
        cfCredentialsAdapter.setPassword(context.getProperty(PASSWORD).getValue());

        this.cachingConnectionFactory = new CachingConnectionFactory(cfCredentialsAdapter);
        this.cachingConnectionFactory.setSessionCacheSize(Integer.parseInt(context.getProperty(SESSION_CACHE_SIZE).getValue()));

        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(this.cachingConnectionFactory);
        jmsTemplate.setPubSubDomain(TOPIC.equals(context.getProperty(DESTINATION_TYPE).getValue()));

        // set of properties that may be good candidates for exposure via configuration
        jmsTemplate.setReceiveTimeout(1000);

        this.targetResource = this.finishBuildingTargetResource(jmsTemplate, context);
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:32,代码来源:AbstractJMSProcessor.java

示例7: createAttributes

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@Override
protected Map<String, String> createAttributes(final FileInfo fileInfo, final ProcessContext context) {
	final Map<String, String> attributes = new HashMap<>();
	final DateFormat formatter = new SimpleDateFormat(ListFile.FILE_MODIFY_DATE_ATTR_FORMAT, Locale.US);
	attributes.put(getProtocolName() + ".remote.host",
			context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue());
	attributes.put(getProtocolName() + ".remote.port",
			context.getProperty(UNDEFAULTED_PORT).evaluateAttributeExpressions().getValue());
	attributes.put(getProtocolName() + ".listing.user",
			context.getProperty(USERNAME).evaluateAttributeExpressions().getValue());
	attributes.put(ListFile.FILE_LAST_MODIFY_TIME_ATTRIBUTE,
			formatter.format(new Date(fileInfo.getLastModifiedTime())));
	attributes.put(ListFile.FILE_PERMISSIONS_ATTRIBUTE, fileInfo.getPermissions());
	attributes.put(ListFile.FILE_OWNER_ATTRIBUTE, fileInfo.getOwner());
	attributes.put(ListFile.FILE_GROUP_ATTRIBUTE, fileInfo.getGroup());
	attributes.put(CoreAttributes.FILENAME.key(), fileInfo.getFileName());
	final String fullPath = fileInfo.getFullPathFileName();
	if (fullPath != null) {
		final int index = fullPath.lastIndexOf("/");
		if (index > -1) {
			final String path = fullPath.substring(0, index);
			attributes.put(CoreAttributes.PATH.key(), path);
		}
	}
	return attributes;
}
 
开发者ID:clickha,项目名称:nifi-tools,代码行数:27,代码来源:ListFileTransferV2.java

示例8: performListing

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@Override
protected List<FileInfo> performListing(final ProcessContext context, final Long minTimestamp) throws IOException {
	final FileTransferV2 transfer = getFileTransfer(context);
	final List<FileInfo> listing;
	try {
		listing = transfer.getListing();
	} finally {
		IOUtils.closeQuietly(transfer);
	}

	if (minTimestamp == null) {
		return listing;
	}

	final Iterator<FileInfo> itr = listing.iterator();
	while (itr.hasNext()) {
		final FileInfo next = itr.next();
		if (next.getLastModifiedTime() < minTimestamp) {
			itr.remove();
		}
	}

	return listing;
}
 
开发者ID:clickha,项目名称:nifi-tools,代码行数:25,代码来源:ListFileTransferV2.java

示例9: onTrigger

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) {
    DesiredCapabilities DesireCaps = new DesiredCapabilities();
    DesireCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, context.getProperty(DRIVER_LOCATION).getValue());
    driver = new PhantomJSDriver(DesireCaps);
    FlowFile flowFile = session.create();
    try {
        driver.get(url);
        (new WebDriverWait(driver, timeout)).until(
                ExpectedConditions.visibilityOfElementLocated(getExpectedCondition(selectorType, selector))
        );

        final byte[] page = formatToXHtml(driver.getPageSource(), StandardCharsets.UTF_8);
        flowFile = session.write(flowFile, outputStream -> outputStream.write(page));
        session.transfer(flowFile, REL_SUCCESS);
    } catch (Exception e) {
        flowFile = session.write(flowFile, outputStream -> outputStream.write(e.getMessage().getBytes()));
        session.transfer(flowFile, REL_FAILURE);
    } finally {
        driver.quit();
    }
    session.getProvenanceReporter().create(flowFile);
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:24,代码来源:GetWebpage.java

示例10: openSession

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
protected Session openSession(final ProcessContext context) throws JSchException {
    final JSch jsch = new JSch();
    final String hostKeyVal = context.getProperty(HOST_KEY_FILE).getValue();
    if (hostKeyVal != null) {
        jsch.setKnownHosts(hostKeyVal);
    }

    final Session session = jsch.getSession(context.getProperty(USERNAME).evaluateAttributeExpressions().getValue(),
            context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue(),
            context.getProperty(PORT).evaluateAttributeExpressions().asInteger().intValue());

    final Properties properties = new Properties();
    properties.setProperty("StrictHostKeyChecking", context.getProperty(STRICT_HOST_KEY_CHECKING).asBoolean() ? "yes" : "no");
    properties.setProperty("PreferredAuthentications", "publickey,password,keyboard-interactive");

    final PropertyValue compressionValue = context.getProperty(USE_COMPRESSION);
    if (compressionValue != null && "true".equalsIgnoreCase(compressionValue.getValue())) {
        properties.setProperty("compression.s2c", "[email protected],zlib,none");
        properties.setProperty("compression.c2s", "[email protected],zlib,none");
    } else {
        properties.setProperty("compression.s2c", "none");
        properties.setProperty("compression.c2s", "none");
    }

    session.setConfig(properties);

    final String privateKeyFile = context.getProperty(PRIVATE_KEY_PATH).evaluateAttributeExpressions().getValue();
    if (privateKeyFile != null) {
        jsch.addIdentity(privateKeyFile, context.getProperty(PRIVATE_KEY_PASSPHRASE).evaluateAttributeExpressions().getValue());
    }

    final String password = context.getProperty(PASSWORD).evaluateAttributeExpressions().getValue();
    if (password != null) {
        session.setPassword(password);
    }

    session.setTimeout(context.getProperty(CONNECTION_TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue());
    session.connect();
    return session;
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:41,代码来源:AbstractScpProcessor.java

示例11: createMongoConnection

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
protected void createMongoConnection(ProcessContext context) {
    // Get processor properties
    databaseName = context.getProperty(DATABASE).evaluateAttributeExpressions().getValue();
    collectionName = context.getProperty(COLLECTION).evaluateAttributeExpressions().getValue();

    clientService = context.getProperty(MONGO_SERVICE).asControllerService(MongoClientService.class);
    client = clientService.getMongoClient();
    database = client.getDatabase(databaseName);
    collection = database.getCollection(collectionName).withWriteConcern(determineWriteConcern(context.getProperty(WRITE_CONCERN)));
}
 
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:11,代码来源:AbstractMongoProcessor.java

示例12: setup

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
public void setup(ProcessContext context) {
	try 
	{
		// If positive, use that particular field number in the input CSV message as input for count
		String useMsgList ="taxi_identifier";
		bloomFilterFilePaths=context.getProperty(BLOOMFILTER_FILEPATH).evaluateAttributeExpressions().getValue();//"/home/sivaprakash/Workspace/Edgent/bloomfilter_taxi_id.model";
		int expectedInsertions = 20000000;
		useMsgFieldList = useMsgList.split(",");
		String bloomFilterPathList[] = bloomFilterFilePaths.split(",");
	
		// Check to enable matching of bloom filter model files and fields provided in property file
		if(useMsgFieldList.length != bloomFilterPathList.length) {
			return;
		}
		bloomFilterMap = new HashMap<String,BloomFilter<String>>();
		testingRange = expectedInsertions;
		
		/// Populating bloom filter for each model
		for(int i = 0; i < useMsgFieldList.length ;i++) {
		//Load BloomFilter from serialized file
		bloomFilter  = readBloomFilterFromfile(bloomFilterPathList[i]);
		if(bloomFilter == null) {
		
			return;
		}
		bloomFilterMap.put(useMsgFieldList[i], bloomFilter);
		}	
	} catch (Exception e) {
	
	}
		
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:33,代码来源:EdgentFilter_RBI.java

示例13: setupExecutor

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@OnScheduled
public void setupExecutor(final ProcessContext context) {
	batchMap = new HashMap<String,Integer>();
    executor = Executors.newFixedThreadPool(context.getMaxConcurrentTasks() * 2, new ThreadFactory() {
        private final ThreadFactory defaultFactory = Executors.defaultThreadFactory();

        @Override
        public Thread newThread(final Runnable r) {
            final Thread t = defaultFactory.newThread(r);
            t.setName("ExecuteProcess " + getIdentifier() + " Task");
            return t;
        }
    });
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:15,代码来源:ExecuteProcessBatch.java

示例14: createCommandStrings

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
protected List<String> createCommandStrings(final ProcessContext context, final String command, final String arguments) {
    final List<String> args = splitArgs(arguments, context.getProperty(ARG_DELIMITER).getValue().charAt(0));
    final List<String> commandStrings = new ArrayList<>(args.size() + 1);
    commandStrings.add(command);
    commandStrings.addAll(args);
    return commandStrings;
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:8,代码来源:ExecuteProcessBatch.java

示例15: onTrigger

import org.apache.nifi.processor.ProcessContext; //导入依赖的package包/类
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
	// TODO Auto-generated method stub
	FlowFile flowfile = session.get();
       
    flowfile = session.putAttribute(flowfile, "Directory", "/home/sivaprakash/Siva/Edgent/NifiTestout");  
    session.transfer(flowfile,REL_SUCCESS);
}
 
开发者ID:dream-lab,项目名称:echo,代码行数:9,代码来源:Update.java


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