project BLF > class BBaseDaemon > method ApiMonitor
Description
Api-method to monitor the fcDaemonQueue records.
Parameters
ilIncludeWaiting | input | logical | Include DaemonQueue records of DaemonQueueStatus Waiting |
ilIncludeInProcess | input | logical | Include DaemonQueue records of DaemonQueueStatus InProcess |
ilIncludeProcessedOk | input | logical | Include DaemonQueue records of DaemonQueueStatus Processed-Ok |
ilIncludeProcessedErr | input | logical | Include DaemonQueue records of DaemonQueueStatus Processed-Err |
tfcDaemonMonitor | output | temp-table | |
tfcDaemonQueueMonitor | output | temp-table | |
tfcDaemonQueueLogMonitor | output | temp-table | |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
unused
program code (program3/bbasedaemon.p)
/* ================================================================================================== */
/* We use a hard-coded value to retriev3e max 1000 rows */
/* This is to avoid that the Monitor function freezes onces there are plentry of records in the queue */
/* ================================================================================================== */
assign viMaxRowsToDownLoad = 1000
viRowsToDownLoad = viMaxRowsToDownLoad.
/* Find information about the Daemon */
<Q-1 run DaemonInfo (all) (Read) (NoCache)
(input ?, (DaemonId)
input vcFcDaemonName, (DaemonName)
input ?, (DaemonStatus)
input ?, (DaemonStatusDiffersFrom)
output dataset tqDaemonInfo) in BBaseDaemon >
find first tqDaemonInfo where
tqDaemonInfo.tcDaemonName = vcFcDaemonName
no-error.
if not available tqDaemonInfo
then do:
<M-2 run SetMessage
(input trim(#T-48'This daemon has not yet been configured. You must configure the daemon before it can be started or monitored.':255(50)T-48#) (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-6':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemon>
assign oiReturnStatus = -1.
return.
end.
/* Clear the output temp-tables */
empty temp-table tfcDaemonMonitor.
empty temp-table tfcDaemonQueueMonitor.
empty temp-table tfcDaemonQueueLogMonitor.
/* Fill output table for fcDaemon */
create tfcDaemonMonitor.
buffer-copy tqDaemonInfo to tfcDaemonMonitor.
assign tfcDaemonMonitor.tiDaemonQueueWaiting = 0.
/* Read Waiting records */
<Q-21 run DaemonQueueByDaemonID (all) (Read) (NoCache)
(input tqDaemonInfo.tiDaemonId, (DaemonID)
input {&DAEMONQUEUESTATUS-WAITING}, (DaemonQueueStatus)
output dataset tqDaemonQueueByDaemonID) in BBaseDaemonQueue>
/* Count the Queues in WAITING */
for each tqDaemonQueueByDaemonID where
tqDaemonQueueByDaemonID.tiDaemonId = tqDaemonInfo.tiDaemonId and
tqDaemonQueueByDaemonID.tcDaemonQueueStatus = {&DAEMONQUEUESTATUS-WAITING}:
assign tfcDaemonMonitor.tiDaemonQueueWaiting = tfcDaemonMonitor.tiDaemonQueueWaiting + 1.
end. /* for each tqDaemonQueueByDaemonID */
if ilIncludeWaiting
then do:
/* Read Waiting records */
<Q-17 run DaemonQueueByDaemonID (firstviRowsToDownLoad) (Read) (NoCache)
(input tqDaemonInfo.tiDaemonId, (DaemonID)
input {&DAEMONQUEUESTATUS-WAITING}, (DaemonQueueStatus)
output dataset tqDaemonQueueByDaemonID) in BBaseDaemonQueue>
for each tqDaemonQueueByDaemonID where
tqDaemonQueueByDaemonID.tiDaemonId = tqDaemonInfo.tiDaemonId and
tqDaemonQueueByDaemonID.tcDaemonQueueStatus = {&DAEMONQUEUESTATUS-WAITING}:
create tfcDaemonQueueMonitor.
buffer-copy tqDaemonQueueByDaemonID to tfcDaemonQueueMonitor.
assign viRowsToDownLoad = viRowsToDownLoad - 1.
end. /* for each tqDaemonQueueByDaemonID */
end. /* if ilIncludeWaiting */
/* Read In Process records if necessary */
if ilIncludeInProcess and viRowsToDownLoad > 0
then do:
<Q-14 run DaemonQueueByDaemonID (firstviRowsToDownLoad) (Read) (NoCache)
(input tqDaemonInfo.tiDaemonId, (DaemonID)
input {&DAEMONQUEUESTATUS-INPROCESS}, (DaemonQueueStatus)
output dataset tqDaemonQueueByDaemonID) in BBaseDaemonQueue>
for each tqDaemonQueueByDaemonID where
tqDaemonQueueByDaemonID.tiDaemonId = tqDaemonInfo.tiDaemonId and
tqDaemonQueueByDaemonID.tcDaemonQueueStatus = {&DAEMONQUEUESTATUS-INPROCESS}:
create tfcDaemonQueueMonitor.
buffer-copy tqDaemonQueueByDaemonID to tfcDaemonQueueMonitor.
assign viRowsToDownLoad = viRowsToDownLoad - 1.
end.
end. /* if ilIncludeInProcess */
/* Read Processed OK records if necessary */
if ilIncludeProcessedOk and viRowsToDownLoad > 0
then do:
<Q-97 run DaemonQueueByDaemonID (firstviRowsToDownLoad) (Read) (NoCache)
(input tqDaemonInfo.tiDaemonId, (DaemonID)
input {&DAEMONQUEUESTATUS-PROCESSEDOK}, (DaemonQueueStatus)
output dataset tqDaemonQueueByDaemonID) in BBaseDaemonQueue>
for each tqDaemonQueueByDaemonID where
tqDaemonQueueByDaemonID.tiDaemonId = tqDaemonInfo.tiDaemonId and
tqDaemonQueueByDaemonID.tcDaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDOK}:
create tfcDaemonQueueMonitor.
buffer-copy tqDaemonQueueByDaemonID to tfcDaemonQueueMonitor.
assign viRowsToDownLoad = viRowsToDownLoad - 1.
end.
end. /* if ilIncludeProcessedOk */
/* Read Processed Error records if necessary */
if ilIncludeProcessedErr and viRowsToDownLoad > 0
then do:
<Q-79 run DaemonQueueByDaemonID (firstviRowsToDownLoad) (Read) (NoCache)
(input tqDaemonInfo.tiDaemonId, (DaemonID)
input {&DAEMONQUEUESTATUS-PROCESSEDERR}, (DaemonQueueStatus)
output dataset tqDaemonQueueByDaemonID) in BBaseDaemonQueue>
for each tqDaemonQueueByDaemonID where
tqDaemonQueueByDaemonID.tiDaemonId = tqDaemonInfo.tiDaemonId and
tqDaemonQueueByDaemonID.tcDaemonQueueStatus = {&DAEMONQUEUESTATUS-PROCESSEDERR}:
create tfcDaemonQueueMonitor.
buffer-copy tqDaemonQueueByDaemonID to tfcDaemonQueueMonitor.
assign viRowsToDownLoad = viRowsToDownLoad - 1.
<Q-44 run DaemonQueueLogByDaemonQueueId (all) (Read) (NoCache)
(input tqDaemonQueueByDaemonID.tiDaemonQueueId, (DaemonQueueId)
output dataset tqDaemonQueueLogByDaemonQueueId) in BBaseDaemonQueue >
for each tqDaemonQueueLogByDaemonQueueId where
tqDaemonQueueLogByDaemonQueueId.tiDaemonQueueId = tqDaemonQueueByDaemonID.tiDaemonQueueId:
create tfcDaemonQueueLogMonitor.
buffer-copy tqDaemonQueueLogByDaemonQueueId to tfcDaemonQueueLogMonitor.
end.
end.
end. /* if ilIncludeProcessedErr */
if viRowsToDownLoad <= 0
then do :
create tfcDaemonQueueMonitor.
assign tfcDaemonQueueMonitor.tiDaemonId = tfcDaemonMonitor.tiDaemonId
tfcDaemonQueueMonitor.tcDaemonQueueStatus = 'INFO'
tfcDaemonQueueMonitor.tcDaemonQueueRefDescription = substitute (#T-87'Note: only the first &1 queues are shown.':255(87800615)T-87#,viMaxRowsToDownLoad).
end.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BBaseDaemon".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiMonitor".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bbasedaemon.apimonitor.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::ilIncludeWaiting = <parameter value>
vhParameter::ilIncludeInProcess = <parameter value>
vhParameter::ilIncludeProcessedOk = <parameter value>
vhParameter::ilIncludeProcessedErr = <parameter value>.
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.