COMP 310
Fall 2015

Lec34:  ChatApp finalization, continued...

Home  Info  Owlspace   Java Resources  Eclipse Resources  Piazza

 

For guidance on handling threads, please see the Java Threads Resource page.

How does the receiver of a data packet know who sent it?

Possibilities:

 

Unknown Data Type Management Protocol Options:

 

Connecting a remotely-sourced command to the local system

Since a command being sent over from a remote system has no idea about the environment of the local system into which it is being installed, it has no intrinsic means in which to display any information on the local UI or interact with the local user or system.     Thus, the local system must give the incoming command a reference to an adapter to the local system where the adapter implements an interface that is part of the common public API.

The question is "What minimal set of operations on this adapter are needed to give the command the most flexibility but minimize its ability to harm the local system?" 

Note that the attachment of this adapter to the incoming command is only ever done once, when the command is first received from the remote sender.   The method that installs the local system adapter, is thus a perfect place for the command to perform any one-time initializations that it needs to do upon its integration into the local system.

 

 

QUESTIONS: Should an incoming command

 

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())!

 

 

 

 


© 2015 by Stephen Wong