public abstract class AbstractAgent extends Object
Modifier and Type | Field and Description |
---|---|
protected DocumentBuilderFactory |
documentbuilderfactory |
protected static Logger |
logger |
protected String |
username |
Constructor and Description |
---|
AbstractAgent() |
Modifier and Type | Method and Description |
---|---|
void |
agentThread()
Is the main agent's thread.
|
boolean |
doAuthentication(String username,
String password)
Unifies the authentication process.
|
static String |
getDate() |
String |
getHost() |
String |
getPassword() |
int |
getPort() |
String |
getUsername() |
void |
processLogIn() |
boolean |
processMessage(Element el_message)
This method parses the message received from the server and selects
the right action to do next.
|
void |
processRequestAction(Element perception,
Element target,
long currenttime,
long deadline) |
void |
processSimulationEnd(Element perception,
long currenttime) |
void |
processSimulationStart(Element perception,
long currenttime) |
boolean |
receiveAuthenticationResult()
Waits for an authentication response from the server.
|
Document |
receiveDocument()
Receives a packet from the server using the
receivePacket |
byte[] |
receivePacket()
This method manages the reception of a packet from the server.
|
void |
sendAuthentication(String username,
String password)
Provides a easy way for the authentication against a server.
|
void |
sendDocument(Document doc)
Sends an specified XML Document to the server.
|
void |
setHost(String host) |
void |
setPassword(String password) |
void |
setPort(int port) |
void |
setUsername(String username) |
void |
start()
Starts the agent main thread.
|
protected String username
protected DocumentBuilderFactory documentbuilderfactory
protected static Logger logger
public static String getDate()
public String getHost()
public void setHost(String host)
public int getPort()
public void setPort(int port)
public String getUsername()
public void setUsername(String username)
public String getPassword()
public void setPassword(String password)
public void start()
agentThread
public void sendAuthentication(String username, String password) throws IOException
username
- Username of the actual agent.password
- Password associated with the username.IOException
- When the conection have not been initialized.public boolean receiveAuthenticationResult() throws IOException
sendAuthentication
method call.IOException
- When the conection have not been initialized.public boolean doAuthentication(String username, String password) throws IOException
username
- Username of the actual agent.password
- Password associated with the username.IOException
- When the conection have not been initialized.sendAuthentication
,
receiveAuthenticationResult
public byte[] receivePacket() throws IOException, massim.agent.AbstractAgent.SocketClosedException
IOException
- When the conection have not been initialized.SocketClosedException
massim.agent.AbstractAgent.SocketClosedException
public Document receiveDocument() throws SAXException, IOException, ParserConfigurationException, massim.agent.AbstractAgent.SocketClosedException
receivePacket method
and converts the received data to a XML Document object.
SAXException
- When the received data is not wellformed.IOException
- When the conection have not been initialized.ParserConfigurationException
SocketClosedException
massim.agent.AbstractAgent.SocketClosedException
receivePacket
public void agentThread()
processLogin
method that is an user specified method. And next
it remains in an infininte loop receiving and processing messages from the server.
The messages must start with the message element.
If it encounters any problem with the reception it ends execution.
doAuthentication
,
processLogIn
,
receiveDocument
,
processMessage
public boolean processMessage(Element el_message)
request-action
sim-start
sim-end
el_message
- XML Element object containing the message to process.processRequestAction
,
processSimulationStart
,
processSimulationEnd
,
sendDocument
public void processRequestAction(Element perception, Element target, long currenttime, long deadline)
public void processSimulationEnd(Element perception, long currenttime)
public void processSimulationStart(Element perception, long currenttime)
public void processLogIn()
public void sendDocument(Document doc) throws IOException
doc
- An XML Document object containing the message to send.IOException
Copyright © 2013. All Rights Reserved.