eWON JTK

com.ewon.ewonitf
Class ScheduledActionManager

java.lang.Object
  extended by com.ewon.ewonitf.ScheduledActionManager

public class ScheduledActionManager
extends Object

This static class is used to execute scheduled actions like: send and email, send an SMS etc.


Method Summary
static void clearPendingActions()
          Clear any pending action in the scheduled action manager which has NOT been started yet.
static int DynDnsUpdate()
          Use the Scheduled Action Manager to send synchronize the eWON online IP address with a dynamic DNS server like NO-IP.
The function will push the request in the Scheduled Action Manager queue.
static int getActionLogSize()
          Read the number of actions in the scheduled action log.
static int GetFtp(String ServerSideFile, String eWonSideFile, String CnxParam)
          Use the Scheduled Action Manager to read a file by FTP.
See also BASIC GETFTP command documentation.
static int GetHttp(String CnxParam, String FileName, String FileUrl)
          Use the Scheduled Action Manager to read an HTTP content.
See also BASIC GETHTTP command documentation.
static int getNextActionId()
          Read the Id of the next action that will be created.
static int NtpSync()
          Use the Scheduled Action Manager to Posts a request for clock re-synchronization
The function will push the request in the Scheduled Action Manager queue.
static int PutFtp(String FileName, String Content, String CnxParam)
          Use the Scheduled Action Manager to send data by FTP.
The function will push the eMail request in the Scheduled Action Manager queue.
static int PutHttp(String CnxParam, String UrlForm, String TextFields, String FileFields, String Response)
          Use the Scheduled Action Manager to post an HTTP form.
See also BASIC PUTHTTP command documentation.
static ScheduledAction readAction(int actionNdx)
          Read an action from the scheduled action log defined by its index in the list.
static ScheduledAction[] readActionLog()
          Read an array of ScheduledAction with all the actions in the scheduled action log.
static int RequestHttpX(String CnxParam, String Method, String Headers, String TextFields, String FileFields, String FileName)
          Use the Scheduled Action Manager to trigger a complete custom HTTP request.
See also BASIC REQUESTHTTPX command documentation.
static ScheduledAction searchAction(int actionId)
          Read an action from the scheduled action log defined by its ID
static int SendMail(String FromSrc, String ToDest, String CcDest, String Subject, String Content)
          Use the Scheduled Action Manager to send an eMail.
The function will push the eMail request in the Scheduled Action Manager queue.
static int SendSMSAction(String SMSDest, String Message)
          Use the Scheduled Action Manager to send an SMS.
See also BASIC SENDSMS command documentation.
static int SensSMSAction(String SMSDest, String Message)
          For compatibility - see SendSMSAction .
See also BASIC SENDSMS command documentation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

SendMail

public static int SendMail(String FromSrc,
                           String ToDest,
                           String CcDest,
                           String Subject,
                           String Content)
                    throws EWException
Use the Scheduled Action Manager to send an eMail.
The function will push the eMail request in the Scheduled Action Manager queue. Then the function will block until the request has finished (failing or succeeding). The operation's result is returned.
Implementation remark: the function will not block all threads (see eWON asynchronous operations)

Parameters:
FromSrc - The eMail address of the person sending the message
ToDest - The eMail address list of recipient. Each email address must be separated by ','
CcDest - The eMail address list of CC recipient. Each email address must be separated by ','
Subject - The text containing the eMail subject
Content - The is the eMail text content. The dynamic eMail content syntaxt is usable and described in detail in the eWON manual (export block descriptors inlined and attached to emails).
Returns:
result of operation (0 means no error, -1 means in progress, -2 means reporting not found - unknown result, positive value is the error code.

Example: SendMail("your_email@example.com","dest1@example.com,dest2@example.com","","Your Subject","The message");
This is an example with 2 recipients and no CC.

Throws:
EWException

PutFtp

public static int PutFtp(String FileName,
                         String Content,
                         String CnxParam)
                  throws EWException
Use the Scheduled Action Manager to send data by FTP.
The function will push the eMail request in the Scheduled Action Manager queue. Then the function will block until the request has finished (failing or succeeding). The operation's result is returned.
Implementation remark: the function will not block all threads (see eWON asynchronous operations)

Parameters:
FileName - The destination file name (leave empty if sending multiple files)
Content - The destination file content. This content follows a special syntax allowing including EXPORT_BLOCK_DESCRIPTOR contents
CnxParam - The connection name
Standard Cnx definition format is: [user:password@]servername[:port][,option1]
If CnxParam is an empty string ("") then the config's FTP server definition is used.
Examples:
user:pass@server.com:25,1 (,1 means passive mode enabled)
server.com:25,1
server.com,1
server.com:25
user:pass@server.com
user:pass@server.com,1
user:pass@server.com:25
Invalid
user@server.com:25,1 (password not specifed)

Example: PutFtp("/ewon1/events","[$dtEV]","adm:adm@10.0.0.53:21,1");
This example will connect to 10.0.0.53 in passive mode.

Throws:
EWException

GetFtp

public static int GetFtp(String ServerSideFile,
                         String eWonSideFile,
                         String CnxParam)
                  throws EWException
Use the Scheduled Action Manager to read a file by FTP.
See also BASIC GETFTP command documentation.

Throws:
EWException

PutHttp

public static int PutHttp(String CnxParam,
                          String UrlForm,
                          String TextFields,
                          String FileFields,
                          String Response)
                   throws EWException
Use the Scheduled Action Manager to post an HTTP form.
See also BASIC PUTHTTP command documentation.

Throws:
EWException

GetHttp

public static int GetHttp(String CnxParam,
                          String FileName,
                          String FileUrl)
                   throws EWException
Use the Scheduled Action Manager to read an HTTP content.
See also BASIC GETHTTP command documentation.

Throws:
EWException

RequestHttpX

public static int RequestHttpX(String CnxParam,
                               String Method,
                               String Headers,
                               String TextFields,
                               String FileFields,
                               String FileName)
                        throws EWException
Use the Scheduled Action Manager to trigger a complete custom HTTP request.
See also BASIC REQUESTHTTPX command documentation.

Throws:
EWException

SendSMSAction

public static int SendSMSAction(String SMSDest,
                                String Message)
                         throws EWException
Use the Scheduled Action Manager to send an SMS.
See also BASIC SENDSMS command documentation.

Throws:
EWException

SensSMSAction

public static int SensSMSAction(String SMSDest,
                                String Message)
                         throws EWException
For compatibility - see SendSMSAction .
See also BASIC SENDSMS command documentation.

Throws:
EWException

DynDnsUpdate

public static int DynDnsUpdate()
                        throws EWException
Use the Scheduled Action Manager to send synchronize the eWON online IP address with a dynamic DNS server like NO-IP.
The function will push the request in the Scheduled Action Manager queue. Then the function will block until the request has finished (failing or succeeding). The operation's result is returned.

Throws:
EWException

NtpSync

public static int NtpSync()
                   throws EWException
Use the Scheduled Action Manager to Posts a request for clock re-synchronization
The function will push the request in the Scheduled Action Manager queue. Then the function will block until the request has finished (failing or succeeding). The operation's result is returned.

Throws:
EWException

clearPendingActions

public static void clearPendingActions()
Clear any pending action in the scheduled action manager which has NOT been started yet.


readAction

public static ScheduledAction readAction(int actionNdx)
Read an action from the scheduled action log defined by its index in the list.

Parameters:
actionNdx - The index of the action in the action log.

The index starts at 0 and goes up to getActionLogSize.

Important: the log is a circular buffer, so action with index 0 is not often the oldest one.

Returns:
a ScheduledAction object.

This object has a number of properties describing the action.


searchAction

public static ScheduledAction searchAction(int actionId)
Read an action from the scheduled action log defined by its ID

Parameters:
actionId - The eWON has a global counter which is increased at every new action. When a new action is created it receives the current actionId. The actionId is different for every new action, it can then be used to return information on a specific action.

If the last action must be fetched getNextActionId() can be used (-1 for last action)

The following example shows how to read the whole log from the last action and print som info .

  int actionLogSize = ScheduledActionManager.getActionLogSize();
  int nextActionId  = ScheduledActionManager.getNextActionId();
  while ((actionLogSize--)>=0)
  {
     nextActionId--;
     try
     {
        ScheduledAction scheduledAction = ScheduledActionManager.readAction(nextActionId);
        System.out.println("Id: "+scheduledAction.getId()+" ---------------------------");
        System.out.println("TypeStr: "+scheduledAction.getTypeAsString());
     }
     catch (Exception e)
     {
        System.out.println("Error readSamTest: "+e.toString());
     }
  }
 
Returns:
a ScheduledAction object.

This object has a number of properties describing the action.


readActionLog

public static ScheduledAction[] readActionLog()
Read an array of ScheduledAction with all the actions in the scheduled action log.

Returns:
array of ScheduledAction.

This array is ordered from the newer action to the oldests (ie from the higher action id to the smaller).


getNextActionId

public static int getNextActionId()
Read the Id of the next action that will be created.

Returns:
The next ActionId that will be allocated to the following scheduled action.
An action ID is created for every new action created (Send SMS, Put FTP, etc...) this Id is increased by 1 after each new action and it is only reset when the eWON is rebooted.

getActionLogSize

public static int getActionLogSize()
Read the number of actions in the scheduled action log.

This function is used with readAction(int) to known the number of actions that can be feteched.

This number is limited by the size of the Action Log.

Returns:
The number of actions in the scheduled actions list.

eWON JTK

www.eWON.biz: Your Eyes Watching Over Net