Interface StateHandlerContext
-
- All Known Implementing Classes:
StateMachine
public interface StateHandlerContextThis interface encapsulates all the ways in which aStateHandlermay interact with the network, the state machine, and the various timers.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidcloseConnection()Close the SPINE connection with no further messaging.voidenableConnectionDataExchange()Enable Connection Data Exchange (it cannot be disabled afterward)ConfigurationgetConfig()<T> TgetExtraData(java.lang.Class<T> dataClass)Retrieve data previously stored withsetExtraData(Object).StategetState()java.lang.IntegergetTimeoutStatus(SpecifiedTimeout which)Query the status of a specific timeout.UserInterfacegetUserInterface()voidincreaseTimeout(SpecifiedTimeout which)Prolong a specific timeout by the initial value.voidincreaseTimeout(SpecifiedTimeout which, int extraSeconds)Prolong a specific timeout.booleanisServerSide()voidprocessMessage()Indicate that the handler is ready to process a waiting message from the communication partner.booleanrequireTrust(int minimumTrust)voidsendMessage(byte[] msg)Send a message to the communication partner.voidsetExtraData(java.lang.Object data)Store some arbitrary extra data.voidsetPeerSkiAuthenticated()voidstartTimeout(SpecifiedTimeout which)Start a specific timeout with the default duration.default voidstartTimeout(SpecifiedTimeout which, int seconds)Start a specific timeout with the given duration.voidstartTimeout(SpecifiedTimeout which, int amount, java.util.concurrent.TimeUnit unit)Start a specific timeout with the given duration.default voidstopAllTimeouts()Stop all timeouts.voidstopTimeouts(SpecifiedTimeout... which)Stop one or more timeouts.voidtransitionTo(State next)Transition the state machine.
-
-
-
Method Detail
-
getState
State getState()
- Returns:
- the current state. Mostly useful for handlers that handle multiple states.
-
transitionTo
void transitionTo(State next)
Transition the state machine.- Parameters:
next- which state to enter now
-
enableConnectionDataExchange
void enableConnectionDataExchange()
Enable Connection Data Exchange (it cannot be disabled afterward)
-
closeConnection
void closeConnection()
Close the SPINE connection with no further messaging.
-
sendMessage
void sendMessage(byte[] msg)
Send a message to the communication partner.- Parameters:
msg- the message to send
-
processMessage
void processMessage()
Indicate that the handler is ready to process a waiting message from the communication partner.
-
startTimeout
void startTimeout(SpecifiedTimeout which)
Start a specific timeout with the default duration.- Parameters:
which- which timeout to start.
-
startTimeout
default void startTimeout(SpecifiedTimeout which, int seconds)
Start a specific timeout with the given duration.- Parameters:
which- which timeout to startseconds- how long it should run
-
startTimeout
void startTimeout(SpecifiedTimeout which, int amount, java.util.concurrent.TimeUnit unit)
Start a specific timeout with the given duration.- Parameters:
which- which timeout to startamount- how long it should rununit- the unit foramount
-
increaseTimeout
void increaseTimeout(SpecifiedTimeout which)
Prolong a specific timeout by the initial value.- Parameters:
which- which timeout to prolong
-
increaseTimeout
void increaseTimeout(SpecifiedTimeout which, int extraSeconds)
Prolong a specific timeout.- Parameters:
which- which timeout to prolongextraSeconds- how many seconds to add
-
stopTimeouts
void stopTimeouts(SpecifiedTimeout... which)
Stop one or more timeouts.- Parameters:
which- which timeout(s) to stop.
-
stopAllTimeouts
default void stopAllTimeouts()
Stop all timeouts.
-
getTimeoutStatus
java.lang.Integer getTimeoutStatus(SpecifiedTimeout which)
Query the status of a specific timeout.- Parameters:
which- which timeout to get the status of- Returns:
- time remaining (in seconds), or null if not active.
-
isServerSide
boolean isServerSide()
- Returns:
- whether the caller is on the server side of a connection.
-
requireTrust
boolean requireTrust(int minimumTrust)
- Parameters:
minimumTrust- required trust level- Returns:
- whether the communication partner is trusted at least this much
-
getConfig
Configuration getConfig()
- Returns:
- the configuration for this node
-
getUserInterface
UserInterface getUserInterface()
- Returns:
- the interface to prompt the user about some action
-
setExtraData
void setExtraData(java.lang.Object data)
Store some arbitrary extra data.The handler must be marked with a
StateHandler.UsesExtraDataannotation indicating the type of the extra data it uses.- Parameters:
data- the data to store.
-
getExtraData
<T> T getExtraData(java.lang.Class<T> dataClass)
Retrieve data previously stored withsetExtraData(Object).The handler must be marked with a
StateHandler.UsesExtraDataannotation indicating the type of the extra data it uses.- Type Parameters:
T- type of the data to retrieve- Parameters:
dataClass- class of the data to retrieve- Returns:
- stored data, or null if not present.
-
setPeerSkiAuthenticated
void setPeerSkiAuthenticated()
-
-