|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectuk.org.arlott.simon.hw.f24.lbsta.Host
public class Host
Represents a host on the network.
| Field Summary | |
|---|---|
private int |
address
The address of this host. |
private static boolean[] |
allAddresses
The addresses currently in use. |
private boolean |
inNetwork
Whether or not this host is currently in the network or not. |
LAN |
lan
The LAN this host is connected to. |
private static int |
lastAssigned
The last assigned address. |
private Log |
log
The event log. |
static int |
MAX_ADDRESSES
The maximum number of host addresses. |
private Network |
network
The network this host is on. |
private java.util.HashSet<Packet> |
packets
The packets attached to this host. |
private boolean |
randomPackets
Whether or not this host should send packets at random. |
int |
x
The X co-ordinate position of this host. |
int |
y
The X co-ordinate position of this host. |
| Constructor Summary | |
|---|---|
Host(Host host,
LAN lan,
Network network)
Creates a new Host object. |
|
Host(Host host,
Network network)
Creates a new Host object. |
|
Host(int x,
int y,
LAN lan,
Network network)
Creates a new Host object. |
|
| Method Summary | |
|---|---|
void |
addPacket(Packet p)
Adds a packet to this host. |
void |
addToNetwork()
Adds this host to the network. |
void |
enableRandomPackets(boolean randomPackets)
Sets the status of the random packets mode. |
private static int |
findFreeAddress()
Finds an unused host address. |
int |
getAddress()
Gets the address. |
java.lang.String[] |
getLog()
Gets the log entries for this host. |
java.util.Vector<Packet> |
getPackets()
Gets all the packets on this host. |
boolean |
isRandomPacketsEnabled()
Gets the status of the random packets mode. |
void |
networkChanged()
Indicates that the network has been modified. |
java.util.Vector<Packet> |
processPacket(Packet p)
Processes a packet received by this host. |
void |
removeAllPackets()
Removes all the packets from this host. |
void |
removeFromNetwork()
Removes this host from the network. |
void |
removePacket(Packet p)
Removes a packet from this host. |
void |
reset()
Resets this host's log. |
private boolean |
setAddress(Host h,
int newAddress)
Sets the address of a host. |
boolean |
setAddress(int newAddress)
Sets the address. |
private static boolean |
setInNetwork(Host h,
boolean inNetwork)
Updates the in network state of a host. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private Log log
private java.util.HashSet<Packet> packets
private Network network
public LAN lan
public int x
public int y
public static final int MAX_ADDRESSES
private static boolean[] allAddresses
private static int lastAssigned
private int address
private boolean inNetwork
private boolean randomPackets
| Constructor Detail |
|---|
public Host(int x,
int y,
LAN lan,
Network network)
throws InvalidPositionException
Host object.
x - X position.y - Y position.lan - The LAN this host is attached to.network - The Network this host is on.
InvalidPositionException - If the position is invalid.
public Host(Host host,
LAN lan,
Network network)
throws InvalidPositionException
Host object.
host - An existing Host object to copy.lan - The LAN this host is attached to.network - The Network this host is on.
InvalidPositionException - If the position is invalid.
public Host(Host host,
Network network)
throws InvalidPositionException
Host object.
host - An existing Host object to copy.network - The Network this host is on.
InvalidPositionException - If the position is invalid.| Method Detail |
|---|
public void networkChanged()
public void addToNetwork()
throws TooManyHostsException
TooManyHostsException - If there are too many hosts on the network already.public void removeFromNetwork()
public void reset()
public java.lang.String[] getLog()
private static boolean setInNetwork(Host h,
boolean inNetwork)
h - The Host to modify.inNetwork - Whether or not the host is in the network or not.
true if the action was successful.private static int findFreeAddress()
public int getAddress()
public boolean setAddress(int newAddress)
newAddress - The new address for the host.
true if the address is not already in use.
private boolean setAddress(Host h,
int newAddress)
h - The Host to modify.newAddress - The new address of the host.
true if the address is not already in use.public boolean isRandomPacketsEnabled()
true if enabled.public void enableRandomPackets(boolean randomPackets)
randomPackets - true to enable or false to disable.public void addPacket(Packet p)
addPacket in interface PacketTransportp - The Packet to add.public void removePacket(Packet p)
removePacket in interface PacketTransportp - The Packet to remove.public java.util.Vector<Packet> getPackets()
public void removeAllPackets()
public java.util.Vector<Packet> processPacket(Packet p)
processPacket in interface PacketDestinationp - The Packet to process.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||