Java Code Examples for org.apache.nifi.processor.ProcessContext#getStateManager()
The following examples show how to use
org.apache.nifi.processor.ProcessContext#getStateManager() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributeRollingWindow.java From localization_nifi with Apache License 2.0 | 6 votes |
@OnScheduled public void onScheduled(final ProcessContext context) throws IOException { timeWindow = context.getProperty(TIME_WINDOW).asTimePeriod(TimeUnit.MILLISECONDS); microBatchTime = context.getProperty(SUB_WINDOW_LENGTH).asTimePeriod(TimeUnit.MILLISECONDS); if(microBatchTime == null || microBatchTime == 0) { StateManager stateManager = context.getStateManager(); StateMap state = stateManager.getState(SCOPE); HashMap<String, String> tempMap = new HashMap<>(); tempMap.putAll(state.toMap()); if (!tempMap.containsKey(COUNT_KEY)) { tempMap.put(COUNT_KEY, "0"); context.getStateManager().setState(tempMap, SCOPE); } } }
Example 2
Source File: AttributeRollingWindow.java From nifi with Apache License 2.0 | 6 votes |
@OnScheduled public void onScheduled(final ProcessContext context) throws IOException { timeWindow = context.getProperty(TIME_WINDOW).asTimePeriod(TimeUnit.MILLISECONDS); microBatchTime = context.getProperty(SUB_WINDOW_LENGTH).asTimePeriod(TimeUnit.MILLISECONDS); if(microBatchTime == null || microBatchTime == 0) { StateManager stateManager = context.getStateManager(); StateMap state = stateManager.getState(SCOPE); HashMap<String, String> tempMap = new HashMap<>(); tempMap.putAll(state.toMap()); if (!tempMap.containsKey(COUNT_KEY)) { tempMap.put(COUNT_KEY, "0"); context.getStateManager().setState(tempMap, SCOPE); } } }
Example 3
Source File: MonitorActivity.java From localization_nifi with Apache License 2.0 | 5 votes |
@OnStopped public void onStopped(final ProcessContext context) { if (getNodeTypeProvider().isPrimary()) { final StateManager stateManager = context.getStateManager(); try { stateManager.clear(Scope.CLUSTER); } catch (IOException e) { getLogger().error("Failed to clear cluster state due to " + e, e); } } }
Example 4
Source File: UpdateAttribute.java From localization_nifi with Apache License 2.0 | 5 votes |
@OnScheduled public void onScheduled(final ProcessContext context) throws IOException { criteriaCache.set(CriteriaSerDe.deserialize(context.getAnnotationData())); propertyValues.clear(); if(stateful) { StateManager stateManager = context.getStateManager(); StateMap state = stateManager.getState(Scope.LOCAL); HashMap<String, String> tempMap = new HashMap<>(); tempMap.putAll(state.toMap()); String initValue = context.getProperty(STATEFUL_VARIABLES_INIT_VALUE).getValue(); // Initialize the stateful default actions for (PropertyDescriptor entry : context.getProperties().keySet()) { if (entry.isDynamic()) { if(!tempMap.containsKey(entry.getName())) { tempMap.put(entry.getName(), initValue); } } } // Initialize the stateful actions if the criteria exists final Criteria criteria = criteriaCache.get(); if (criteria != null) { for (Rule rule : criteria.getRules()) { for (Action action : rule.getActions()) { if (!tempMap.containsKey(action.getAttribute())) { tempMap.put(action.getAttribute(), initValue); } } } } context.getStateManager().setState(tempMap, Scope.LOCAL); } defaultActions = getDefaultActions(context.getProperties()); debugEnabled = getLogger().isDebugEnabled(); }
Example 5
Source File: MonitorActivity.java From nifi with Apache License 2.0 | 5 votes |
@OnStopped public void onStopped(final ProcessContext context) { if (getNodeTypeProvider().isPrimary()) { final StateManager stateManager = context.getStateManager(); try { stateManager.clear(Scope.CLUSTER); } catch (IOException e) { getLogger().error("Failed to clear cluster state due to " + e, e); } } }
Example 6
Source File: UpdateAttribute.java From nifi with Apache License 2.0 | 4 votes |
@OnScheduled public void onScheduled(final ProcessContext context) throws IOException { final int cacheSize = context.getProperty(CANONICAL_VALUE_LOOKUP_CACHE_SIZE).asInteger(); canonicalValueLookup = Caffeine.newBuilder() .maximumSize(cacheSize) .build(attributeValue -> attributeValue); criteriaCache.set(CriteriaSerDe.deserialize(context.getAnnotationData())); propertyValues.clear(); if(stateful) { StateManager stateManager = context.getStateManager(); StateMap state = stateManager.getState(Scope.LOCAL); HashMap<String, String> tempMap = new HashMap<>(); tempMap.putAll(state.toMap()); String initValue = context.getProperty(STATEFUL_VARIABLES_INIT_VALUE).getValue(); // Initialize the stateful default actions for (PropertyDescriptor entry : context.getProperties().keySet()) { if (entry.isDynamic()) { if(!tempMap.containsKey(entry.getName())) { tempMap.put(entry.getName(), initValue); } } } // Initialize the stateful actions if the criteria exists final Criteria criteria = criteriaCache.get(); if (criteria != null) { for (Rule rule : criteria.getRules()) { for (Action action : rule.getActions()) { if (!tempMap.containsKey(action.getAttribute())) { tempMap.put(action.getAttribute(), initValue); } } } } context.getStateManager().setState(tempMap, Scope.LOCAL); } defaultActions = getDefaultActions(context.getProperties()); debugEnabled = getLogger().isDebugEnabled(); }