com.anwrt.hl.model
Class AwtDataManager

java.lang.Object
  extended by com.anwrt.hl.model.AwtDataManager

public class AwtDataManager
extends java.lang.Object

The AwtDataManager is the entry point of the AWT high level API.
It allows the sending of data and events to the server and the (un)registration of AwtMessageListener.

creation : 3 oct. 2008

Author:
David FRANCOIS

Constructor Summary
AwtDataManager(java.lang.String assetId)
          Returns a new AwtDataManager instance for the assetId given as parameter.
AwtDataManager(java.lang.String assetId, java.lang.String host, int port)
          Returns a new AwtDataManager instance for the assetId given as parameter.
 
Method Summary
 void addAcknowledgment(AwtMessage message, java.lang.Object data, int statusCode)
          add an acknowledgment to the list of message to be sent and serialize it.
 void addContainer(AbstractContainer container)
          Serialized, according to the AwtDaProtocol specification, the container given as parameter and add it to the list of objects to be sent.
 int addContainer(AbstractContainer container, AwtResponseListener listener)
          Serialize, according to the AwtDaProtocol specification, the container given as parameter and add it to the list of objects to be sent.
 void destroy()
          Close the connection with the M2MAgent and release all internal resources.
 void flush()
          Send all added containers and acks to the M2MAgent.
 AwtCom getAwtCom()
          Returns the internal instance of the AwtCom.
 void setMessageListener(java.lang.String relativePath, AwtMessageListener listener, int messageType)
          If listener is not null registers a message listener to the framework for messages to assetId.relativePath and type messageType.
 void start()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AwtDataManager

public AwtDataManager(java.lang.String assetId)
               throws AwtException
Returns a new AwtDataManager instance for the assetId given as parameter.

Parameters:
assetId - AssetId of the asset (i.e the root path of the application).
Throws:
AwtException - if the connection to the M2MAgent fails or if a manager is already registered with the same assetId.

AwtDataManager

public AwtDataManager(java.lang.String assetId,
                      java.lang.String host,
                      int port)
               throws AwtException
Returns a new AwtDataManager instance for the assetId given as parameter.

Parameters:
assetId - AssetId of the asset (i.e the root path of the application).
String - ReadyAgent host name or IP
int - Port of the ReadyAgent to connect to
Throws:
AwtException - if the connection to the M2MAgent fails or if a manager is already registered with the same assetId.
Method Detail

start

public void start()
           throws AwtComException
Throws:
AwtComException

destroy

public void destroy()
Close the connection with the M2MAgent and release all internal resources.


addAcknowledgment

public void addAcknowledgment(AwtMessage message,
                              java.lang.Object data,
                              int statusCode)
                       throws AwtException
add an acknowledgment to the list of message to be sent and serialize it.

Parameters:
message - The message to acknowledge
data - Data of the acknowledgment
statusCode - Status of the Acknowledgment
Throws:
AwtException - If a problem occurred during the serialization.

addContainer

public void addContainer(AbstractContainer container)
                  throws AwtException
Serialized, according to the AwtDaProtocol specification, the container given as parameter and add it to the list of objects to be sent.

Parameters:
container - The container to be sent.
Throws:
AwtException - if the serialization of the container failed.

addContainer

public int addContainer(AbstractContainer container,
                        AwtResponseListener listener)
                 throws AwtException
Serialize, according to the AwtDaProtocol specification, the container given as parameter and add it to the list of objects to be sent. If the second argument is not null, the framework will notify the listener given as parameter that the message has been correctly received.

Parameters:
container - The container to be sent.
listener - The listener to be notified.
Returns:
An unique requestId as int to identify the message to be acknowledged. This int will be passed as argument into the AwtResponseListener.onAck(int, AwtResponse) method.
Throws:
AwtException - if the given listener is null or if the serialization of the container failed.

flush

public void flush()
           throws AwtComException
Send all added containers and acks to the M2MAgent. To force the M2MAgent to send them to the platform server, just call the AwtCom.forceConnectionToServer(com.anwrt.communication.listeners.AwtConnectionStatusListener) method of the M2MAgentConnector.

Throws:
AwtComException - Throws AwtComException if a communication error occurred between the application and the M2MAgent, or if a message can not be serialized.

setMessageListener

public void setMessageListener(java.lang.String relativePath,
                               AwtMessageListener listener,
                               int messageType)
If listener is not null registers a message listener to the framework for messages to assetId.relativePath and type messageType.
If the given listener is null, this method remove a previously registered listener for the given messageType and relativePath. When an incoming message is received, if no listener matches exactly the message path, then the listener with the closest parent-path will be used. For example, an invocation of this method with ("house", listener, AwtMessageListener.SERVER_COMMAND) as parameter will register the listener as command listener for path "house". If a command is received to path "house.living-room" and there is no command listener on this path, the previously registered listener will be called.

Parameters:
relativePath - relative path to listen to or to unregistered.
listener - if not null, the listener to be added.
messageType - MessageType is the type of message to listen to. AwtMessageListener for available messages type.

getAwtCom

public AwtCom getAwtCom()
Returns the internal instance of the AwtCom.

Returns:
Returns the internal instance of the AwtCom.