LectureGame.Test.network_stresstest
Class playerAgent

java.lang.Object
  extended by LectureGame.Test.network_stresstest.playerAgent

public class playerAgent
extends java.lang.Object

Created by IntelliJ IDEA. User: olekrst Date: 04.apr.2007 Time: 10:41:21 A playerAgent instance has the properties of a student client connected to the server, i.e. it has a username with an assiociated password, it has a lecture code which it will send and it will receive and send answers to questions. The agent answers the question randomly and a at a random time during or a litte after the timelimit for answering has passed. This is to emulate that not all answer the question simoultanously. An improvement of this class will be to have better answering heuristics such as a tendency to answer towards the end of the given timelimit.


Nested Class Summary
private static class playerAgent.WorkState
           
 
Field Summary
private  int answerIndex
           
private  int inputState
           
private  java.io.BufferedInputStream is
           
private  java.lang.String lectureCode
           
private  java.lang.String name
           
private  java.io.PrintWriter os
           
private  java.lang.String password
           
private  int protocolState
           
private  java.lang.String quedQuestion
           
private  long replyTimeDelay
           
private  long replyTimer
           
private  java.net.Socket sc
           
private  playerAgent.WorkState state
           
 
Constructor Summary
playerAgent(java.lang.String name, java.lang.String password)
          A player agent is created using by giving her a username and a password.
 
Method Summary
 void close()
          closes the socket and associated streams
 void connect()
          Connects to the server.
 void doWork()
          This is the core method called from the StressTester class on the agent to make it process any availiable indata from the server, or evaluate if it should answer questions
 void login()
          Ehen a client is connected, it must log in to the server using its username and password
private  void parse(java.lang.String received)
          Parses a received string.
private  java.lang.String receive()
          This method is derived directly and unmodified from the receive() method in LectureGame.Core.StudentClient
private  void send(java.lang.String str)
          Sends a string over the socket connection
private  void sendQuestion()
          Sends a question reply over the socket
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private java.lang.String name

password

private java.lang.String password

lectureCode

private java.lang.String lectureCode

sc

private java.net.Socket sc

state

private playerAgent.WorkState state

quedQuestion

private java.lang.String quedQuestion

replyTimeDelay

private long replyTimeDelay

replyTimer

private long replyTimer

os

private java.io.PrintWriter os

is

private java.io.BufferedInputStream is

protocolState

private int protocolState

inputState

private int inputState

answerIndex

private int answerIndex
Constructor Detail

playerAgent

public playerAgent(java.lang.String name,
                   java.lang.String password)
A player agent is created using by giving her a username and a password. The lecture code is hardcoded

Parameters:
name - username of the agent
password - password
See Also:
NamesPasswords
Method Detail

connect

public void connect()
             throws java.io.IOException
Connects to the server. This method must be called on an agent to connect it.

Throws:
java.io.IOException

login

public void login()
Ehen a client is connected, it must log in to the server using its username and password


doWork

public void doWork()
            throws java.io.IOException
This is the core method called from the StressTester class on the agent to make it process any availiable indata from the server, or evaluate if it should answer questions

Throws:
java.io.IOException

receive

private java.lang.String receive()
This method is derived directly and unmodified from the receive() method in LectureGame.Core.StudentClient

Returns:
the string received

parse

private void parse(java.lang.String received)
            throws java.io.IOException
Parses a received string. This is a modified version of the parse() method found in LectureGame.Core.StudentClient. This method handles the playerAgent logic.

Parameters:
received -
Throws:
java.io.IOException

send

private void send(java.lang.String str)
Sends a string over the socket connection

Parameters:
str - the string to be sendt

sendQuestion

private void sendQuestion()
Sends a question reply over the socket


close

public void close()
           throws java.io.IOException
closes the socket and associated streams

Throws:
java.io.IOException