T
- tuple typepublic class Valve<T> extends java.lang.Object implements Predicate<T>
Predicate
.
A valve is either open or closed.
When used as a Predicate to TStream.filter()
,
filter passes tuples only when the valve is open.
A valve is typically used to dynamically control whether or not
some downstream tuple processing is enabled. A decision to change the
state of the valve may be a result of local analytics or an external
command.
E.g., in a simple case, a Valve might be used to control
whether or not logging or publishing of tuples is enabled.
TStream<JsonObject> stream = ...;
Valve<JsonObject> valve = new Valve<>(false);
stream.filter(valve).sink(someTupleLoggingConsumer);
// from some analytic or device command handler...
valve.setOpen(true);
Constructor and Description |
---|
Valve()
Create a new Valve Predicate
|
Valve(boolean isOpen)
Create a new Valve Predicate
|
Modifier and Type | Method and Description |
---|---|
boolean |
isOpen()
Get the valve state
|
void |
setOpen(boolean isOpen)
Set the valve state
|
boolean |
test(T value)
Test the state of the valve,
value is ignored. |
java.lang.String |
toString()
Returns a String for development/debug support.
|
public Valve()
Same as Valve(true)
public Valve(boolean isOpen)
isOpen
- the initial statepublic void setOpen(boolean isOpen)
isOpen
- true to open the valvepublic boolean isOpen()
public boolean test(T value)
value
is ignored.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641