|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmassim.agent.AbstractAgent
public abstract class AbstractAgent
This class provides a very simple foundation to agents. It will only connect once (no automatic reconnection). It will authenticate itself and wait for any messages. You can send ping using "sendPing" whenever
Field Summary | |
---|---|
protected javax.xml.parsers.DocumentBuilderFactory |
documentbuilderfactory
|
protected static java.util.logging.Logger |
logger
|
protected java.lang.String |
username
|
Constructor Summary | |
---|---|
AbstractAgent()
|
Method Summary | |
---|---|
void |
agentThread()
Is the main agent's thread. |
boolean |
doAuthentication(java.lang.String username,
java.lang.String password)
Unifies the authentication process. |
static java.lang.String |
getDate()
|
java.lang.String |
getHost()
|
java.lang.String |
getPassword()
|
int |
getPort()
|
java.lang.String |
getUsername()
|
void |
processLogIn()
|
boolean |
processMessage(org.w3c.dom.Element el_message)
This method parses the message received from the server and selects the right action to do next. |
void |
processRequestAction(org.w3c.dom.Element perception,
org.w3c.dom.Element target,
long currenttime,
long deadline)
|
void |
processSimulationEnd(org.w3c.dom.Element perception,
long currenttime)
|
void |
processSimulationStart(org.w3c.dom.Element perception,
long currenttime)
|
boolean |
receiveAuthenticationResult()
Waits for an authentication response from the server. |
org.w3c.dom.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(java.lang.String username,
java.lang.String password)
Provides a easy way for the authentication against a server. |
void |
sendDocument(org.w3c.dom.Document doc)
Sends an specified XML Document to the server. |
void |
setHost(java.lang.String host)
|
void |
setPassword(java.lang.String password)
|
void |
setPort(int port)
|
void |
setUsername(java.lang.String username)
|
void |
start()
Starts the agent main thread. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String username
protected javax.xml.parsers.DocumentBuilderFactory documentbuilderfactory
protected static java.util.logging.Logger logger
Constructor Detail |
---|
public AbstractAgent()
Method Detail |
---|
public static java.lang.String getDate()
public java.lang.String getHost()
public void setHost(java.lang.String host)
public int getPort()
public void setPort(int port)
public java.lang.String getUsername()
public void setUsername(java.lang.String username)
public java.lang.String getPassword()
public void setPassword(java.lang.String password)
public void start()
agentThread
public void sendAuthentication(java.lang.String username, java.lang.String password) throws java.io.IOException
username
- Username of the actual agent.password
- Password associated with the username.
java.io.IOException
- When the conection have not been initialized.public boolean receiveAuthenticationResult() throws java.io.IOException
sendAuthentication
method call.
java.io.IOException
- When the conection have not been initialized.public boolean doAuthentication(java.lang.String username, java.lang.String password) throws java.io.IOException
username
- Username of the actual agent.password
- Password associated with the username.
java.io.IOException
- When the conection have not been initialized.sendAuthentication
,
receiveAuthenticationResult
public byte[] receivePacket() throws java.io.IOException, massim.agent.AbstractAgent.SocketClosedException
java.io.IOException
- When the conection have not been initialized.
SocketClosedException
massim.agent.AbstractAgent.SocketClosedException
public org.w3c.dom.Document receiveDocument() throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException, massim.agent.AbstractAgent.SocketClosedException
receivePacket method
and converts the received data to a XML Document object.
- Returns:
- A valid XML Document object.
- Throws:
org.xml.sax.SAXException
- When the received data is not wellformed.
java.io.IOException
- When the conection have not been initialized.
javax.xml.parsers.ParserConfigurationException
SocketClosedException
massim.agent.AbstractAgent.SocketClosedException
- See Also:
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.
- See Also:
doAuthentication
,
processLogIn
,
receiveDocument
,
processMessage
public boolean processMessage(org.w3c.dom.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(org.w3c.dom.Element perception, org.w3c.dom.Element target, long currenttime, long deadline)
public void processSimulationEnd(org.w3c.dom.Element perception, long currenttime)
public void processSimulationStart(org.w3c.dom.Element perception, long currenttime)
public void processLogIn()
public void sendDocument(org.w3c.dom.Document doc) throws java.io.IOException
doc
- An XML Document object containing the message to send.
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |