COMP 310
Fall 2012

Lec34:  ChatApp finalization, continued...

Home  Info  Owlspace  Java Resources  Eclipse Resources

 

New threading topics added to Java Threads Resource page.

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

Possibilities:

 

Unknown Data Type Management Protocol Options:

(Sub-items are a matched set)

  1. Receiver attempts to process a received data packet and discovers that they don't know how to process it.
  2. Receiver returns IUnknownData_XmitStatus object to sender.
    1. Receiver caches the unknown data waiting to process it, OR
    2. Receiver  discards unknown data.
  3.  Sender receives IUnknownData_XmitStatus and sends DataPacket<IAddCommand> to receiver ONLY.
  4. Resending data?
    1. No need to resend if data was cached by receiver.  OR
    2. Resend data
      1. Data is automatically resent  -- sender must remember what data was originally sent.   OR
      2. Sender waits for request to resend data.   -- resend data to everyone?

Agreed upon protocol:

  1. Receiver attempts to process a received data packet and discovers that they don't know how to process it.
  2. Receiver initiates the sending of a request (to the sender ONLY) for the command for the unknown data packet type.   This must be a blocking call!
  3. Sender responds to the request for a command by replying with an  DataPacket<IAddCommand>
  4. Receiver installs new command and processes the originally received data packet.
  5. Receiver replies to original reception of the data packet with the results of having processed it.

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?

ICmd2ModelAdapter Interface

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

 

 

 

 


© 2012 by Stephen Wong