
[ Previous ] [ Index ] [ Next ]


In this pattern, we are dealing only with sending the current state to a new client which is starting up. We deal with sending events to existing clients in the Event Handling pattern.
If you would like a more detailed description of how the communication between hablets works, you can read about Habanero's event model.
protected void writeHablet(MarshallOutputStream out) throws IOExceptionand
protected void readHablet(MarshallInputStream in) throws IOExceptionWithin writeHablet(), you need to write out each variable that changes. You can read about how to decide which variables to send.
Then within readHablet(), you need to read in in the same order the variables you sent.
Here is an example of a generic way of doing writeHablet() and readHablet() if you need to save the state of a generic object:
| Example from HabTextDemo2.java. |
| protected void writeHablet(MarshallOutputStream out)
throws IOException
{ out.writeObject(outArea); } protected void readHablet(MarshallInputStream in) throws
IOException
|
In our Running Example, we picked a more effecient method than the generic method above. Since we know that the data in outArea is textual, we simply wrote out the string:
| Running Example from the example of habanerizing TextDemo.java. |
| Add these methods to the class HabTextDemo:
protected void writeHablet(MarshallOutputStream out) throws
IOException
|
|
|
A Hablet is Externalizable as opposed to Serializable. If you are habanerizing a multiple-class applet, the other classes should implement Serializable, then all their data will be automatically transmitted, unless you make the variable transient. |
Habanero® is a registered trademark owned by The Board of Trustees of the University of Illinois. Copyright 1996-1998. All rights reserved. Java(TM) is a proprietary trademark owned by Sun Microsystems, Inc.
![]()
The National Center for Supercomputing Applications
University of Illinois at Urbana-Champaign
Contacts page