Class WaitNotifyProtocol
java.lang.Object
org.apache.nifi.processors.standard.WaitNotifyProtocol
This class provide a protocol for Wait and Notify processors to work together.
Once AtomicDistributedMapCacheClient is passed to this protocol, components that wish to join the notification mechanism
should only use methods provided by this protocol, instead of calling cache API directly.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicDistributedMapCacheClientstatic final Stringstatic final Stringprivate static final org.slf4j.Loggerprivate static final intprivate static final com.fasterxml.jackson.databind.ObjectMapperprivate static final intprivate final Deserializer<String> private static final Serializer<String> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidFinish protocol and remove the cache entry.Retrieve a stored Signal in the cache engine.Notify a signal to increase a counter.Notify a signal to increase a counter.booleanreplace(WaitNotifyProtocol.Signal signal)
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
DEFAULT_COUNT_NAME
- See Also:
-
CONSUMED_COUNT_NAME
- See Also:
-
MAX_REPLACE_RETRY_COUNT
private static final int MAX_REPLACE_RETRY_COUNT- See Also:
-
REPLACE_RETRY_WAIT_MILLIS
private static final int REPLACE_RETRY_WAIT_MILLIS- See Also:
-
objectMapper
private static final com.fasterxml.jackson.databind.ObjectMapper objectMapper -
stringSerializer
-
stringDeserializer
-
cache
-
-
Constructor Details
-
WaitNotifyProtocol
-
-
Method Details
-
notify
public WaitNotifyProtocol.Signal notify(String signalId, Map<String, Integer> deltas, Map<String, throws IOException, ConcurrentModificationExceptionString> attributes) Notify a signal to increase a counter.- Parameters:
signalId- a key in the underlying cache enginedeltas- a map containing counterName and delta entries, 0 has special meaning, clears the counter back to 0attributes- attributes to save in the cache entry- Returns:
- A Signal instance, merged with an existing signal if any
- Throws:
IOException- thrown when it failed interacting with the cache engineConcurrentModificationException- thrown if other process is also updating the same signal and failed to update after few retry attempts
-
notify
public WaitNotifyProtocol.Signal notify(String signalId, String counterName, int delta, Map<String, String> attributes) throws IOException, ConcurrentModificationExceptionNotify a signal to increase a counter.- Parameters:
signalId- a key in the underlying cache enginecounterName- specify count to updatedelta- delta to update a counter, 0 has special meaning, clears the counter back to 0attributes- attributes to save in the cache entry- Returns:
- A Signal instance, merged with an existing signal if any
- Throws:
IOException- thrown when it failed interacting with the cache engineConcurrentModificationException- thrown if other process is also updating the same signal and failed to update after few retry attempts
-
getSignal
public WaitNotifyProtocol.Signal getSignal(String signalId) throws IOException, DeserializationException Retrieve a stored Signal in the cache engine. If a caller gets satisfied with the returned Signal state and finish waiting, it should callcomplete(String)to complete the Wait Notify protocol.- Parameters:
signalId- a key in the underlying cache engine- Returns:
- A Signal instance
- Throws:
IOException- thrown when it failed interacting with the cache engineDeserializationException- thrown if the cache found is not in expected serialized format
-
complete
Finish protocol and remove the cache entry.- Parameters:
signalId- a key in the underlying cache engine- Throws:
IOException- thrown when it failed interacting with the cache engine
-
replace
- Throws:
IOException
-