Aggregation APL Functions(3.1)

The following functions may be used in the aggregation APL code. All functions described in the <Analysis Agent section in the Desktop user's guide are also available>.

sessionMirror - Couchbase Storage Only

This function retrieves a list of sessions from the storage specified by the Mirror Profile.

list<session> sessionMirrors ( session)
ParameterDescription

session

This is a built-in variable. For information about session, see Aggregation Variables(3.1).

Returns

A list of mirror sessions.

Note!

The return value always contains one element. The use of the list data type serves to support future requirements. 

Example - Using sessionMirror

sessionInit {    
    session.anum = input.anum;
    session.bnum = input.bnum;
    session.total_duration = 0;                   
}
 
consume {            
    session.total_duration = session.total_duration +  input.duration;
    sessionTimeout(session, 3600);
    //Get mirror sessions
    list<any> allMirrorSessions = sessionMirrors(session);   
// Do not use sessionMirrorLastErrorCode
  // in asynchronous mode.
    if (0 == sessionMirrorLastErrorCode()) {        
        Default.session.session aggregateTotal =  udrClone(session);        
        aggregateTotal.total_duration =  session.total_duration +  getTotalDuration(allMirrorSessions);                
        debug(aggregateTotal.total_duration);
    } else {
       logError("sessionMirrorLastErrorCode:" + sessionMirrorLastErrorCode() + "sessionMirrorLastErrorMessage:" +sessionMirrorLastErrorMessage());
    }       
}
 
timeout{        
    list<any> allMirrorSessions = sessionMirrors(session);
// Do not use sessionMirrorLastErrorCode
 // in asynchronous mode.
    if (0 == sessionMirrorLastErrorCode()) {      
        Default.session.session aggregateTotal =  udrClone(session);
        aggregateTotal.total_duration = session.total_duration +  getTotalDuration(allMirrorSessions); 
        debug(aggregateTotal);
    } else {
        logError("sessionMirrorLastErrorCode:" + sessionMirrorLastErrorCode() + "sessionMirrorLastErrorMessage:" +sessionMirrorLastErrorMessage());
    }
}
 
int getTotalDuration( list<any> allSessions) {
    int total_duration = 0;
    if (1 == listSize(allSessions)) {
        Default.session.session s =  (Default.session.session)listGet(allSessions, 0);
        total_duration = s.total_duration;
    }
    return total_duration;

sessionMirrorLastErrorCode - Couchbase Storage Only

This function returns the error code from the last call to sessionMirrors function.

Note!

You should only use sessionMirrorLastErrorCode when asynchronous mode is disabled, which is the default setting. In asynchronous mode, errors are handled by the Aggregation agent and are not available in APL. For more information about using asynchronous mode, see Aggregation Agent(3.0).

Since sessionMirrors does not return error codes and generally does not cause runtime errors, sessionMirrorLastErrorCode or sessionMirrorLastErrorMessage should be called after each operation to validate success.

int sessionMirrorLastErrorCode () 
ParameterDescription

Returns

0 - All operations were successful.
1 - An operation resulted in an unknown error.
4 - A temporary failure occurred.
5 - An operation timed out.

sessionMirrorLastErrorMessage - Couchbase Storage Only

This function returns the error message from the last call to sessionMirrors function.

Note!

You should only use sessionMirrorLastErrorMessage when asynchronous mode is disabled, which is the default setting. In asynchronous mode, errors are handled by the Aggregation agent and are not available in APL. For more information about using asynchronous mode, see Aggregation Agent(3.0) in the Desktop user's guide.

Since sessionMirrors does not return error codes and generally does not cause runtime errors, sessionMirrorLastErrorCode or sessionMirrorLastErrorMessage should be called after each operation to validate success.

string sessionMirrorLastErrorMessage()
ParameterDescription

Returns

An error message, or null if no error has occurred

Example - Using sessionMirrorLastErrorMessage

sessionInit {
    list<any> allMirrorSessions = sessionMirrors(session);
    if (0 == sessionMirrorLastErrorCode()) {
        //No error            
    } else {
        logError("sessionMirrorLastErrorCode:" + sessionMirrorLastErrorCode() + "sessionMirrorLastErrorMessage:" +sessionMirrorLastErrorMessage());
    }
}


sessionRemove - Batch and Real-Time

Removes the current session.

This function must be called when a session is considered to be closed and a new UDR has been emitted, or when a session is considered to be closed due to an expired timeout.

sessionRemove(session)


ParameterDescription

session

This is a built-in variable. For information about session, see Aggregation Variables(3.1).


sessionTimeout - Batch and Real-Time

Sets a time limit to call the timeout function block or, if not available, the consume block, within the number of seconds specified, or at an exact time. Only one timeout per session may exist, thus if a subsequent call to this function is made, the old timeout is cancelled.

Timeouts are not always called at the exact time stated. See Aggregation Agent(3.0) in the Desktop user's guide for details on when the time limit is actually invoked.

The timeout for a session is cleared each time the consume or timeout function blocks are called.

void sessionTimeout(DRUDR session, long timeOutSeconds)
ParameterDescription

session

This is a built-in variable. For information about session, see Aggregation Variables(3.1).

timeoutSeconds

Number of seconds. If set to 0 (zero) or? null, the timeout is removed. This is? useful if it is desired to reset the timeout to the default? timeout. If set to a negative value, the session will be outdated

sessionTimeout(session, date  timeoutDate )
ParameterDescription

session

This is a built-in variable. For information about session, see Aggregation Variables(3.1).

timeoutDate

An exact date. If set to null, the timeout is removed. This is useful if it is desired to reset the timeout to the default timeout.

If set to a passed date, the session will be outdated.