COMP 310/510
|
Lec34: ChatApp finalization, continued... |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
New threading topics added to Java Threads Resource page.
Possibilities:
(Sub-items are a matched set)
Agreed upon protocol:
Note: IUnknownData_XmitStatus should be renamed to IUnknownData_CmdRequest to clarify its use as a request rather than as a transmission status response.
Question: What should you do if the response to IUnknownData_Request is not an IAddCommand data packet?
import java.awt.Component; import comp310f11.rmiChat.IUser; /** * Interface between a DataPacketAlgoCmd and the model of a ChatApp system. Allows a foreign command * access to some limited services of its host ChatApp. */ public interface ICmd2ModelAdapter { /** * Gets a reference to the local IUser stub which is needed to instantiate IStatus return objects. * @return The local IUser's stub. */ public abstract IUser getLocalUserStub(); /** * Appends the given string onto a text display somewhere on the host ChatApp's GUI. * @param s A string to display */ public abstract void append(String s); /** * Allows the command to give a java.awt.Component to the host ChatApp to be displayed on * its GUI somewhere. * @param name A title for the component, useful for tabs, frame titles, etc. * @param newComp The component to display. */ public void addComponent(String name, Component newComp); }
QUESTION: Should an incoming command
This implies the existence of a method on ADataPacketAlgoCmd:
public abstract void setCmd2ModelAdpt(ICmd2ModelAdapter cmd2ModelAdpt);
Important implementation detail:
Keeping a field value from being serialized:
As per the above API standard, a ADataPacketAlgoCmd implementaion may have a field of type ICmd2ModelAdapter that holds a reference to current adapter. When a command is transferred from the sender to the receiver, the command may have been already connected to the sender's model via an ICmd2ModelAdapter implementation created by the sender.
But when the command is sent to the receiver, the receiver will install its own ICmd2ModelAdapter that connects to its own model and view. It is not necessary or desirable to serialize and transmit the value of the adapter reference esp. since such adapters are usually anonymous inner classes.
To tell Java not to serialize and transmit the value of a field, mark the field with the keyword "transient".
Example:
private transient ICmd2ModelAdapter cmd2ModelAdpt;
When this the command is deserialized at the receiver, this field will be null. Thus, you MUST call setCmd2ModelAdpt() on the new command BEFORE it is installed into the data packet processing visitor (e.g. algo.setCmd())!
© 2013 by Stephen Wong