Alternative 4: Piggyback (No Suspend or Resume, No Timer)"

From Documentation
m (correct highlight (via JWB))
 
Line 3: Line 3:
 
Instead of checking the results periodically, you can piggyback them to the client when the user, say, clicks a button or enters something.
 
Instead of checking the results periodically, you can piggyback them to the client when the user, say, clicks a button or enters something.
  
To piggyback, all you need to do is to register an event listener for the <tt>onPiggyback</tt> event to one of the root components. Then, the listener will be invoked each time ZK Update Engine has processed the events. For example, you can rewrite the codes as follows.
+
To piggyback, all you need to do is to register an event listener for the <code>onPiggyback</code> event to one of the root components. Then, the listener will be invoked each time ZK Update Engine has processed the events. For example, you can rewrite the codes as follows.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 27: Line 27:
 
The advantage of the piggyback is no extra traffic between the client and the server. However, the user sees no updates if he doesn't have any activity, such as clicking or typing. Whether it is proper is really up to the application requirements.
 
The advantage of the piggyback is no extra traffic between the client and the server. However, the user sees no updates if he doesn't have any activity, such as clicking or typing. Whether it is proper is really up to the application requirements.
  
'''Note''': A deferrable event won't be sent to the client immediately, so the <tt>onPiggyback</tt> event is triggered only if a non-deferrable event is fired. Refer to the '''Deferrable Event Listeners''' section.
+
'''Note''': A deferrable event won't be sent to the client immediately, so the <code>onPiggyback</code> event is triggered only if a non-deferrable event is fired. Refer to the '''Deferrable Event Listeners''' section.
  
 
{{ ZKDevelopersGuidePageFooter}}
 
{{ ZKDevelopersGuidePageFooter}}

Latest revision as of 10:35, 19 January 2022

DocumentationZK Developer's GuideAdvanced ZKLong OperationsAlternative 4: Piggyback (No Suspend or Resume, No Timer)
Alternative 4: Piggyback (No Suspend or Resume, No Timer)


Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


Instead of checking the results periodically, you can piggyback them to the client when the user, say, clicks a button or enters something.

To piggyback, all you need to do is to register an event listener for the onPiggyback event to one of the root components. Then, the listener will be invoked each time ZK Update Engine has processed the events. For example, you can rewrite the codes as follows.

<window id="main" title="Working Thread3" onPiggyback="checkResult()">
    <zscript>
     List result = Collections.synchronizedList(new LinkedList());
 
     void checkResult() {
         while (!result.isEmpty())
             main.appendChild(result.remove(0));
     }
    </zscript>
    <timer id="timer" />
    <button label="Start Working Thread">
        <attribute name="onClick">
     		timer.start();
     		new test.WorkingThread2(desktop, result).start();
        </attribute>
    </button>
</window>

The advantage of the piggyback is no extra traffic between the client and the server. However, the user sees no updates if he doesn't have any activity, such as clicking or typing. Whether it is proper is really up to the application requirements.

Note: A deferrable event won't be sent to the client immediately, so the onPiggyback event is triggered only if a non-deferrable event is fired. Refer to the Deferrable Event Listeners section.



Last Update : 2022/01/19

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.