Daemon example: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
m (add category)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
Sirius '''Daemons''' are a class of objects that run on a thread other than the user that launched them. The thread that launches the Daemon is called the "parent"The Daemon responds to requests from the parent and may optionally pass back to the parent thread the results of commands and [[User Language]] programs.
SOUL '''Daemons''' are a class of objects that run on a thread other than the user that launched them. The thread that launches the <var>Daemon</var> is called the "parent." The <var>Daemon</var> responds to requests from the parent and may optionally pass back to the parent thread the results of commands and <var class="product">[[User Language]]</var> programs.


See the [[Daemon class]] and [[Daemon methods]] pages for detailed information on Daemons and Daemon behaviors.
See the [[Daemon class|Daemon class]] and its method pages for detailed information about <var>Daemon</var> behaviors.


=Why use a Daemon?=
==Why use a Daemon?==
<var>Daemon</var> objects make it easy to capture command output and <var class="product">User Language</var> output to <var>Stringlist</var> objects. They make it easy to keep server sizes low by splitting work between a parent and daemon.  The use of [[Daemon class#Asynchronous and Independent daemons|Asynchronous and Independent daemons]] allows work to be discharged in "fire and forget" mode, where the <var>Daemon</var> completes a task while the parent thread moves on to other processes.


Daemons make it easy to capture command output and User Language output to Stringlist objects. They make it easy to keep server sizes low by splitting work between a parent and daemonThe use of Asynchronous daemons allows work to be discharged in "fire and forget" mode, where the Daemon completes a task while the parent thread moves on to other processes.
==Variable Find conditions==
One problem often encountered in <var class="product">User Language</var> is that <var>Find</var> conditions are bound at compile time. Variable input to a fixed number of conditions, with an unchanging set of field names, is handled well in ordinary <var class="product">User Language</var>But <var class="product">User Language</var> has no clean mechanism to programmatically set up and execute dynamically generated <var>Find</var>s.


=Variable Find Conditions=
Daemons handle this situation very elegantly. In the following program, a <var>Daemon</var> is instantiated, and a small program is built to <var>Find</var> a set of records. The program is submitted to the <var>Daemon</var> in a <var>[[Stringlist class|Stringlist]]</var>, and the resulting set of found records is returned to the parent thread in a <var>[[Recordset class#SortedRecordSet|SortedRecordSet]]</var> object.
 
<p class="code">Begin
One problem often encountered in [[Model 204]] [[User Language]] is that FIND conditions are bound at compile time.  Variable input to a fixed number of conditions, with an unchanging set of field names, is handled well in ordinary User Language.  But User Language has no clean mechanism to programmatically set up and execute dynamically generated FINDs.
 
Daemons handle this situation very elegantly. In the following program, a Daemon is instantiated, and a small program is built to FIND a set of records. The program is submitted to the Daemon in a [[Stringlist class|StringList]], and the resulting set of found records is returned to the parent thread in a [[Recordset class#SortedRecordSet|SortedRecordSet]] object.
 
 
Begin
      %FindCriteria    is string len 255
      %Pazuzu          is object Daemon
      %Sorted          is object SortedRecordSet in file CUSTOMER
      %SubList        is object stringList
   
   
* Any of a variety of FIND conditions can be submitted to the Daemon.
      %FindCriteria    is string len 255
* In a full application, these conditions could be selected by the user through
      %Pazuzu          is object Daemon
* a screen or browser interface.
      %Sorted          is object SortedRecordSet in file CUSTOMER
      %SubList        is object stringList
   
   
*    %FindCriteria = 'RECTYPE = ''C'' '
&#42; Any of a variety of FIND conditions can be submitted to the Daemon.
*    %FindCriteria = 'NICKNAME IS LIKE ''SI*'' '
&#42; In a full application, these conditions could be selected by the user through
      %FindCriteria = 'RECTYPE = ''C'' AND LAST_MODIFIED=20101225'
&#42; a screen or browser interface.
   
   
      %SubList = new
&#42;    %FindCriteria = 'RECTYPE = ''C'' '
      Text to %SubList
&#42;    %FindCriteria = 'NICKNAME IS LIKE ''SI*'' '
      Begin
      %FindCriteria = 'RECTYPE = ''C'' AND LAST_MODIFIED=20101225'
          %BasicSet        is object RecordSet in file CUSTOMER
          %Sorted          is object SortedRecordSet in file CUSTOMER
          %BasicSet = New
          Find Records to %BasicSet
              {%FindCriteria}
          End Find
          Sort records in %BasicSet to %Sorted by NICKNAME
          %(daemon):returnObject(%Sorted)
      End
      End Text
   
   
       %Pazuzu = New
      %SubList =  new
      %Pazuzu:open('CUSTOMER')
      Text to %SubList
      %Pazuzu:run(%SubList,,%Sorted)
      Begin
        %BasicSet       is object RecordSet in file CUSTOMER
        %Sorted          is object SortedRecordSet in file CUSTOMER
        %BasicSet = New
        Find Records to %BasicSet
            {%FindCriteria}
        End Find
        Sort records in %BasicSet to %Sorted by NICKNAME
        %(daemon):returnObject(%Sorted)
      End
      End Text
   
   
      * Process the returned sorted list
      %Pazuzu = New
      For each record in %Sorted
      %Pazuzu:open('CUSTOMER')
feoname: feo NAME
      %Pazuzu:run(%SubList,,%Sorted)
            print NICKNAME and NAME(occurrence in feoname) and TCPADDR(occurrence in feoname)
          End For
      End For
   
   
  End
      * Process the returned sorted list
      For each record in %Sorted
feoname: feo NAME
            print NICKNAME and NAME(occurrence in feoname) and TCPADDR(occurrence in feoname)
        End For
      End For
End
</p>


=References=
==See also==
<ul>
<li>[[Daemon class]] </li>


[[Daemon class]]
<li>[[List of Daemon methods]] </li>


[[Daemon methods]]
<li>[[Stringlist class]] </li>


[[Stringlist class]]
<li>[[Recordset class]] </li>
</ul>


[[Recordset class]]
[[Category:SOUL object-oriented programming topics]]

Latest revision as of 19:18, 20 April 2018

SOUL Daemons are a class of objects that run on a thread other than the user that launched them. The thread that launches the Daemon is called the "parent." The Daemon responds to requests from the parent and may optionally pass back to the parent thread the results of commands and User Language programs.

See the Daemon class and its method pages for detailed information about Daemon behaviors.

Why use a Daemon?

Daemon objects make it easy to capture command output and User Language output to Stringlist objects. They make it easy to keep server sizes low by splitting work between a parent and daemon. The use of Asynchronous and Independent daemons allows work to be discharged in "fire and forget" mode, where the Daemon completes a task while the parent thread moves on to other processes.

Variable Find conditions

One problem often encountered in User Language is that Find conditions are bound at compile time. Variable input to a fixed number of conditions, with an unchanging set of field names, is handled well in ordinary User Language. But User Language has no clean mechanism to programmatically set up and execute dynamically generated Finds.

Daemons handle this situation very elegantly. In the following program, a Daemon is instantiated, and a small program is built to Find a set of records. The program is submitted to the Daemon in a Stringlist, and the resulting set of found records is returned to the parent thread in a SortedRecordSet object.

Begin %FindCriteria is string len 255 %Pazuzu is object Daemon %Sorted is object SortedRecordSet in file CUSTOMER %SubList is object stringList * Any of a variety of FIND conditions can be submitted to the Daemon. * In a full application, these conditions could be selected by the user through * a screen or browser interface. * %FindCriteria = 'RECTYPE = C ' * %FindCriteria = 'NICKNAME IS LIKE SI* ' %FindCriteria = 'RECTYPE = C AND LAST_MODIFIED=20101225' %SubList = new Text to %SubList Begin %BasicSet is object RecordSet in file CUSTOMER %Sorted is object SortedRecordSet in file CUSTOMER %BasicSet = New Find Records to %BasicSet {%FindCriteria} End Find Sort records in %BasicSet to %Sorted by NICKNAME  %(daemon):returnObject(%Sorted) End End Text %Pazuzu = New %Pazuzu:open('CUSTOMER') %Pazuzu:run(%SubList,,%Sorted) * Process the returned sorted list For each record in %Sorted feoname: feo NAME print NICKNAME and NAME(occurrence in feoname) and TCPADDR(occurrence in feoname) End For End For End

See also