edu.uiuc.cs.net.DPRPManager
Class DPRPClient

java.lang.Object
  |
  +--edu.uiuc.cs.net.DPRPManager.DPRPClient
All Implemented Interfaces:
DPRPClientConstants, DPRPLeaseListenerConstants, java.util.EventListener

public class DPRPClient
extends java.lang.Object
implements DPRPLeaseListenerConstants, DPRPClientConstants

This class is an overall container for the DPRP Client. It can be instantiated, and once done, contains a vector of all of the leases currently outstanding for this client. Furthermore, it can spawn new 'DPRPClientSession' threads, in order to obtain & update new leases.

This is going to need some major help so that this class can fire events at the GUI. Hell, maybe the thread should be the one firing the events. Well, it should be here, because this is the one that is interrupting the caller thread (ugly like Mike's mom). Anyways, the help for EventListenerList in the JDK 1.3.1 documentation is the most lucid source of information that I have at at this point. I'm still confused as to what sort of interface I need to create (probably DPRPEventListener), and what this interface needs to define.

Everything sucks.

Version:
1.1 - November 15th, 2001
Author:
Andy Reitz (areitz@cs.uiuc.edu)

Field Summary
private  java.lang.Thread callerThread
          A reference to the thread that started this object.
private  java.net.InetAddress cliIP
          The IP address on the local machine that we are using.
private  int cliPort
          The port on the local machine that we are using.
static boolean DEBUG
          Controls the printing of debug messages.
private  java.net.InetAddress extIP
           
private  int extPort
           
 DPRPLease gotLease
          Notifies the session that we already have a valid lease, and that it should simply sit on it (i.e.
private  javax.swing.event.EventListenerList listenerList
          A list of event listeners, who need to be notified whenever we muck with a lease.
private  java.util.Vector obtainedLeases
          Internal variable, contains a reference to all outstanding leases for this client.
private  int reqDuration
          The lease duration to request from the gateway.
private  short reqFlags
          The flags to accompany all messages to the gateway.
private  int reqPort
          The port to request from the gateway.
private  byte reqProtocol
          The type of port to request from the gateway.
 DPRPLeaseEvent returnLeaseEvent
          For the legacy client interrupt method, passes a reference to a DPRPLeaseEvent object, which gives some details about this event..
 int sentRequest
          Set by the caller, whenever it wants to interrupt the thread with new instructions.
private  java.lang.Thread sessionThreadID
          The Thread object for the client session.
private  java.net.InetAddress srvIP
          The IP address of the gateway, that we connect to.
private  int srvPort
          The UDP port on the server to connect to.
 
Fields inherited from interface edu.uiuc.cs.net.DPRPManager.DPRPLeaseListenerConstants
NEW_LEASE_EVENT, REMOVE_LEASE_EVENT, UPDATE_LEASE_EVENT
 
Fields inherited from interface edu.uiuc.cs.net.DPRPManager.DPRPClientConstants
CLI_COMMAND, CLI_FORCE_LEASE_TERMINATE, CLI_FORCE_LEASE_UPDATE, CLI_TERMINATE_THREAD, cliIPFieldString, HALT, HALT_ACQUIRE_LEASE, HALT_INTERRUPTED, HALT_INVALID_SLEEP_TIMER, HALT_NO_RESPONSE, HALT_SERVER_NACK, HALT_T2_EXPIRED, NUM_RETRIES, okButtonString, reqDurationFieldString, reqPortFieldString, reqProtocolFieldString, resetButtonString, srvIPFieldString, srvPortFieldString, terminateButtonString, updateButtonString
 
Constructor Summary
DPRPClient()
          Creates a new DPRPClient object instance.
DPRPClient(DPRPLease il)
          Creates a new DPRPClient object from a pre-existing lease.
DPRPClient(java.net.InetAddress sIP, java.net.InetAddress cIP, int rPort, int rD, short rF, byte rProt)
          Creates a new DPRPClient object instance.
DPRPClient(java.lang.Thread ct)
          Creates a new DPRPClient object instance.
 
Method Summary
 void addDPRPLeaseListener(DPRPLeaseListener pl)
          Adds a listener to our internal list.
 void addLease(DPRPLease lea)
          Add a lease to the internal vector-o-leases.
 void dumpParameters()
          Prints all of the initial parameters to stdout.
protected  void fireReceiveLease(DPRPLease lea, char reason)
          Deprecated. This is only for backwards compatibility.
protected  void fireReceiveLease(DPRPLeaseEvent eventToSend)
          Send a new event to our listeners.
 java.net.InetAddress getClientIP()
          Gets our local IP address.
 int getDuration()
          Gets the duration that we are requesting.
 java.net.InetAddress getExternalIP()
          Gets the current notion of the external IP address.
 int getExternalPort()
          Gets the DPRP-leased external port.
 short getFlags()
          Gets the flags that we are sending in all requests.
 byte getProtocol()
          Gets the protocol that we are requesting for our port.
 int getRequestedPort()
          Gets the port that we're requesting from the gateway.
 java.net.InetAddress getServerIP()
          Gets the servers' internal IP address.
 int getServerPort()
          Gets the port to connect to on the server.
 java.lang.Thread getSessionThreadID()
          Returns the Thread object for the session.
 void interruptSession()
          Used by the GUI in order to pass immediate orders to the session (i.e.
 void kickoffNewRequest()
          Forces this client object to instantiate a new session thread, which does the actual lease gettin'/renewin'.
 void notifyController(DPRPLeaseEvent ev)
          Notifies whomever is controlling us that something has happend.
 java.lang.String ourAddrString()
          Returns our current client IP address, as a string.
 java.lang.String ourSrvAddrString()
          Returns our current notion of the server's IP address, as a string.
 java.lang.String ourSrvPortString()
          Returns the port to connect to on the server, as a string.
 void removeDPRPLeaseListener(DPRPLeaseListener pl)
          Removes a lease listener from our internal list.
 void rmLease(DPRPLease lea, DPRPLeaseEvent ev)
          Remove a lease from the internal vector-o-leases.
 void setClientIP(java.net.InetAddress cIP)
          Sets our local IP address.
 void setDuration(int durata)
          Sets the duration to request.
 void setExternalIP(java.net.InetAddress i)
          Sets the external IP address, after the lease has been acquired.
 void setExternalPort(int p)
          Sets the external port, after the lease has been acquired.
 void setFlags(short rF)
          Sets the flags that accompany all requests.
 void setProtocol(byte p)
          Sets the protocol to request.
 void setProtocol(java.lang.String str)
          Sets the protocol to request.
 void setRequestedPort(int rP)
          Sets the port number to request.
 void setServerIP(java.net.InetAddress sIP)
          Sets the server's IP address, to connect to.
 void setServerPort(int sPort)
          Sets the port on the server to connect to, initially.
 void setSessionThreadID(java.lang.Thread tid)
          Sets the thread ID of the session, so that we can properly interrupt it.
 void updateLease(DPRPLease curLea, DPRPLease newLea)
          Update a lease in the internal vector-o-leases.
 void waitForSession()
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEBUG

public static boolean DEBUG
Controls the printing of debug messages.

gotLease

public DPRPLease gotLease
Notifies the session that we already have a valid lease, and that it should simply sit on it (i.e. manage it).

sentRequest

public int sentRequest
Set by the caller, whenever it wants to interrupt the thread with new instructions.

returnLeaseEvent

public DPRPLeaseEvent returnLeaseEvent
For the legacy client interrupt method, passes a reference to a DPRPLeaseEvent object, which gives some details about this event..

srvIP

private java.net.InetAddress srvIP
The IP address of the gateway, that we connect to.

srvPort

private int srvPort
The UDP port on the server to connect to. This should really specify the main port on which the server is listening, and not ever point to any "per session" ports.

cliIP

private java.net.InetAddress cliIP
The IP address on the local machine that we are using.

cliPort

private int cliPort
The port on the local machine that we are using.

reqPort

private int reqPort
The port to request from the gateway.

reqDuration

private int reqDuration
The lease duration to request from the gateway.

reqFlags

private short reqFlags
The flags to accompany all messages to the gateway.

reqProtocol

private byte reqProtocol
The type of port to request from the gateway.

extPort

private int extPort

extIP

private java.net.InetAddress extIP

obtainedLeases

private java.util.Vector obtainedLeases
Internal variable, contains a reference to all outstanding leases for this client.

callerThread

private java.lang.Thread callerThread
A reference to the thread that started this object.

listenerList

private javax.swing.event.EventListenerList listenerList
A list of event listeners, who need to be notified whenever we muck with a lease.

sessionThreadID

private java.lang.Thread sessionThreadID
The Thread object for the client session.
Constructor Detail

DPRPClient

public DPRPClient()
Creates a new DPRPClient object instance.

DPRPClient

public DPRPClient(java.lang.Thread ct)
Creates a new DPRPClient object instance.
Parameters:
ct - A reference to a thread object, so that we can interrupt them if we so choose.

DPRPClient

public DPRPClient(java.net.InetAddress sIP,
                  java.net.InetAddress cIP,
                  int rPort,
                  int rD,
                  short rF,
                  byte rProt)
Creates a new DPRPClient object instance. I don't think that this constructor is ever called.

DPRPClient

public DPRPClient(DPRPLease il)
Creates a new DPRPClient object from a pre-existing lease. This is used when a GUI user loads a batch of saved leases from disk. A DPRPClient must be started for each lease (via this constructor), and the appropriate threads must be started. The session threads detect that they are being started from a previously negotiated (and still valid) lease, and thus don't try and get a new lease at the outset.
Parameters:
il - A valid DPRPLease, to base this session around.
Method Detail

addLease

public void addLease(DPRPLease lea)
Add a lease to the internal vector-o-leases.
Parameters:
lea - The 'DPRPLease' to be added.

rmLease

public void rmLease(DPRPLease lea,
                    DPRPLeaseEvent ev)
Remove a lease from the internal vector-o-leases.
Parameters:
lea - A lease to be removed.

updateLease

public void updateLease(DPRPLease curLea,
                        DPRPLease newLea)
Update a lease in the internal vector-o-leases. This is only ever called if the update has been successful. So, we always know that our notification is going to be one of success. Yay.
Parameters:
curLea - The current lease in the database.
newLea - The lease that is to replace the current lease.

kickoffNewRequest

public void kickoffNewRequest()
Forces this client object to instantiate a new session thread, which does the actual lease gettin'/renewin'.

waitForSession

public void waitForSession()

interruptSession

public void interruptSession()
Used by the GUI in order to pass immediate orders to the session (i.e. user requests immediate update or termination).

setSessionThreadID

public void setSessionThreadID(java.lang.Thread tid)
Sets the thread ID of the session, so that we can properly interrupt it. This is all quite hacky -- the thread must call back on us after it has been told to run, because only then, does the thread ID exist proper.
Parameters:
tid - A thread ID object, which we'll interrupt later.

notifyController

public void notifyController(DPRPLeaseEvent ev)
Notifies whomever is controlling us that something has happend. The exact details of this "happening" are included in the lease event object.
Parameters:
ev - A DPRPLeaseEvent, to be sent to whomever is controlling us (CLI or GUI).

setServerPort

public void setServerPort(int sPort)
Sets the port on the server to connect to, initially.

setDuration

public void setDuration(int durata)
Sets the duration to request.

setRequestedPort

public void setRequestedPort(int rP)
Sets the port number to request.

setFlags

public void setFlags(short rF)
Sets the flags that accompany all requests.

setProtocol

public void setProtocol(byte p)
Sets the protocol to request.

setProtocol

public void setProtocol(java.lang.String str)
Sets the protocol to request.

setClientIP

public void setClientIP(java.net.InetAddress cIP)
Sets our local IP address.

setServerIP

public void setServerIP(java.net.InetAddress sIP)
Sets the server's IP address, to connect to.

getServerPort

public int getServerPort()
Gets the port to connect to on the server.

getServerIP

public java.net.InetAddress getServerIP()
Gets the servers' internal IP address.

getClientIP

public java.net.InetAddress getClientIP()
Gets our local IP address.

getRequestedPort

public int getRequestedPort()
Gets the port that we're requesting from the gateway.

getDuration

public int getDuration()
Gets the duration that we are requesting.

getFlags

public short getFlags()
Gets the flags that we are sending in all requests.

getProtocol

public byte getProtocol()
Gets the protocol that we are requesting for our port.

getSessionThreadID

public java.lang.Thread getSessionThreadID()
Returns the Thread object for the session.

setExternalIP

public void setExternalIP(java.net.InetAddress i)
Sets the external IP address, after the lease has been acquired.

setExternalPort

public void setExternalPort(int p)
Sets the external port, after the lease has been acquired.

getExternalIP

public java.net.InetAddress getExternalIP()
Gets the current notion of the external IP address.

getExternalPort

public int getExternalPort()
Gets the DPRP-leased external port.

ourAddrString

public java.lang.String ourAddrString()
Returns our current client IP address, as a string. If no such address has been set, then we use the standard Java routines to get "our best guess" of the local address.
Returns:
A string, representing the dotted-quad version of our local IP address.

ourSrvAddrString

public java.lang.String ourSrvAddrString()
Returns our current notion of the server's IP address, as a string. Someday, this might try and get all fancy and return hostnames if available, or IP addresses if unavailable. But for now, we gots what we gots. The algorithm followed here is to check and see if srvIP has been set. If so, we return that. Otherwise, we see if cliIP has been set. It if has, then we find it's network address (based upon a 255.255.255.0 mask), and guess that the first addressable machine on that network (".1") is the gateway. Finally, as a last resort, we return the string "0.0.0.0" if we truly have nothing else.
Returns:
A string representation of the server's address.

ourSrvPortString

public java.lang.String ourSrvPortString()
Returns the port to connect to on the server, as a string.

dumpParameters

public void dumpParameters()
Prints all of the initial parameters to stdout.

addDPRPLeaseListener

public void addDPRPLeaseListener(DPRPLeaseListener pl)
Adds a listener to our internal list. This is the result of me trying to figure out how Swing event sourcing works, simply by reverse-engineering the functionality out of the JDK source. Since this appears to work, I'd say that I was pretty damn successful.
Parameters:
pl - A DPRPLeaseListener to be added as the target of fired events.

removeDPRPLeaseListener

public void removeDPRPLeaseListener(DPRPLeaseListener pl)
Removes a lease listener from our internal list.
Parameters:
pl - A DPRPLeaseListener who no longer wishes to receive events.

fireReceiveLease

protected void fireReceiveLease(DPRPLease lea,
                                char reason)
Deprecated. This is only for backwards compatibility.

Send a new event to our listeners. This just makes an DPRPLeaseEvent object, and calls the real fireReceiveLease() method.
Parameters:
lea - A lease to send.
reason - Why we're sending said lease.

fireReceiveLease

protected void fireReceiveLease(DPRPLeaseEvent eventToSend)
Send a new event to our listeners. This is the real magilla, and as it turns out, this method is mostly comments. There is some magic in the listeners, that intercepts the calls to receiveLease(), and schedules them to occur serially in the worker thread.
Parameters:
eventToSend - A nice DPRPLeaseEvent object, which I can customize to my will, passing all sorts of data in an event.