Interface StateHandlerContext

  • All Known Implementing Classes:
    StateMachine

    public interface StateHandlerContext
    This interface encapsulates all the ways in which a StateHandler may interact with the network, the state machine, and the various timers.
    • 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 start
        seconds - 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 start
        amount - how long it should run
        unit - the unit for amount
      • 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 prolong
        extraSeconds - 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.UsesExtraData annotation 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 with setExtraData(Object).

        The handler must be marked with a StateHandler.UsesExtraData annotation 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()