|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.udo.cs.ie.cowbots.arch.massim.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 This code is taken from the MASSim software package. We have to implement the + processRequestAction + processSimulationBegin + processSimulationEnd + processLogIn methods properly. modified verison, supports asynchronous action response messages (author: Thomas)
Nested Class Summary | |
---|---|
private class |
AbstractAgent.SocketClosedException
|
Field Summary | |
---|---|
(package private) org.w3c.dom.Document |
actDoc
|
(package private) org.w3c.dom.Element |
actEl
|
(package private) java.lang.String |
actID
|
(package private) java.util.concurrent.locks.ReentrantLock |
actLock
|
protected javax.xml.parsers.DocumentBuilderFactory |
documentbuilderfactory
|
private java.io.InputStream |
inputstream
|
protected static java.util.logging.Logger |
logger
|
private java.lang.String |
networkhost
|
private int |
networkport
|
private java.io.OutputStream |
outputstream
|
private java.lang.String |
password
|
private java.net.Socket |
socket
|
private java.net.InetSocketAddress |
socketaddress
|
private javax.xml.transform.TransformerFactory |
transformerfactory
|
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 |
sendResponseAction(java.lang.String action)
sends an action 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 |
---|
private int networkport
private java.lang.String networkhost
private java.net.InetSocketAddress socketaddress
private java.net.Socket socket
private java.io.InputStream inputstream
private java.io.OutputStream outputstream
protected java.lang.String username
private java.lang.String password
protected javax.xml.parsers.DocumentBuilderFactory documentbuilderfactory
private javax.xml.transform.TransformerFactory transformerfactory
protected static java.util.logging.Logger logger
java.util.concurrent.locks.ReentrantLock actLock
java.lang.String actID
org.w3c.dom.Document actDoc
org.w3c.dom.Element actEl
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, AbstractAgent.SocketClosedException
java.io.IOException
- When the conection have not been initialized.
AbstractAgent.SocketClosedException
public org.w3c.dom.Document receiveDocument() throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException, 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
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 sendResponseAction(java.lang.String action)
action
- action to sendpublic 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 |