|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--edu.uiuc.cs.net.DPRPManager.DPRPLease
This class represents all of the details that comprise a "lease". In the DPRP sense, this means that we have several private variables, comprising the external IP address and port on the gateway, as well as duration, protocol, flags, and the starting time for this lease. This class also contains methods to write out a lease into a machine-parsable string, and of course, to suck in a lease from such a string.
Field Summary | |
private java.net.InetAddress |
clientIP
The IP address of the client that registered this lease. |
private int |
clientPort
The port of the registering client. |
static boolean |
DEBUG
In order to ease JAR file creation, this variable is now public, and set to be true whenever the server or client sets it's debug variables to true. |
static int |
DEFAULT_DURATION
Constant representing the default duration, in seconds. |
static short |
DEFAULT_FLAGS
Constant representing the default flags for a new lease. |
private int |
duration
The length of time, in seconds, during which this lease is valid. |
private java.net.InetAddress |
externalIP
The external IP address (on the gateway) for this lease. |
private int |
externalPort
The external port (on the gateway) for this lease. |
private short |
flags
The flags that govern this lease. |
private short |
nackError
Extra field to pass server lease NACK errorcodes. |
private int |
numRenews
Number of times this lease has been renewed. |
private byte |
protocol
The protocol type that the gateway will forward. |
private java.net.InetAddress |
serverIP
I've been forced to make the lease track the IP address of the server that generated it. |
private int |
serverPort
The server's main listening port; where new connections go. |
private java.util.Calendar |
startTime
The wall-clock time at which this lease was created. |
Constructor Summary | |
DPRPLease()
Simple constructor for DPRPLease. |
|
DPRPLease(DPRPMessage msg,
boolean dst)
DPRPLease constructor from DPRPMessage. |
Method Summary | |
boolean |
compareToMsg(DPRPMessage msg)
Compares the parameters in the given message to those in this lease. |
boolean |
equals(DPRPLease cmp)
Localized method for determining the equality of two leases. |
boolean |
equals(java.lang.Object obj)
Overloading the exact equals() method that appears in Object. |
static DPRPLease |
fromString(java.lang.String str)
Converts a string representation of a lease into a DPRPLease object. |
java.net.InetAddress |
getClientIP()
Returns the client IP address that 'owns' this lease. |
int |
getClientPort()
Returns the port of the client that established this lease. |
int |
getDuration()
Returns the duration of this lease, in seconds. |
java.net.InetAddress |
getExternalIP()
Returns the external IP address of this lease. |
int |
getExternalPort()
Gets the external port of this lease. |
short |
getFlags()
Returns the current value of the flags. |
short |
getNackError()
Deprecated. This will be removed, when I refactor the NACK stuff out of this class. |
int |
getNumRenews()
Gets the number of times this lease has been renewed. |
java.lang.String |
getPrimaryKey()
Returns the "primary key" for this lease. |
byte |
getProtocol()
Return the current protocol for this lease. |
java.lang.String |
getProtocolStr()
Return the current protocol as a human-readable string. |
java.net.InetAddress |
getServerIP()
Get the server's IP address. |
int |
getServerPort()
Gets the server port. |
java.util.Date |
getStopTime()
Determines when this lease expires. |
int |
hashCode()
Returns an integer represenation of this lease, for use in hashing. |
void |
incNumRenews()
Increments the number of times this lease has been renewed. |
boolean |
isExpired()
This method checks to see if a lease has expired. |
DPRPMessage |
messageToClient(java.net.InetAddress sourceIP,
int sourcePort)
Spits out a fully-formed DPRPMessage, addressed to the client. |
private static java.util.Vector |
parseLeaseString(java.lang.String str,
char separator)
An internal method that breaks a string into components around the separator. |
void |
prettyPrint()
Prints a lease to stdout in a human-readable format. |
static java.util.HashSet |
readLeaseFile(java.io.File fname)
Reads ASCII lease representations from disk, and returns them in a collection. |
void |
setClientIP(java.net.InetAddress a)
Sets the client IP address for this lease. |
void |
setClientPort(int extPortInt)
Sets the client port for this lease. |
void |
setClientPort(java.lang.String extPortStr)
Sets the client port for this lease. |
void |
setDuration(int dur)
Sets the duration of this lease. |
void |
setDuration(java.lang.String sDur)
Sets the duration of this lease. |
void |
setExternalIP(java.net.InetAddress a)
Sets the external IP address of this lease. |
void |
setExternalPort(int extP)
Sets the external port for this lease. |
void |
setExternalPort(java.lang.String extS)
Sets the external port for this lease. |
void |
setFlags(short f)
Sets the flags for this lease. |
void |
setFlags(java.lang.String fStr)
Set the flags for this lease, given a string representation of a short. |
void |
setNackError(short r)
Sets the nack reason. |
void |
setNumRenews(int i)
Sets the number of times this lease has been renewed. |
void |
setNumRenews(java.lang.String s)
Sets the number of times this lease has been renewed. |
void |
setProtocol(byte prot)
Sets the raw protocol. |
void |
setProtocol(java.lang.String sP)
Sets the protocol, given a human-readable string. |
void |
setServerIP(java.net.InetAddress sIP)
Sets the server's IP. |
void |
setServerPort(int xp)
Sets the port on the server, from an int. |
void |
setServerPort(java.lang.String ps)
Sets the port on the server, from a string. |
void |
setStartTime(java.util.Date t)
Sets the startTime to the Date object given. |
java.lang.String |
toString()
Writes out a lease in a computer-parseable format. |
void |
touchStartTime()
Updates the startTime for this lease with the current wall-clock time. |
static java.util.HashSet |
writeLeaseFile(java.io.File fname,
java.util.HashSet leasesToWrite)
Writes a given collection of leases to disk, and returns the leases that were actually written. |
private static void |
writeLeaseFileComment(java.io.File fname)
Writes out the standard comment block at the top of the on-disk lease database. |
Methods inherited from class java.lang.Object |
|
Field Detail |
public static final int DEFAULT_DURATION
public static final short DEFAULT_FLAGS
private int duration
private java.util.Calendar startTime
private java.net.InetAddress externalIP
private int externalPort
private java.net.InetAddress clientIP
private int clientPort
private java.net.InetAddress serverIP
private int serverPort
private byte protocol
private short flags
private short nackError
private int numRenews
public static boolean DEBUG
Constructor Detail |
public DPRPLease(DPRPMessage msg, boolean dst)
msg
- A DPRPMessage, containing the parameters to make a
lease out of.dst
- Wether the proposed lease's 'ClientIP' refers to the
destination or the source of the message.public DPRPLease()
Method Detail |
public java.net.InetAddress getExternalIP()
public void setExternalIP(java.net.InetAddress a)
public int getExternalPort()
public void setExternalPort(int extP)
extP
- An integer value, representing the port.public void setExternalPort(java.lang.String extS) throws java.lang.NumberFormatException
extS
- A string value, to be converted to an integral port
value.java.lang.NumberFormatException
- If the string doesn't contain a
valid integer.public java.net.InetAddress getClientIP()
public void setClientIP(java.net.InetAddress a)
public int getClientPort()
public void setClientPort(int extPortInt)
extP
- An integral port value.public void setClientPort(java.lang.String extPortStr) throws java.lang.NumberFormatException
extPortStr
- A string, hopefully containing an integer port value.java.lang.NumberFormatException
- If the string doesn't contain a
valid integer value.public java.net.InetAddress getServerIP()
public void setServerIP(java.net.InetAddress sIP)
public int getServerPort()
public void setServerPort(int xp)
public void setServerPort(java.lang.String ps) throws java.lang.NumberFormatException
public int getDuration()
public void setDuration(int dur)
dur
- An integer number of seconds, to comprise the new
duration.public void setDuration(java.lang.String sDur) throws java.lang.NumberFormatException
sDur
- An string, representing an integer number of seconds.java.lang.NumberFormatException
- If the string doesn't contain a
valid integer value.public byte getProtocol()
public java.lang.String getProtocolStr()
public void setProtocol(byte prot)
public void setProtocol(java.lang.String sP) throws DPRPInvalidProtocolException
DPRPInvalidProtocolException
- If the given string can't
be matched to a known numeric representation.public short getFlags()
public void setFlags(short f)
public void setFlags(java.lang.String fStr) throws java.lang.NumberFormatException
java.lang.NumberFormatException
- If the string given can't be
convereted to a numeric value.public short getNackError()
public void setNackError(short r)
public void touchStartTime()
public void setStartTime(java.util.Date t)
public java.lang.String getPrimaryKey()
public int getNumRenews()
public void incNumRenews()
public void setNumRenews(int i)
i
- The number of renews are set equal to this value.public void setNumRenews(java.lang.String s) throws java.lang.NumberFormatException
s
- A string, representing an integer number.java.lang.NumberFormatException
- If the string doesn't accurately
represent an integer.public boolean isExpired()
public java.util.Date getStopTime()
public DPRPMessage messageToClient(java.net.InetAddress sourceIP, int sourcePort)
sourceIP
- The source IP address (server).sourcePort
- The source IP port (server).public boolean compareToMsg(DPRPMessage msg)
msg
- A DPRPMessage, of which values certain
fields will be compared to those in this lease.public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- An object, to compare our values against, if it is in
fact a DPRPLease instance.public boolean equals(DPRPLease cmp)
cmp
- A DPRPLease, to compare our values against.public int hashCode()
equals()
, I also have to overload
this method. Essentially, I just take the bits of the primary key,
and smash them all together into a 32-bit quantity.hashCode
in class java.lang.Object
public java.lang.String toString()
extIP:extPort:protocol|cliIP:cliPort|srvIP:srvPort|startTime|duration|flags|numRenewsWhere extIP:extPort:protocol is the primary key.
toString
in class java.lang.Object
public static DPRPLease fromString(java.lang.String str)
str
- A String representing a lease, to be converted.private static java.util.Vector parseLeaseString(java.lang.String str, char separator)
str
- A String object to parse.separator
- A character that separates out the fields.public void prettyPrint()
public static java.util.HashSet readLeaseFile(java.io.File fname) throws java.io.IOException
fname
- The name of the file to be read.public static java.util.HashSet writeLeaseFile(java.io.File fname, java.util.HashSet leasesToWrite)
fname
- A File instance, containing the name
and location of the file to be written.leasesToWrite
- A collection of leases to be written.private static void writeLeaseFileComment(java.io.File fname) throws java.io.IOException
java.io.IOException
- If there was a problem writing to the file.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |