Class Server
java.lang.Object
com.sgware.serialsoc.SerialServerSocket
edu.uky.cs.nil.tt.Server
- All Implemented Interfaces:
com.sgware.serialsoc.CheckedRunnable, AutoCloseable, Callable<Void>
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected SSLSocketaccept(ServerSocket server) protected SSLServerSocketprotected AgentcreateSocket(Socket socket) protected voidexecute(com.sgware.serialsoc.CheckedRunnable runnable) Returns a list of story world/agent pairs that are currently waiting and could be matched immediately.booleanReturns true if this server has beeninstructed to begin shutting down.protected booleanThis method finds a single pair of compatible agents who are waiting for a session and, if one is found, starts a session for them.protected voidThis method tries to find pairs of compatible agents who are waiting for sessions and, if any are found, starts sessions for them.protected voidonClose()protected voidThis method is called each time asessionends.protected voidonException(Exception exception) protected voidprotected voidprotected voidonStop()protected voidtick()This method is called regularly by theclock threadto check things that are time-sensative but not triggered by events, such as disconnecting agents who have taken too long to send a message.Methods inherited from class com.sgware.serialsoc.SerialServerSocket
close, createReader, createWriter, getServerSocket, onStart, runMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sgware.serialsoc.CheckedRunnable
call
-
Field Details
-
log
Used to record system messages and data from completed sessions -
database
A set of story worlds and agent types supported by this server -
port
public final int portThe network port on which the server listens for new connections
-
-
Constructor Details
-
Server
Constructs a server from its various components.- Parameters:
log- the log file where system messages will be recorded, or null if the server should not record a logsessions- the directory where the server should write completed session files, or null if the server should not record session datadatabase- the existing database the server should use (if the file exists), or the file where the server should save its database (if the file does not exist), or null if the server start with an empty database and not save it to fileport- the network port on which the server should listen for new connections- Throws:
IOException- if a problem occurs while reading the various files created or read during setup
-
-
Method Details
-
getStopped
public boolean getStopped()Returns true if this server has beeninstructed to begin shutting down.- Returns:
- true if the server has begun shutting down, false otherwise
-
createServer
- Overrides:
createServerin classcom.sgware.serialsoc.SerialServerSocket- Throws:
IOException
-
accept
- Overrides:
acceptin classcom.sgware.serialsoc.SerialServerSocket- Throws:
IOException
-
createSocket
-
execute
protected void execute(com.sgware.serialsoc.CheckedRunnable runnable) - Overrides:
executein classcom.sgware.serialsoc.SerialServerSocket
-
getAvailable
Returns a list of story world/agent pairs that are currently waiting and could be matched immediately. Only pairs where both the world and agent are publicly listed in the server's database will be returned.- Returns:
- a list of world/agent pairs that are currently waiting for matches
-
onJoin
This method is called each time a newagentsends itsjoinmessage. This method will register the new join request and try tomake matchesbetween pairs of compatible agents.- Parameters:
join- a new agent's join message, specifying the details of its request- Throws:
Exception- if an exception occurs while processing the agent's join request or while making matches between agents
-
makeMatches
-
makeMatch
This method finds a single pair of compatible agents who are waiting for a session and, if one is found, starts a session for them.- Returns:
- true if a compatible pairs of agents was found and a session started, or false if not
- Throws:
Exception- if a problem occurs while matching agents
-
onStart
- Parameters:
world- the story world in which the session will take placegm- the agent playing the game master roleplayer- the agent playing the player role- Throws:
Exception- if a problem occurs while starting the new session
-
tick
This method is called regularly by theclock threadto check things that are time-sensative but not triggered by events, such as disconnecting agents who have taken too long to send a message.- Throws:
Exception- if a problem occurs while this method is running
-
onEnd
This method is called each time asessionends. Note that this method is not called immediately after its story ends, but only after both agents have either acknowledged the end viastopmessages or by disconnecting, which means allreportswill have been logged.- Parameters:
session- the session which has endedgm- the agent playing the role of game master in the ended sessionplayer- the agent playing the role of player in the ended session- Throws:
Exception- if a problem occurs while ending the session
-
onException
- Overrides:
onExceptionin classcom.sgware.serialsoc.SerialServerSocket
-
onClose
protected void onClose()- Overrides:
onClosein classcom.sgware.serialsoc.SerialServerSocket
-
onStop
- Overrides:
onStopin classcom.sgware.serialsoc.SerialServerSocket- Throws:
IOException
-