Class Server
java.lang.Object
com.sgware.serialsoc.SerialServerSocket
com.sgware.serialsoc.SimpleSerialServerSocket
com.sgware.serialsoc.SecureSerialServerSocket
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()protected voidconnect()protected Agentprotected voidexecute(com.sgware.serialsoc.CheckedRunnable runnable) Returns a list of story world/agent pairs that are currently waiting and could be matched immediately.Returns astatus objectthat summarizes the sessions currently running and agents currently waiting to start sessions.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 voidprotected voidonDisconnect(Agent agent) Everyagentcalls this method exactly once after it hasdisconnectedfrom the server.protected voidThis method is called each time asessionends.protected voidonException(Exception exception) protected voidprotected voidonStart(WorldModel world, Agent gm, Agent player) protected voidonStop()Methods inherited from class com.sgware.serialsoc.SimpleSerialServerSocket
disconnect, getAddress, getPortMethods inherited from class com.sgware.serialsoc.SerialServerSocket
await, close, getStatus, has, onAccept, onConnect, onDisconnect, onStart, run, tickMethods 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
-
-
Constructor Details
-
Server
Constructs a server from its various components.- Parameters:
logs- the directory where system messages will be recorded, or null if the server should not record system logsstatus- the file to which the server's current status will be written, or null if the server should not write its status to filesessions- 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 should 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
-
connect
- Overrides:
connectin classcom.sgware.serialsoc.SimpleSerialServerSocket- Throws:
IOException
-
accept
- Overrides:
acceptin classcom.sgware.serialsoc.SecureSerialServerSocket- Throws:
IOException
-
create
- Overrides:
createin classcom.sgware.serialsoc.SimpleSerialServerSocket- Throws:
IOException
-
execute
protected void execute(com.sgware.serialsoc.CheckedRunnable runnable) - Overrides:
executein classcom.sgware.serialsoc.SerialServerSocket
-
getServerStatus
Returns astatus objectthat summarizes the sessions currently running and agents currently waiting to start sessions. This list will include agents and worlds that are not publicly listed in the database and is not meant to be shown to users.- Returns:
- a server summary
-
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
-
onConnect
-
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 pair 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
-
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
-
onDisconnect
Everyagentcalls this method exactly once after it hasdisconnectedfrom the server.- Parameters:
agent- the agent that has just disconnected- Throws:
Exception- if a problem occurs while handling the disconnection
-
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
-