|
|
The Droplets Platform supports server-initiated changes to any part of the application GUI without user intervention. This is one of the main advantages of Droplets, as this allows Droplets UIs to run dynamically without requiring a user "Refresh". This tutorial shows you how to enable server-side UI updates with the Droplets API. The related topic of desktop alerts is covered in the Writing Desktop Alerts tutorial. There are two major ways of writing server-side events with Droplets:
The Client polls the Server at regular intervals for UI updates; Which of these two methods you use depends largely on the circumstances. Polling the Server is usually best for regular, predictable changes like reading a periodically changing database, and allows you to serve large-scale UI updates with a minimum of server-side work. Posting to Clients, on the other hand, is often best when working with unpredictable updates that do not take place at regular intervals like the reading of changing stock prices from a data feed. Regardless, you need not worry about synchronization issues with either one of these alternatives; the Droplets UI Server takes care of this without your intervention.
Setting up a poll to the Server involves a single call to setPollTime() within your Application object:
The integer argument represents the number of centiseconds (1/100ths of a second) between client polls. So an argument of 100 would cause the client to poll the server every second; 6000 would cause the client to poll every minute. Once you've set the client to poll, you need to wire a poll listener and account for application behavior in the event of an update. This is accomplished by:
If you want to stop the client polling at any point in your application logic, all you need do is again call setPollTime with an argument of -1:
You can also remove the application's PollListener at any time by calling Application.removePollListener() with your existing PollListener as an argument.
An alternate mechanism for delivering server-initiated UI updates is to post them to all clients currently presenting the application's GUI, via the Application object's postEvent() method. This may be more expensive for the UI Server if it requires that thread to poll, but often more efficient than constant client polls when UI updates are unpredictable or intermittent. In order for the Droplets Platform to ensure the handling of all synchronization issues, you must also always use postEvent to update the GUI in the following two circumstances: 1. You've written your own threads that change the GUI periodically (for example, a thread that periodically changes the application's skin parameters); 2. Your application sessions can alter the GUIs of other sessions (for example, an online Chat application). In that case, use postEvent() on the application that is not handling a user event. Since the Droplets UI Server takes care of all thread synchronization issues, adding event posts to your applications is a relatively simple matter: Java
C++
|