core
Class Agent

java.lang.Object
  |
  +--core.Agent

public class Agent
extends java.lang.Object

This class represents an agent running a protocol

Author:
Xavier Didelot

Field Summary
private  java.lang.String id
          The identity of the agent as written in the protocol description (for example a or b)
private  java.io.BufferedReader in
          This BufferedReader is used by an host to receive messages that have been sent to him, with the get method
private  java.lang.String ip
          The internet location of the agent (for example booth35.ecs.ox.ac.uk)
private  java.lang.String name
          The name of the agent that is used for example in the KeyStores (for example Alice or Bob)
private  java.io.PrintWriter out
          This PrintWriter is used by an host to send a message to another one, with the put method
private  java.net.Socket socket
          The socket used to communicate with this Agent
 
Constructor Summary
Agent()
          Creates a new empty agent
 
Method Summary
 void contact(java.lang.String url, int port)
          creates a socket connected to (url,port) and use it to communicate with this Agent also sets the in and out accordingly
 java.lang.String get()
          Receive data from this Agent.
 java.lang.String getId()
          Returns the id of this agent
 java.lang.String getIp()
          Return the IP of this Agent
 java.lang.String getName()
          return the name of this agent
 java.net.Socket getSocket()
          Return the Socket that has been allocated to this Agent
 void put(java.lang.String what, int port)
          Send data to this Agent on the given port.
 void setId(java.lang.String string)
          sets the id of this agent
private  void setInAndOut()
          sets the in and out private members according to the socket used
 void setIP(java.lang.String ip)
          Changes the IP of this Agent
 void setName(java.lang.String string)
          sets the name of this agent
 void setSocket(java.net.Socket socket)
          sets the socket used to communicate with this Agent and the in and out accordingly
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

private java.lang.String id
The identity of the agent as written in the protocol description (for example a or b)


ip

private java.lang.String ip
The internet location of the agent (for example booth35.ecs.ox.ac.uk)


name

private java.lang.String name
The name of the agent that is used for example in the KeyStores (for example Alice or Bob)


out

private java.io.PrintWriter out
This PrintWriter is used by an host to send a message to another one, with the put method


in

private java.io.BufferedReader in
This BufferedReader is used by an host to receive messages that have been sent to him, with the get method


socket

private java.net.Socket socket
The socket used to communicate with this Agent

Constructor Detail

Agent

public Agent()
Creates a new empty agent

Method Detail

setIP

public void setIP(java.lang.String ip)
Changes the IP of this Agent

Parameters:
ip - new IP to be allocated to this host

getId

public java.lang.String getId()
Returns the id of this agent

Returns:
the id of this agent

getName

public java.lang.String getName()
return the name of this agent

Returns:
the name of this agent

setId

public void setId(java.lang.String string)
sets the id of this agent

Parameters:
string - new id of this agent

setName

public void setName(java.lang.String string)
sets the name of this agent

Parameters:
string - new name of this agent

setInAndOut

private void setInAndOut()
sets the in and out private members according to the socket used


setSocket

public void setSocket(java.net.Socket socket)
sets the socket used to communicate with this Agent and the in and out accordingly

Parameters:
socket - to use to communicate with this Agent

contact

public void contact(java.lang.String url,
                    int port)
creates a socket connected to (url,port) and use it to communicate with this Agent also sets the in and out accordingly

Parameters:
url - internet name of the host corresponding to this Agent
port - port to use for communication with this Agent

put

public void put(java.lang.String what,
                int port)
Send data to this Agent on the given port. A socket or an IP has to be allocated to this Agent.

Parameters:
what - what has to be sent to the Agent
port - port to use

get

public java.lang.String get()
Receive data from this Agent. A socket has to be allocated to this Agent.

Returns:
the String received from this Agent

getIp

public java.lang.String getIp()
Return the IP of this Agent

Returns:
the IP of this Agent

getSocket

public java.net.Socket getSocket()
Return the Socket that has been allocated to this Agent

Returns:
the Socket that has been allocated to this Agent