massim.eismassim
Class Entity

java.lang.Object
  extended by massim.eismassim.Entity
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
CowboysEntity, GoldminersEntity

public abstract class Entity
extends java.lang.Object
implements java.lang.Runnable

This represents an abstract entity. Basically an entity is a structure that represents a connection to the MASSim-Server. Thus is implements the official MASSim client-server communication protocol. Additionally we expect from subclasses of this class to implement methods that identify the type of the entity, and methods that map IILang tokens to XML and vice versa.

Author:
tristanbehrens

Field Summary
protected  java.util.Collection<eis.iilang.Percept> byePercepts
           
protected static javax.xml.parsers.DocumentBuilderFactory documentbuilderfactory
           
protected static EnvironmentInterface ei
           
protected  java.util.AbstractQueue<java.util.Collection<eis.iilang.Percept>> perceptsQueue
           
protected  java.util.Collection<eis.iilang.Percept> requestActionPercepts
           
protected  java.util.Collection<eis.iilang.Percept> simEndPercepts
           
protected  java.util.Collection<eis.iilang.Percept> simStartPercepts
           
protected static javax.xml.transform.TransformerFactory transformerfactory
           
 
Constructor Summary
protected Entity()
          Not supposed to be called by anyone else.
 
Method Summary
protected abstract  org.w3c.dom.Document actionToXML(eis.iilang.Action action)
          Maps an IILang-action to XML.
static void activatePerceptQueue()
           
static void activateStatistics()
           
 boolean authenticate(java.lang.String username, java.lang.String password)
          Sends an authentication-message to the server and waits for the reply.
protected abstract  java.util.Collection<eis.iilang.Percept> byeToIIL(org.w3c.dom.Document document)
          Maps the bye-message (XML) to IILang.
static Entity createEntity(java.lang.String name, java.lang.String scenario, java.lang.String host, int port, java.lang.String username, java.lang.String password)
           
 void enableIILang()
           
static void enableNotifications()
           
static void enableScheduling()
           
static void enableTimeAnnotations()
           
 void enableXML()
           
 void establishConnection()
          Establishes a connection to the MASSim-Server.
 java.util.LinkedList<eis.iilang.Percept> getAllPercepts()
          Yields all percepts or the first one in the queue, if queuing is activated
protected  int getCurrentActionId()
          Yields the current action-id.
 java.lang.String getName()
          Yields the name of the entity.
abstract  java.lang.String getType()
          Yields the type of the entity.
 boolean isConnected()
          Returns true if the entity is connected to the MASSim-server.
 void performAction(eis.iilang.Action action)
          Performs an action.
protected  void println(java.lang.Object obj)
           
 org.w3c.dom.Document receiveDocument()
          Receives a document
protected abstract  java.util.Collection<eis.iilang.Percept> requestActionToIIL(org.w3c.dom.Document document)
          Maps the request-action-message (XML) to IILang.
 void run()
           
static void setEnvironmentInterface(EnvironmentInterface ei)
           
 void setStatistic(Statistic stats)
           
static void setTimeout(int t)
           
protected abstract  java.util.Collection<eis.iilang.Percept> simEndToIIL(org.w3c.dom.Document document)
          Maps the sim-end-message (XML) to IILang.
protected abstract  java.util.Collection<eis.iilang.Percept> simStartToIIL(org.w3c.dom.Document document)
          Maps the sim-start-message (XML) to IILang.
static java.lang.String XMLToString(org.w3c.dom.Node node)
          Converts an XML-node to a simple string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ei

protected static EnvironmentInterface ei

documentbuilderfactory

protected static javax.xml.parsers.DocumentBuilderFactory documentbuilderfactory

transformerfactory

protected static javax.xml.transform.TransformerFactory transformerfactory

simStartPercepts

protected java.util.Collection<eis.iilang.Percept> simStartPercepts

requestActionPercepts

protected java.util.Collection<eis.iilang.Percept> requestActionPercepts

simEndPercepts

protected java.util.Collection<eis.iilang.Percept> simEndPercepts

byePercepts

protected java.util.Collection<eis.iilang.Percept> byePercepts

perceptsQueue

protected java.util.AbstractQueue<java.util.Collection<eis.iilang.Percept>> perceptsQueue
Constructor Detail

Entity

protected Entity()
Not supposed to be called by anyone else. Use factory method instead.

Method Detail

enableXML

public void enableXML()

enableIILang

public void enableIILang()

getName

public java.lang.String getName()
Yields the name of the entity.

Returns:
the name of the entity.

establishConnection

public void establishConnection()
Establishes a connection to the MASSim-Server. Firstly a socket is created. Secondly an authenticication message is sent. Finally an reply from the server is expected.


authenticate

public boolean authenticate(java.lang.String username,
                            java.lang.String password)
Sends an authentication-message to the server and waits for the reply.

Parameters:
username - the username of the cowboy.
password - the password of the cowboy.
Returns:
true on success.

receiveDocument

public org.w3c.dom.Document receiveDocument()
                                     throws java.io.IOException
Receives a document

Returns:
the received document.
Throws:
java.io.IOException - is thrown if reception failed.

println

protected void println(java.lang.Object obj)

createEntity

public static Entity createEntity(java.lang.String name,
                                  java.lang.String scenario,
                                  java.lang.String host,
                                  int port,
                                  java.lang.String username,
                                  java.lang.String password)

getType

public abstract java.lang.String getType()
Yields the type of the entity.

Returns:

getAllPercepts

public java.util.LinkedList<eis.iilang.Percept> getAllPercepts()
                                                        throws eis.exceptions.PerceiveException
Yields all percepts or the first one in the queue, if queuing is activated

Returns:
a linked list containing all percepts or the first one in the queue, if queuing is activated
Throws:
eis.exceptions.ActException
eis.exceptions.PerceiveException

actionToXML

protected abstract org.w3c.dom.Document actionToXML(eis.iilang.Action action)
Maps an IILang-action to XML.

Parameters:
action -
Returns:

simStartToIIL

protected abstract java.util.Collection<eis.iilang.Percept> simStartToIIL(org.w3c.dom.Document document)
Maps the sim-start-message (XML) to IILang.

Parameters:
document -
Returns:

requestActionToIIL

protected abstract java.util.Collection<eis.iilang.Percept> requestActionToIIL(org.w3c.dom.Document document)
Maps the request-action-message (XML) to IILang.

Parameters:
document -
Returns:

simEndToIIL

protected abstract java.util.Collection<eis.iilang.Percept> simEndToIIL(org.w3c.dom.Document document)
Maps the sim-end-message (XML) to IILang.

Parameters:
document -
Returns:

byeToIIL

protected abstract java.util.Collection<eis.iilang.Percept> byeToIIL(org.w3c.dom.Document document)
Maps the bye-message (XML) to IILang.

Parameters:
document -
Returns:

run

public void run()
Specified by:
run in interface java.lang.Runnable

performAction

public void performAction(eis.iilang.Action action)
                   throws eis.exceptions.ActException
Performs an action. The action is fistly transformed to an XML-message. Secondly it is sent off.

Parameters:
action -
Throws:
eis.exceptions.ActException

XMLToString

public static java.lang.String XMLToString(org.w3c.dom.Node node)
Converts an XML-node to a simple string.

Parameters:
node -
Returns:

getCurrentActionId

protected int getCurrentActionId()
Yields the current action-id.

Returns:

isConnected

public boolean isConnected()
Returns true if the entity is connected to the MASSim-server.

Returns:

enableScheduling

public static void enableScheduling()

enableTimeAnnotations

public static void enableTimeAnnotations()

enableNotifications

public static void enableNotifications()

setEnvironmentInterface

public static void setEnvironmentInterface(EnvironmentInterface ei)

setTimeout

public static void setTimeout(int t)

setStatistic

public void setStatistic(Statistic stats)

activateStatistics

public static void activateStatistics()

activatePerceptQueue

public static void activatePerceptQueue()


Copyright © 2012. All Rights Reserved.