public final class StateWaiter extends Object
Provides wait calls that block until the next unobserved state of the requested type arrives. Unobserved states are states that have occurred since the last wait, or that will be received from the camera device in the future.
Thread interruptions are not supported; interrupting a thread that is either
waiting with waitForState(int, long)
/ waitForAnyOfStates(java.util.Collection<java.lang.Integer>, long)
or is currently in
StateChangeListener.onStateChanged(int)
(provided by getListener()
) will result in an
UnsupportedOperationException
being raised on that thread.
Constructor and Description |
---|
StateWaiter(String[] stateNames)
Create a new state waiter.
|
Modifier and Type | Method and Description |
---|---|
void |
appendStateNames(StringBuilder s,
Collection<Integer> states)
Append all states to string
|
StateChangeListener |
getListener() |
String |
getStateName(int state)
Convert state integer to a String
|
int |
waitForAnyOfStates(Collection<Integer> states,
long timeoutMs)
Wait until the one of the desired
states is observed, checking all
state transitions since the last time a state was waited on. |
void |
waitForState(int state,
long timeoutMs)
Wait until the desired state is observed, checking all state
transitions since the last time a state was waited on.
|
public StateWaiter(String[] stateNames)
All state
/states
arguments used in other methods must be
in the range of [0, stateNames.length - 1]
.
stateNames
- an array of string names, used to mark the range of the valid statespublic StateChangeListener getListener()
public void waitForState(int state, long timeoutMs)
Any intermediate state transitions that is not state
are ignored.
Note: Only one waiter allowed at a time!
state
- state to observe a transition totimeoutMs
- how long to wait in millisecondsIllegalArgumentException
- if state
was out of rangeTimeoutRuntimeException
- if the desired state is not observed before timeout.IllegalStateException
- if another thread is already waiting for a state transitionpublic int waitForAnyOfStates(Collection<Integer> states, long timeoutMs)
states
is observed, checking all
state transitions since the last time a state was waited on.
Any intermediate state transitions that are not in states
are ignored.
Note: Only one waiter allowed at a time!
states
- Set of desired states to observe a transition to.timeoutMs
- how long to wait in millisecondsIllegalArgumentException
- if state
was out of rangeTimeoutRuntimeException
- if none of the states is observed before timeout.IllegalStateException
- if another thread is already waiting for a state transitionpublic String getStateName(int state)
public void appendStateNames(StringBuilder s, Collection<Integer> states)