Package sudoku

Class Table


  • public class Table
    extends akka.actor.typed.javadsl.AbstractBehavior<Table.Protocol>
    Table agent, who moderates negotiations between 3 players for choosing the best number in the Sudoku cell. A child of the Teacher agent.
    • Field Detail

      • _tableId

        private final int _tableId
        Global ID of the Table
      • _tablePos

        private final Position _tablePos
        Global position of the Table
      • _memory

        private final TableMemory _memory
        Structure containing current state of Table
      • _players

        private AgentMap<akka.actor.typed.ActorRef<Player.Protocol>> _players
        Map from global Player id to internal index and Player reference Data structure for storing Players - agents registered to this Table.
      • _parent

        private final akka.actor.typed.ActorRef<Teacher.Protocol> _parent
        Reference to Table's parent - the Teacher
    • Method Detail

      • create

        public static akka.actor.typed.Behavior<Table.Protocol> create​(Table.CreateMsg createMsg)
        Public method that calls private constructor. Existence required by Akka.
        Parameters:
        createMsg - message initialising the start of the agent
        Returns:
        wrapped Behavior
      • createReceive

        public akka.actor.typed.javadsl.Receive<Table.Protocol> createReceive()
        Main method controlling incoming messages. Existence required by Akka.
        Specified by:
        createReceive in class akka.actor.typed.javadsl.AbstractBehavior<Table.Protocol>
        Returns:
        wrapped Behavior
      • onRegisterPlayer

        private akka.actor.typed.Behavior<Table.Protocol> onRegisterPlayer​(Table.RegisterPlayerMsg msg)
        Registers new Player to this Table. When a playerId is already registered, it is replaced with the new ActorRef. When a 4th Player is about to be registered, IncorrectRegisterException is thrown. Replies with RegisteredMsg.
        Parameters:
        msg - message for registering new Player
        Returns:
        wrapped Behavior
      • attemptBestOffer

        private void attemptBestOffer()
        Table tries to evaluate the best offer if gathered enough information. If there's not enough information, Table asks Players for it and waits for response. When the best offer is chosen, Table informs all the Players about this.
      • quitNegotiations

        private void quitNegotiations()
        Ends negotiations irrevocably. Sends TableFinishedNegotiationsMsg to the Teacher reporting finish of the negotiations.
      • withdrawAndInform

        private void withdrawAndInform​(int digitColliding)
        Register a digit as colliding (denied) and inform proper Players about this fact.
        Parameters:
        digitColliding - digit to be withdrawn
      • onOffer

        private akka.actor.typed.Behavior<Table.Protocol> onOffer​(Table.OfferMsg msg)
        Receives new offer from registered Player. This action formally starts the negotiations. May reply all Players with RejectOfferMsg.
        Parameters:
        msg - message representing Player's offer of digit to be inputted
        Returns:
        wrapped Behavior
      • onAdditionalInfo

        private akka.actor.typed.Behavior<Table.Protocol> onAdditionalInfo​(Table.AdditionalInfoMsg msg)
        Receives requested weighs for given digits. During this action Table analyses if there is a conflict or not and takes appropriate actions. To prevent synchronization issues Table must check if weighed digit is up to date with Tables's one. May reply all Players with RejectOfferMsg.
        Parameters:
        msg - message representing Player's requested weighs for given digits
        Returns:
        wrapped Behavior
      • onWithdrawOffer

        private akka.actor.typed.Behavior<Table.Protocol> onWithdrawOffer​(Table.WithdrawOfferMsg msg)
        Action on the Player's present offer withdrawal. No reply.
        Parameters:
        msg - message with layer's withdrawal along with withdrawn digit
        Returns:
        wrapped Behavior
      • onAcceptNegotiationsResults

        private akka.actor.typed.Behavior<Table.Protocol> onAcceptNegotiationsResults​(Table.AcceptNegotiationsResultsMsg msg)
        Table collects accepting messages and finishes negotiations. Table may also get declining message, what results in continuing the negotiations. To prevent synchronization issues Table must check if msg._acceptedDigit is up to date with Table's one. May reply to all Players with RejectOfferMsg or NegotiationsFinishedMsg.
        Parameters:
        msg - message with Player's acceptance / decline of present negotiations results.
        Returns:
        wrapped Behavior
      • onResetMemory

        private akka.actor.typed.Behavior<Table.Protocol> onResetMemory​(Table.ResetMemoryMsg msg)
        Table resets it's memory to get ready for new iteration.
        Parameters:
        msg - message from the Teacher
        Returns:
        wrapped Behavior
      • onWakeUp

        private akka.actor.typed.Behavior<Table.Protocol> onWakeUp​(Table.WakeUpMsg msg)
        Table is being informed that is not enough responsive.
        Parameters:
        msg - message from the Teacher
        Returns:
        wrapped Behavior
      • onPlayerIsDead

        private akka.actor.typed.Behavior<Table.Protocol> onPlayerIsDead​(Table.PlayerIsDeadMsg msg)
        Table is being informed that its Player is dead.
        Returns:
        wrapped Behavior
      • onPreRestart

        private Table onPreRestart()
        Handler of PreRestart signal. Expected just before restarting the agent.
        Returns:
        wrapped Behavior