本文整理汇总了Java中org.apache.nifi.components.state.StateManager类的典型用法代码示例。如果您正苦于以下问题:Java StateManager类的具体用法?Java StateManager怎么用?Java StateManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StateManager类属于org.apache.nifi.components.state包,在下文中一共展示了StateManager类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: incrementAndSet
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
private Map<String, String> incrementAndSet(StateManager stateManager, double value, boolean resetFirst) throws IOException {
StateMap stateMap = stateManager.getState(Scope.LOCAL);
String oldSumString = stateMap.get(TUMBLING_WINDOW_SUM_KEY);
String oldCountString = stateMap.get(TUMBLING_WINDOW_COUNT_KEY);
if (oldCountString == null || oldSumString == null) {
oldSumString = "0.0";
oldCountString = "0";
}
String newSumString = String.valueOf(value);
String newCountString = "1";
if (!resetFirst) {
newSumString = String.valueOf(Double.valueOf(oldSumString) + value);
newCountString = String.valueOf(Long.valueOf(oldCountString) + 1);
}
Map<String, String> newState = ImmutableMap.of(TUMBLING_WINDOW_SUM_KEY, newSumString, TUMBLING_WINDOW_COUNT_KEY, newCountString);
stateManager.setState(newState, Scope.LOCAL);
return resetFirst ?
ImmutableMap.of(TUMBLING_WINDOW_SUM_KEY, oldSumString, TUMBLING_WINDOW_COUNT_KEY, oldCountString) :
newState;
}
开发者ID:Asymmetrik,项目名称:nifi-nars,代码行数:27,代码来源:AttributeTumblingWindow.java
示例2: testStateJavascript
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
/**
* Demonstrates reading and writing processor state values
* @throws Exception
*/
@Test
public void testStateJavascript() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "ECMAScript");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/state/state.js");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
StateManager stateManager = runner.getStateManager();
stateManager.clear(Scope.CLUSTER);
Map<String, String> initialStateValues = new HashMap<>();
initialStateValues.put("some-state", "foo");
stateManager.setState(initialStateValues, Scope.CLUSTER);
runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8));
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
StateMap resultStateValues = stateManager.getState(Scope.CLUSTER);
Assert.assertEquals("foobar", resultStateValues.get("some-state"));
}
开发者ID:BatchIQ,项目名称:nifi-scripting-samples,代码行数:27,代码来源:TestState.java
示例3: testStatePython
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
/**
* Demonstrates reading and writing processor state values
* @throws Exception
*/
@Test
public void testStatePython() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
runner.setValidateExpressionUsage(false);
runner.setProperty(SCRIPT_ENGINE, "python");
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "src/test/resources/executescript/state/state.py");
runner.setProperty(ScriptingComponentUtils.MODULES, "src/test/resources/executescript");
runner.assertValid();
StateManager stateManager = runner.getStateManager();
stateManager.clear(Scope.CLUSTER);
Map<String, String> initialStateValues = new HashMap<>();
initialStateValues.put("some-state", "foo");
stateManager.setState(initialStateValues, Scope.CLUSTER);
runner.enqueue("sample text".getBytes(StandardCharsets.UTF_8));
runner.run();
runner.assertAllFlowFilesTransferred("success", 1);
StateMap resultStateValues = stateManager.getState(Scope.CLUSTER);
Assert.assertEquals("foobar", resultStateValues.get("some-state"));
}
开发者ID:BatchIQ,项目名称:nifi-scripting-samples,代码行数:27,代码来源:TestState.java
示例4: getLastEventId
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
private long getLastEventId(StateManager stateManager) {
try {
final StateMap stateMap = stateManager.getState(Scope.CLUSTER);
final String lastEventIdStr = stateMap.get("lastEventId");
final long lastEventId = lastEventIdStr != null ? Long.parseLong(lastEventIdStr) : 0;
return lastEventId;
} catch (final IOException ioe) {
getLogger().warn("Failed to retrieve the last event id from the "
+ "state manager.", ioe);
return 0;
}
}
开发者ID:jfrazee,项目名称:nifi-provenance-reporting-bundle,代码行数:13,代码来源:AbstractProvenanceReporter.java
示例5: persist
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
private void persist(final long listingTimestamp, final long processedTimestamp, final StateManager stateManager, final Scope scope) throws IOException {
final Map<String, String> updatedState = new HashMap<>(1);
updatedState.put(LISTING_TIMESTAMP_KEY, String.valueOf(listingTimestamp));
updatedState.put(PROCESSED_TIMESTAMP_KEY, String.valueOf(processedTimestamp));
stateManager.setState(updatedState, scope);
}
开发者ID:clickha,项目名称:nifi-tools,代码行数:7,代码来源:AbstractListProcessor.java
示例6: getStateManager
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
@Override
public StateManager getStateManager() {
return null;
}
开发者ID:apache,项目名称:nifi-minifi,代码行数:5,代码来源:MockControllerServiceInitializationContext.java
示例7: setLastEventId
import org.apache.nifi.components.state.StateManager; //导入依赖的package包/类
private void setLastEventId(StateManager stateManager, long eventId) throws IOException {
final StateMap stateMap = stateManager.getState(Scope.CLUSTER);
final Map<String, String> statePropertyMap = new HashMap<>(stateMap.toMap());
statePropertyMap.put("lastEventId", Long.toString(eventId));
stateManager.setState(statePropertyMap, Scope.CLUSTER);
}
开发者ID:jfrazee,项目名称:nifi-provenance-reporting-bundle,代码行数:7,代码来源:AbstractProvenanceReporter.java
注:本文中的org.apache.nifi.components.state.StateManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论