GetFirst (TStereotypeClassQueue)
De Wiki1000
(Différences entre les versions)
(Page créée avec « <source lang='delphi'>class function GetFirst(const iTopic:string):TQueueObject;</source> Cette fonction retourne le premier objet prêt de la file d'attente sans le cons... ») |
|||
Ligne 12 : | Ligne 12 : | ||
|} | |} | ||
− | {{tip|Cette fonction est utile pour | + | {{tip|Cette fonction est utile pour |
+ | * Anticiper la valeur du sujet lorsqu'elle est utilisée avec un topic comportant une partie variable | ||
+ | * Consommer les objets par une boucle First/Next sans être bloqué par un message "poison" | ||
+ | }} | ||
Exemple : | Exemple : | ||
Ligne 29 : | Ligne 32 : | ||
if Assigned(obj) then | if Assigned(obj) then | ||
begin | begin | ||
+ | // We can do some check on the actual topic of the queue object | ||
+ | // we keep obj for the GetNext, so we used an other instance | ||
todo := MyQueue.deQueue(obj.queueTopic); | todo := MyQueue.deQueue(obj.queueTopic); | ||
+ | // the object may has been consumed by an other process, so we have to check it again. | ||
if Assigned(todo) then | if Assigned(todo) then | ||
begin | begin | ||
Ligne 35 : | Ligne 41 : | ||
if Assigned(inst) then | if Assigned(inst) then | ||
try | try | ||
− | // | + | // This is a test case for requeue capability |
if inst.unEntier=21 then raise Exception.Create('check error'); | if inst.unEntier=21 then raise Exception.Create('check error'); | ||
// | // | ||
S := S+stag+inst.unCode; | S := S+stag+inst.unCode; | ||
stag := ','; | stag := ','; | ||
− | |||
// delete this queue object | // delete this queue object | ||
todo.DeleteThisObject; | todo.DeleteThisObject; | ||
except | except | ||
// on error requeue the object with the same topic | // on error requeue the object with the same topic | ||
+ | // The object will not been retreive in the next loop turn because of the GetNext | ||
todo.ReQueue(''); | todo.ReQueue(''); | ||
end; | end; |
Version actuelle en date du 17 avril 2013 à 11:39
class function GetFirst(const iTopic:string):TQueueObject;
Cette fonction retourne le premier objet prêt de la file d'attente sans le consommer.
Result | Le premier objet non consommée de la file pour le sujet. |
iTopic | Nom de sujet demandé. |
Exemple :
//Procedure TestInQueue; var sel:TSelector; obj,todo:MyQueue; inst:WFClasseA; S,stag:string; begin sel := WFClasseA.CreateSelector('unEntier>%1','',true,[10]); sel.InQueue('MyQueue','wfclassea/@oid'); S := ''; stag := ''; obj := MyQueue.GetFirst(''); Repeat if Assigned(obj) then begin // We can do some check on the actual topic of the queue object // we keep obj for the GetNext, so we used an other instance todo := MyQueue.deQueue(obj.queueTopic); // the object may has been consumed by an other process, so we have to check it again. if Assigned(todo) then begin inst := todo.queueRef as WFClasseA; if Assigned(inst) then try // This is a test case for requeue capability if inst.unEntier=21 then raise Exception.Create('check error'); // S := S+stag+inst.unCode; stag := ','; // delete this queue object todo.DeleteThisObject; except // on error requeue the object with the same topic // The object will not been retreive in the next loop turn because of the GetNext todo.ReQueue(''); end; end; end; // obj := MyQueue.GetNext('',obj); Until not Assigned(obj); showMessage(S); end;
Voir aussi
Whos here now: Members 0 Guests 0 Bots & Crawlers 1 |