org.netxms.mobile.agent
Class Session

java.lang.Object
  extended by org.netxms.mobile.agent.Session

public class Session
extends java.lang.Object

Communication session with NetXMS server.


Field Summary
static int DEFAULT_CONN_PORT
           
static int PROTOCOL_VERSION
           
 
Constructor Summary
Session(java.lang.String address, int port, java.lang.String deviceId, java.lang.String loginName, java.lang.String password)
           
Session(java.lang.String address, int port, java.lang.String deviceId, java.lang.String loginName, java.lang.String password, boolean useEncryption)
           
Session(java.lang.String address, java.lang.String deviceId, java.lang.String loginName, java.lang.String password)
           
 
Method Summary
 void connect()
          Connect to server.
 void disconnect()
          Disconnect from server
protected  void executeSimpleCommand(int command)
          Execute simple commands (without arguments and only returning RCC)
protected  void finalize()
           
 NXCPMessage newMessage(int code)
          Create new NXCP message with unique id
 void pushDciData(DciPushData[] data)
          Push data to server.
 void pushDciData(long nodeId, long dciId, java.lang.String value)
          Push value for single DCI.
 void pushDciData(java.lang.String nodeName, java.lang.String dciName, java.lang.String value)
          Push value for single DCI.
 void reportDeviceStatus(java.net.InetAddress address, GeoLocation location, int flags, int batteryLevel)
          Report basic current status of the device.
 void reportDeviceSystemInfo(java.lang.String vendor, java.lang.String model, java.lang.String osName, java.lang.String osVersion, java.lang.String serialNumber, java.lang.String userId)
          Report basic system information about mobile device.
 void sendMessage(NXCPMessage msg)
          Send message to server
 void setCommandTimeout(int commandTimeout)
          Set command execution timeout in milliseconds.
 NXCPMessage waitForMessage(int code, long id)
          Wait for message with specific code and id.
 NXCPMessage waitForMessage(int code, long id, int timeout)
          Wait for message with specific code and id.
 NXCPMessage waitForRCC(long id)
          Wait for CMD_REQUEST_COMPLETED message with given id using default timeout
 NXCPMessage waitForRCC(long id, int timeout)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CONN_PORT

public static final int DEFAULT_CONN_PORT
See Also:
Constant Field Values

PROTOCOL_VERSION

public static final int PROTOCOL_VERSION
See Also:
Constant Field Values
Constructor Detail

Session

public Session(java.lang.String address,
               java.lang.String deviceId,
               java.lang.String loginName,
               java.lang.String password)
Parameters:
address -
deviceId -
loginName -
password -

Session

public Session(java.lang.String address,
               int port,
               java.lang.String deviceId,
               java.lang.String loginName,
               java.lang.String password)
Parameters:
address -
port -
deviceId -
loginName -
password -

Session

public Session(java.lang.String address,
               int port,
               java.lang.String deviceId,
               java.lang.String loginName,
               java.lang.String password,
               boolean useEncryption)
Parameters:
address -
port -
deviceId -
loginName -
password -
useEncryption -
Method Detail

finalize

protected void finalize()
Overrides:
finalize in class java.lang.Object

sendMessage

public void sendMessage(NXCPMessage msg)
                 throws java.io.IOException,
                        MobileAgentException
Send message to server

Parameters:
msg - Message to sent
Throws:
java.io.IOException - in case of socket communication failure
MobileAgentException - in case of encryption error

waitForMessage

public NXCPMessage waitForMessage(int code,
                                  long id,
                                  int timeout)
                           throws MobileAgentException
Wait for message with specific code and id.

Parameters:
code -
id -
timeout -
Returns:
Message object
Throws:
MobileAgentException

waitForMessage

public NXCPMessage waitForMessage(int code,
                                  long id)
                           throws MobileAgentException
Wait for message with specific code and id.

Parameters:
code -
id -
Returns:
Message object
Throws:
MobileAgentException

waitForRCC

public NXCPMessage waitForRCC(long id)
                       throws MobileAgentException
Wait for CMD_REQUEST_COMPLETED message with given id using default timeout

Parameters:
id -
Returns:
Throws:
MobileAgentException

waitForRCC

public NXCPMessage waitForRCC(long id,
                              int timeout)
                       throws MobileAgentException
Parameters:
id -
timeout -
Returns:
Throws:
NXCException
MobileAgentException

newMessage

public final NXCPMessage newMessage(int code)
Create new NXCP message with unique id

Parameters:
code - message code
Returns:
new message object

executeSimpleCommand

protected void executeSimpleCommand(int command)
                             throws java.io.IOException,
                                    MobileAgentException
Execute simple commands (without arguments and only returning RCC)

Parameters:
command - Command code
Throws:
java.io.IOException
MobileAgentException

connect

public void connect()
             throws java.io.IOException,
                    java.net.UnknownHostException,
                    MobileAgentException
Connect to server.

Throws:
java.io.IOException
java.net.UnknownHostException
MobileAgentException

disconnect

public void disconnect()
Disconnect from server


setCommandTimeout

public void setCommandTimeout(int commandTimeout)
Set command execution timeout in milliseconds.

Parameters:
commandTimeout -

pushDciData

public void pushDciData(DciPushData[] data)
                 throws java.io.IOException,
                        MobileAgentException
Push data to server.

Parameters:
data - push data
Throws:
java.io.IOException - if socket I/O error occurs
MobileAgentException - if NetXMS server returns an error or operation was timed out

pushDciData

public void pushDciData(long nodeId,
                        long dciId,
                        java.lang.String value)
                 throws java.io.IOException,
                        MobileAgentException
Push value for single DCI.

Parameters:
nodeId - node ID
dciId - DCI ID
value - value to push
Throws:
java.io.IOException - if socket I/O error occurs
MobileAgentException - if NetXMS server returns an error or operation was timed out

pushDciData

public void pushDciData(java.lang.String nodeName,
                        java.lang.String dciName,
                        java.lang.String value)
                 throws java.io.IOException,
                        MobileAgentException
Push value for single DCI.

Parameters:
nodeName - node name
dciName - DCI name
value - value to push
Throws:
java.io.IOException - if socket I/O error occurs
MobileAgentException - if NetXMS server returns an error or operation was timed out

reportDeviceSystemInfo

public void reportDeviceSystemInfo(java.lang.String vendor,
                                   java.lang.String model,
                                   java.lang.String osName,
                                   java.lang.String osVersion,
                                   java.lang.String serialNumber,
                                   java.lang.String userId)
                            throws java.io.IOException,
                                   MobileAgentException
Report basic system information about mobile device. Additional information may be reported via push DCIs.

Parameters:
vendor - vendor name (like "HTC")
model - device model (like "Desire A8181")
osName - operating system name (like "Android")
osVersion - operating system version (like "2.2")
serialNumber - device serial number
userId - user id, if available (can be null)
Throws:
java.io.IOException - if socket I/O error occurs
MobileAgentException - if NetXMS server returns an error or operation was timed out

reportDeviceStatus

public void reportDeviceStatus(java.net.InetAddress address,
                               GeoLocation location,
                               int flags,
                               int batteryLevel)
                        throws java.io.IOException,
                               MobileAgentException
Report basic current status of the device. Additional information may be reported via push DCIs.

Parameters:
address - current IP address of the device (may be null if not known)
location - current device location (may be null if not known)
flags -
batteryLevel - current battery level, -1 if not known or not applicable
Throws:
java.io.IOException - if socket I/O error occurs
MobileAgentException - if NetXMS server returns an error or operation was timed out


Copyright © 2013. All Rights Reserved.