lanSimulation
Class Network

java.lang.Object
  extended bylanSimulation.Network

public class Network
extends java.lang.Object

A Network represents the basic data stucture for simulating a Local Area Network (LAN). The LAN network architecture is a token ring, implying that packahes will be passed from one node to another, until they reached their destination, or until they travelled the whole token ring.


Constructor Summary
Network(int size)
          Construct a Network suitable for holding #size Workstations.
 
Method Summary
 boolean consistentNetwork()
          Answer whether #receiver is a consistent token ring network.
static Network DefaultExample()
          Return a Network that may serve as starting point for various experiments.
 boolean hasWorkstation(java.lang.String ws)
          Answer whether #receiver contains a workstation with the given name.
 boolean isInitialized()
          Answer whether #receiver is properly initialized.
 void printHTMLOn(java.lang.StringBuffer buf)
          Write a HTML representation of #receiver on the given #buf.
 void printOn(java.lang.StringBuffer buf)
          Write a printable representation of #receiver on the given #buf.
 void printXMLOn(java.lang.StringBuffer buf)
          Write an XML representation of #receiver on the given #buf.
 boolean requestBroadcast(java.io.Writer report)
          The #receiver is requested to broadcast a message to all nodes.
 boolean requestWorkstationPrintsDocument(java.lang.String workstation, java.lang.String document, java.lang.String printer, java.io.Writer report)
          The #receiver is requested by #workstation to print #document on #printer.
 java.lang.String toString()
          Return a printable representation of #receiver.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Network

public Network(int size)
Construct a Network suitable for holding #size Workstations.

Postcondition:(result.isInitialized()) & (! result.consistentNetwork());

Method Detail

DefaultExample

public static Network DefaultExample()
Return a Network that may serve as starting point for various experiments. Currently, the network looks as follows.
    Workstation Filip [Workstation] -> Node -> Workstation Hans [Workstation]
    -> Printer Andy [Printer] -> ... 
    

Postcondition:result.isInitialized() & result.consistentNetwork();


isInitialized

public boolean isInitialized()
Answer whether #receiver is properly initialized.


hasWorkstation

public boolean hasWorkstation(java.lang.String ws)
Answer whether #receiver contains a workstation with the given name.

Precondition:this.isInitialized();


consistentNetwork

public boolean consistentNetwork()
Answer whether #receiver is a consistent token ring network. A consistent token ring network - contains at least one workstation and one printer - is circular - all registered workstations are on the token ring - all workstations on the token ring are registered.

Precondition:this.isInitialized();


requestBroadcast

public boolean requestBroadcast(java.io.Writer report)
The #receiver is requested to broadcast a message to all nodes. Therefore #receiver sends a special broadcast packet across the token ring network, which should be treated by all nodes.

Precondition: consistentNetwork();

Parameters:
report - Stream that will hold a report about what happened when handling the request.
Returns:
Anwer #true when the broadcast operation was succesful and #false otherwise

requestWorkstationPrintsDocument

public boolean requestWorkstationPrintsDocument(java.lang.String workstation,
                                                java.lang.String document,
                                                java.lang.String printer,
                                                java.io.Writer report)
The #receiver is requested by #workstation to print #document on #printer. Therefore #receiver sends a packet across the token ring network, until either (1) #printer is reached or (2) the packet travelled complete token ring.

Precondition: consistentNetwork() & hasWorkstation(workstation);

Parameters:
workstation - Name of the workstation requesting the service.
document - Contents that should be printed on the printer.
printer - Name of the printer that should receive the document.
report - Stream that will hold a report about what happened when handling the request.
Returns:
Anwer #true when the print operation was succesful and #false otherwise

toString

public java.lang.String toString()
Return a printable representation of #receiver.

Precondition: isInitialized();


printOn

public void printOn(java.lang.StringBuffer buf)
Write a printable representation of #receiver on the given #buf.

Precondition: isInitialized();


printHTMLOn

public void printHTMLOn(java.lang.StringBuffer buf)
Write a HTML representation of #receiver on the given #buf.

Precondition: isInitialized();


printXMLOn

public void printXMLOn(java.lang.StringBuffer buf)
Write an XML representation of #receiver on the given #buf.

Precondition: isInitialized();