Package sudoku
Class Table
- java.lang.Object
-
- akka.actor.typed.Behavior<T>
-
- akka.actor.typed.ExtensibleBehavior<T>
-
- akka.actor.typed.javadsl.AbstractBehavior<Table.Protocol>
-
- sudoku.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Table.AcceptNegotiationsResultsMsg
Message telling that the Player accepted negotiations results.static class
Table.AdditionalInfoMsg
Message received from the Player, consisting of it's subjective weights of requested digits.static class
Table.CreateMsg
Message for creating the Table.static class
Table.IncorrectRegisterException
Custom exception thrown when 4th Player is about to be registered to this table.static interface
Table.InitialisationProtocol
Protocol interface for messages for initialisation strategystatic class
Table.NegotiationsMsg
Abstract class for messages received from the Player during negotiations.static class
Table.OfferMsg
Message received from the Player, consisting of it's subjectively the best digit to be insertedstatic class
Table.PlayerIsDeadMsg
Message received from the Player when agent is about to crash.static interface
Table.Protocol
Protocol interface for input messages.static class
Table.RegisterPlayerMsg
Message for registering a Player.static class
Table.ResetMemoryMsg
Message commanding the agent to reset it's memory due to start of new iteration.static class
Table.WakeUpMsg
Message received from the Teacher when agent is not responding.static class
Table.WithdrawOfferMsg
Message received when the Player withdraws it's present offer.-
Nested classes/interfaces inherited from class akka.actor.typed.Behavior
akka.actor.typed.Behavior.BehaviorDecorators<Inner extends Object>, akka.actor.typed.Behavior.BehaviorDecorators$
-
-
Field Summary
Fields Modifier and Type Field Description private TableMemory
_memory
Structure containing current state of Tableprivate akka.actor.typed.ActorRef<Teacher.Protocol>
_parent
Reference to Table's parent - the Teacherprivate 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.private int
_tableId
Global ID of the Tableprivate Position
_tablePos
Global position of the Table
-
Constructor Summary
Constructors Modifier Constructor Description private
Table(akka.actor.typed.javadsl.ActorContext<Table.Protocol> context, Table.CreateMsg createMsg)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
attemptBestOffer()
Table tries to evaluate the best offer if gathered enough information.static akka.actor.typed.Behavior<Table.Protocol>
create(Table.CreateMsg createMsg)
Public method that calls private constructor.akka.actor.typed.javadsl.Receive<Table.Protocol>
createReceive()
Main method controlling incoming messages.private akka.actor.typed.Behavior<Table.Protocol>
onAcceptNegotiationsResults(Table.AcceptNegotiationsResultsMsg msg)
Table collects accepting messages and finishes negotiations.private akka.actor.typed.Behavior<Table.Protocol>
onAdditionalInfo(Table.AdditionalInfoMsg msg)
Receives requested weighs for given digits.private akka.actor.typed.Behavior<Table.Protocol>
onOffer(Table.OfferMsg msg)
Receives new offer from registered Player.private akka.actor.typed.Behavior<Table.Protocol>
onPlayerIsDead(Table.PlayerIsDeadMsg msg)
Table is being informed that its Player is dead.private Table
onPreRestart()
Handler of PreRestart signal.private akka.actor.typed.Behavior<Table.Protocol>
onRegisterPlayer(Table.RegisterPlayerMsg msg)
Registers new Player to this Table.private akka.actor.typed.Behavior<Table.Protocol>
onResetMemory(Table.ResetMemoryMsg msg)
Table resets it's memory to get ready for new iteration.private akka.actor.typed.Behavior<Table.Protocol>
onWakeUp(Table.WakeUpMsg msg)
Table is being informed that is not enough responsive.private akka.actor.typed.Behavior<Table.Protocol>
onWithdrawOffer(Table.WithdrawOfferMsg msg)
Action on the Player's present offer withdrawal.private void
quitNegotiations()
Ends negotiations irrevocably.private void
withdrawAndInform(int digitColliding)
Register a digit as colliding (denied) and inform proper Players about this fact.-
Methods inherited from class akka.actor.typed.javadsl.AbstractBehavior
getContext, newReceiveBuilder, receive, receiveSignal
-
-
-
-
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
-
-
Constructor Detail
-
Table
private Table(akka.actor.typed.javadsl.ActorContext<Table.Protocol> context, Table.CreateMsg createMsg)
-
-
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 classakka.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
-
-