Comp150CPA: Clouds and Power-Aware Computing
Classroom Exercise 3
group member 1: ____________________________ login: ______________
group member 2: ____________________________ login: ______________
group member 3: ____________________________ login: ______________
group member 4: ____________________________ login: ______________
group member 5: ____________________________ login: ______________
In class we have studied the concept of asynchronous client-server interactions, in which the client schedules page updates that occur later in time.
Let's explore a bit more about these interactions.
- In the examples, why is the asynchronous callback class defined inside the client method, rather than in another class?
Answer: The callback must modify local variables of the OnModuleLoad method. It can only see and access these variables if it is declared inside that scope.
- Suppose the user in the SimplePersistence example presses the
"Save" button twice in rapid succession. What does the user see?
Absolutely nothing. The two presses lead to two persistent saves,
which do not conflict and are consistent, so the client sets the
success message twice, which has no visible effect for the user.
- Suppose you want to do real-time updates of, e.g., stock quotes.
GWT allows the client to regularly request data asynchronously.
For requesting one stock's quote, what should the argument and return
value to the service look like? Hint: can you tell quotes apart?
The key issue is that when asynchronous data returns, it is not marked
with its identity. If one simply returned the average, one would not
know which company the average is for. Thus one must instead return
an object that both contains the average and identifies it.
- Suppose you want to make one request of a server for a bundle
of loosely related data items to be scattered around a web page in
various places. How would you approach designing the clientside
and serverside code so that there is no confusion as to what data
goes where from the (asynchronous) return value?
The obvious solution is to use a List of objects like the ones in the
previous problem. Each element of the list must identify what its
data means and the company to which it refers. Any serializable object
can be used as a service response value, and Lists are serializable.
- (Advanced) Why is the asynchronous version of a service
class created through a factory-like construction:
PersistentThingServiceAsync thingService =
rather than being pre-defined through inheritance?
(It actually isn't a factory; it just looks like one.)
The relationship between these interfaces can't be represented by
simple inheritance. Inheritance can only change the meanings of
existing functions. In this case the prototypes of the required
functions are different and tt is instead a mapping relationship.
Some students pointed out that one can use object introspection
to accomplish the mapping, this is what is done in the GWT compiler.
But the client can't introspect, partly because it isn't running in
a Java Virtual Machine (JVM)! Hence we must compile rather than
using a factory, because the basic function needed to run a factory
(introspection) is not present!