com.anwrt.communication.connector
Class AwtCom

java.lang.Object
  extended by com.anwrt.communication.connector.AwtCom

public final class AwtCom
extends java.lang.Object

The AwtCom is the connector that allows an application to connect as a client to the M2MAgent.

creation : 26 sept. 2008

Author:
David FRANCOIS

Field Summary
static java.lang.String PATH_SEPARATOR
          PATH_SEPARATOR constant
 
Method Summary
 void connect()
           
 void destroy()
          Close the connection with the M2MAgent
 void forceConnectionToServer(AwtConnectionStatusListener listener)
          Force the connection between M2MAgent and the M2M server.
 int getNextTicketId()
          Returns the next ticket id.
 java.util.List getVariable(java.lang.String path, java.lang.Integer level)
          Retrieves a set of variables from M2MAgent.
static AwtCom initialize(java.lang.String assetId)
          Initializes the library with default values and opens a connection to the M2MAgent.
static AwtCom initialize(java.lang.String assetId, java.lang.String host, int port)
          Initializes the library with given parameters and opens a connection to the M2MAgent.
 boolean isConnected()
           
 int notifySoftwareUpdateResult(java.lang.String spackage, int resultCode)
          Notify a software update result for the given package to the M2MAgent
 int notifyVariable(java.lang.String path)
          Notify variable of the core Agent
 void registerDataListener(AwtDataListener listener)
          Register a DataListener.
 int registerVariable(java.lang.String path)
          Register variable of the core Agent
 int sendMessages(byte[] buffer)
          Send the buffer given as parameter to the M2MAgent.
 int sendSMS(java.lang.String recipient, byte[] payload)
          Send a SMS message to the given recipient.
 int setSMSListener(AwtSMSListener listener, java.lang.String pattern)
          Set the given listener as a SMSListener.
 void setSoftwareListener(AwtSofwareUpdateListener listener, java.lang.String path)
          If not null, set the AwtSofwareUpdateListener listener for the given path.
 int setVariable(java.lang.String path, java.lang.Object value)
          Set variable of the core Agent
 void unregisterDataListener(AwtDataListener dataListener)
          Unregister a DataListener.
 int unsetSMSListener()
          Unset the current SMSListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_SEPARATOR

public static final java.lang.String PATH_SEPARATOR
PATH_SEPARATOR constant

See Also:
Constant Field Values
Method Detail

connect

public void connect()
             throws AwtComException
Throws:
AwtComException

initialize

public static AwtCom initialize(java.lang.String assetId)
                         throws AwtComException
Initializes the library with default values and opens a connection to the M2MAgent.

Parameters:
assetId - client's assetId.
Returns:
a new instance of an AwtCom if the connection succeed, throws an AwtComException otherwise
Throws:
AwtComException - Throws AwtComException if the connection to the M2MAgent failed.

initialize

public static AwtCom initialize(java.lang.String assetId,
                                java.lang.String host,
                                int port)
                         throws AwtComException
Initializes the library with given parameters and opens a connection to the M2MAgent.

Parameters:
assetId - client's assetId.
String - ReadyAgent host name or IP
int - Port of the ReadyAgent to connect to
Returns:
a new instance of an AwtCom if the connection succeed, throws an AwtComException otherwise
Throws:
AwtComException - Throws AwtComException if the connection to the M2MAgent failed.

destroy

public void destroy()
Close the connection with the M2MAgent


getNextTicketId

public int getNextTicketId()
Returns the next ticket id.

Returns:
the next ticket id.

sendMessages

public int sendMessages(byte[] buffer)
                 throws AwtComException
Send the buffer given as parameter to the M2MAgent.

Parameters:
buffer - buffer of serialized data.
Returns:
0 if the result is correctly sent, an error code otherwise
Throws:
AwtComException - Throws M2MAgentException if the connection with the M2MAgent or if an IOException occurred.

getVariable

public java.util.List getVariable(java.lang.String path,
                                  java.lang.Integer level)
                           throws AwtComException
Retrieves a set of variables from M2MAgent.

Parameters:
path - is the path of the variable to retrieve
level - is the recursive level to retrieve variable in the tree, default is 0 (no recusivity)
Returns:
null an error occurred or results as a map
Throws:
AwtComException - if the connection with the M2MAgent is lost.

setVariable

public int setVariable(java.lang.String path,
                       java.lang.Object value)
                throws AwtComException
Set variable of the core Agent

Parameters:
path - path of the variable to set
value - is the value of the variable (can be a table, in that case it will actually set a whole sub tree (several variables at once))
Returns:
0 if the result is correctly sent, an error code otherwise
Throws:
AwtComException - Throws M2MAgentException if the connection with the M2MAgent or if an IOException occurred.

registerVariable

public int registerVariable(java.lang.String path)
                     throws AwtComException
Register variable of the core Agent

Parameters:
path - path of the variable to register
Returns:
0 if the result is correctly sent, an error code otherwise
Throws:
AwtComException - Throws M2MAgentException if the connection with the M2MAgent or if an IOException occurred.

notifyVariable

public int notifyVariable(java.lang.String path)
                   throws AwtComException
Notify variable of the core Agent

Parameters:
path - path of the variable to notify
Returns:
0 if the result is correctly sent, an error code otherwise
Throws:
AwtComException - Throws M2MAgentException if the connection with the M2MAgent or if an IOException occurred.

sendSMS

public int sendSMS(java.lang.String recipient,
                   byte[] payload)
            throws AwtComException
Send a SMS message to the given recipient.

Parameters:
recipient - recipient of the message.
payload - Message payload.
Returns:
0 if the sms is correctly sent, an error code otherwise
Throws:
AwtComException - Throws M2MAgentException if the connection with the M2MAgent or if an IOException occurred.

forceConnectionToServer

public void forceConnectionToServer(AwtConnectionStatusListener listener)
                             throws AwtComException
Force the connection between M2MAgent and the M2M server. As a consequence all data which are not sent yet will be sent as soon as possible.

Parameters:
listener - The optional listener to be notified of the communication status.
Throws:
AwtComException - Throws AwtComException if the connection with the M2MAgent is lost or if an IOException occurred.

notifySoftwareUpdateResult

public int notifySoftwareUpdateResult(java.lang.String spackage,
                                      int resultCode)
                               throws AwtComException
Notify a software update result for the given package to the M2MAgent

Parameters:
spackage - The software package
resultCode - update result
Returns:
0 if the result is correctly sent, an error code otherwise
Throws:
AwtComException - if the connection with the M2MAgent is lost or if an IOException occurred.

registerDataListener

public void registerDataListener(AwtDataListener listener)
Register a DataListener. The listener given as parameter will be notified of all the messages which are intended to him.

Parameters:
listener - listener to be added.

unregisterDataListener

public void unregisterDataListener(AwtDataListener dataListener)
Unregister a DataListener.

Parameters:
dataListener - listener to be removed.

setSoftwareListener

public void setSoftwareListener(AwtSofwareUpdateListener listener,
                                java.lang.String path)
If not null, set the AwtSofwareUpdateListener listener for the given path. If null remove the AwtSofwareUpdateListener listener for the given path.

Parameters:
listener - the AwtSofwareUpdateListener to be registered.
path - the AwtSofwareUpdateListener path to listen to.

unsetSMSListener

public int unsetSMSListener()
                     throws AwtComException
Unset the current SMSListener

Returns:
0 if the listener is correctly unset, an error code otherwise
Throws:
AwtComException - Throws an AwtComException if the connection to the M2Magent is lost.

setSMSListener

public int setSMSListener(AwtSMSListener listener,
                          java.lang.String pattern)
                   throws AwtComException
Set the given listener as a SMSListener.
This listener will be notified of incoming SMS matching the pattern given as second parameter. Pattern must be conformed to lua pattern specification

Parameters:
listener - Listener to be notified. If null, current listener will be unsetted.
pattern - Pattern that recipient number must match. If null or empty string, current listener will be unsetted.
Returns:
0 if the listener is correctly set, an error code otherwise
Throws:
AwtComException - Throws an AwtComException if the connection to the M2Magent is lost.

isConnected

public boolean isConnected()