core_lib
Class Network

java.lang.Object
  extended by core_lib.Network

public class Network
extends java.lang.Object

The Network class is a high-level object managing data and behaviors specific to users, files, and bandwidth


Field Summary
private  java.util.Queue<Transaction> delay_queue
          Queue storing transactions in progress, yet to commit data.
private  java.util.LinkedList<FileCopy>[] files
          Array acting as a file library for the Network.
 Globals GLOBALS
          Parameterization of this Network.
 Statistics STATS
          Statistics pertaining to happenings on this Network.
private  User[] users
          Array containing Users in the Network; a User library.
 
Constructor Summary
Network(Globals GLOBALS)
          Construct a Network object.
 
Method Summary
 void addFile(int user_num, int file_num, boolean valid)
          Add a file/owner/validity entry to the libraries.
 int availableFiles()
          Determine the number of files available in this Network.
 Transaction dequeueTrans()
          Dequeue transaction at the head of the delay queue.
 void enqueueTrans(Transaction trans)
          Enqueue a transaction onto tail of the delay queue.
 boolean fileCopyValid(int file_num, int user_num)
          Seek the validity of a FileCopy in the file library.
 int fileOwners(int file_num)
          The number of owners (e.g.
 java.util.Iterator<FileCopy> getFileIterator(int file_num)
          Fetch an iterator over all copies of a particular file.
 User getUser(int user_num)
          Access method to a User in the User library.
 Relation getUserRelation(int source, int dest)
          Access method to a Relation object between two library Users.
 boolean hasFile(int user_num, int file_num)
          Determine if a user possesses a certain file.
 Transaction peekQueue()
          Return, but not remove transaction on head of delay queue.
 int queueSize()
          The number of transactions currently in the delay queue.
 void setUser(int user_num, User user)
          Modifier to place a User into the User library.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLOBALS

public Globals GLOBALS
Parameterization of this Network.


STATS

public Statistics STATS
Statistics pertaining to happenings on this Network.


users

private User[] users
Array containing Users in the Network; a User library.


files

private java.util.LinkedList<FileCopy>[] files
Array acting as a file library for the Network.


delay_queue

private java.util.Queue<Transaction> delay_queue
Queue storing transactions in progress, yet to commit data.

Constructor Detail

Network

public Network(Globals GLOBALS)
Construct a Network object.

Parameters:
GLOBALS - The Network parameterization object
Method Detail

getUser

public User getUser(int user_num)
Access method to a User in the User library.

Parameters:
user_num - Numerical identifier of the User to return
Returns:
User with identifier 'user_num'

setUser

public void setUser(int user_num,
                    User user)
Modifier to place a User into the User library.

Parameters:
user_num - Numerical identifier of parameter 'user'
user - The User object to be placed into the User library

getUserRelation

public Relation getUserRelation(int source,
                                int dest)
Access method to a Relation object between two library Users.

Parameters:
source - Numerical identifier of a User
dest - Numerical identifier of a second User
Returns:
Relation between 'source' and 'dest'; from former's perspective

getFileIterator

public java.util.Iterator<FileCopy> getFileIterator(int file_num)
Fetch an iterator over all copies of a particular file.

Parameters:
file_num - Numerical file identifier
Returns:
Iterator over all FileCopies of file 'file'

fileOwners

public int fileOwners(int file_num)
The number of owners (e.g. FileCopies) of a particular file.

Parameters:
file_num - Numerical file identifier
Returns:
Number of FileCopies that exist for file 'file'

fileCopyValid

public boolean fileCopyValid(int file_num,
                             int user_num)
Seek the validity of a FileCopy in the file library.

Parameters:
file_num - Numerical file identifier
user_num - Numerical user identifier
Returns:
TRUE if 'file_num' owned by 'user_num' is valid. Else, FALSE.

hasFile

public boolean hasFile(int user_num,
                       int file_num)
Determine if a user possesses a certain file.

Parameters:
user_num - Numerical user identifier
file_num - Numerical file identifier
Returns:
TRUE if 'user_num" owns a copy of 'file_num'. Else, FALSE.

availableFiles

public int availableFiles()
Determine the number of files available in this Network.

Returns:
Number of files with at least one owner

addFile

public void addFile(int user_num,
                    int file_num,
                    boolean valid)
Add a file/owner/validity entry to the libraries.

Parameters:
user_num - Numerical user identifier of file owner
file_num - Numerical file identifier of file to be added
valid - Validity of the file being added

enqueueTrans

public void enqueueTrans(Transaction trans)
Enqueue a transaction onto tail of the delay queue.

Parameters:
trans - The transaction to be enqueued

dequeueTrans

public Transaction dequeueTrans()
Dequeue transaction at the head of the delay queue.

Returns:
Transaction at head of the delay queue

peekQueue

public Transaction peekQueue()
Return, but not remove transaction on head of delay queue.

Returns:
Transaction at head of the delay queue

queueSize

public int queueSize()
The number of transactions currently in the delay queue.

Returns:
Number of transactions currently in the delay queue.