project BLF > class BBaseDaemonQueue > method ApiClearDaemonQueue
Description
ApiClearDaemonQueue; this Api-method allows users to clean-up a Queue of a certain daemon (identified by its ID or Name).
A set of input parameters allows the user to specify the details of the clean-up action.
General remarks;
This method starts by cleaning everything that was in this instance to make sure we start from scratch. This method also contains a DateSave; this implies that this code will be committed in case this component was started with &AddToTransAction=True
In case only Warnings (ReturnStatus>0) are created then
- the transaction will be committed,
- the warnings will be retuned to the caller via FcMessages
Parameters
iiDaemonID | input | integer | DaemonID |
icDaemonName | input | character | DaemonName |
ilDeleteWaiting | input | logical | Delete DaemonQueue records with status Waiting |
ilDeleteInProcess | input | logical | Delete DaemonQueue records with status InProcess |
ilDeleteProcessedOk | input | logical | Delete DaemonQueue records with status Processed-Ok |
ilDeleteProcessedErr | input | logical | Delete DaemonQueue records with status Processed-Err |
olDeletesExecuted | output | logical | Deletes Executed (Yes/No) |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
BLF
program code (program3/bbasedaemonqueue.p)
/* ========================================================================== */
/* General remark; */
/* This method contains a DataSave; this implies that this code will be */
/* committed in case this component was started with &AddToTransAction=True */
/* In case only Warnings (ReturnStatus>0) are created then */
/* - the transaction will be committed, */
/* - the physical files will be removed (if applicable) */
/* - the warnings will be retuned to the caller via FcMessages */
/* ========================================================================== */
/* Initialize */
assign vcMessage = ""
olDeletesExecuted = false.
if iiDaemonID = ?
then assign iiDaemonID = 0.
if icDaemonName = ?
then assign icDaemonName = "".
if ilDeleteWaiting = ?
then assign ilDeleteWaiting = false.
if ilDeleteInProcess = ?
then assign ilDeleteInProcess = false.
if ilDeleteProcessedOk = ?
then assign ilDeleteProcessedOk = false.
if ilDeleteProcessedErr = ?
then assign ilDeleteProcessedErr = false.
if ilDeleteInProcess = false and
ilDeleteProcessedErr = false and
ilDeleteProcessedOk = false and
ilDeleteWaiting = false
then return.
/* Validate input parameters */
if iiDaemonID = 0
then do:
if icDaemonName = ""
then assign vcMessage = trim(#T-11'Daemon ID or daemon name should be specified for the cleanup of a daemon queue.':255(32)T-11#).
else do:
<Q-1 run DaemonPrim (all) (Read) (NoCache)
(input icDaemonName, (DaemonName)
input ?, (DaemonId)
output dataset tqDaemonPrim) in BBaseDaemon >
find tqDaemonPrim where
tqDaemonPrim.tcDaemonName = icDaemonName
no-error.
if not available tqDaemonPrim
then assign vcMessage = trim(subst(#T-12'Unable to find the daemon based on its name (&1).':255(33)T-12#, icDaemonName)).
else assign iiDaemonID = tqDaemonPrim.tiDaemonId.
end.
end.
if vcMessage <> ""
then do:
<M-2 run SetMessage
(input vcMessage (icMessage),
input '' (icArguments),
input '' (icFieldName),
input '' (icFieldValue),
input 'E' (icType),
input 3 (iiSeverity),
input '' (icRowid),
input 'BLF-39':U (icFcMsgNumber),
input '' (icFcExplanation),
input '' (icFcIdentification),
input '' (icFcContext),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonQueue>
assign oiReturnStatus = -1.
return.
end.
/*
For performance and scalability (1 record = 1 transaction) reasons,
use WriteDirect in stead of DataLoad + DataSave
*/
assign vcFreeForm = "for each fcDaemonQueue where fcDaemonQueue.DaemonID = " + string(iiDaemonID).
if ilDeleteInProcess = false or
ilDeleteProcessedErr = false or
ilDeleteProcessedOk = false or
ilDeleteWaiting = false
then do:
if ilDeleteWaiting
then assign vcFreeForm = vcFreeForm + " and (fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-WAITING} + "'".
if ilDeleteInProcess
then assign vcFreeForm = vcFreeForm +
(if ilDeleteWaiting
then " or fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-INPROCESS} + "'"
else " and (fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-INPROCESS} + "'").
if ilDeleteProcessedOk
then assign vcFreeForm = vcFreeForm +
(if ilDeleteWaiting or
ilDeleteInProcess
then " or fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-PROCESSEDOK} + "'"
else " and (fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-PROCESSEDOK} + "'").
if ilDeleteProcessedErr
then assign vcFreeForm = vcFreeForm +
(if ilDeleteWaiting or
ilDeleteInProcess or
ilDeleteProcessedOk
then " or fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-PROCESSEDERR} + "'"
else " and (fcDaemonQueue.DaemonQueueStatus = '" + {&DAEMONQUEUESTATUS-PROCESSEDERR} + "'").
assign vcFreeForm = vcFreeForm + ")".
end.
<M-57 run StartPersistence
(output vhFcComponent (ohPersistence),
output viFcReturnSuper (oiReturnStatus)) in BBaseDaemonQueue>
<M-75 run WriteDirect
(input 'fcDaemonQueue' (icTableName),
input vcFreeForm (icPrepare),
input '' (icFieldList),
input '' (icFieldListDataTypes),
input '' (icAbsolute),
input '' (icIncremental),
input {&TARGETPROCEDURE} (ihClass),
input vcUserLogin (icUserLogin),
output oiReturnStatus (oiReturnStatus)) in persistence>
if oiReturnStatus = -4
then assign olDeletesExecuted = false
oiReturnStatus = 0.
else if oiReturnStatus >= 0
then assign olDeletesExecuted = true.
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 = "BBaseDaemonQueue".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiClearDaemonQueue".
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/bbasedaemonqueue.apicleardaemonqueue.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::iiDaemonID = <parameter value>
vhParameter::icDaemonName = <parameter value>
vhParameter::ilDeleteWaiting = <parameter value>
vhParameter::ilDeleteInProcess = <parameter value>
vhParameter::ilDeleteProcessedOk = <parameter value>
vhParameter::ilDeleteProcessedErr = <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.