|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--edu.uiuc.cs.net.DPRPManager.DPRPClientSession
This class represents an individual DPRP Client session. Essentially, this means that this object is instantiated into a new thread. Then, it starts by negotiating a lease from the server. If this is successful, it sleeps until such a time until it must renew the lease. If the renewal process is successful, it will sleep again, repeating this cycle for as long as it can.
Field Summary | |
private DPRPClient |
client
A reference to the client object that spawned us. |
private DPRPLease |
curLease
A reference to the current lease that we are holding. |
private java.net.InetAddress |
myIP
Our local IP address, as specified when the client was launched. |
private int |
myPort
Local port, associated with the socket. |
private DPRPSocket |
mySock
Local socket, refreshed for each new request. |
private int |
reqDuration
The lease duration to request for our lease. |
private short |
reqFlags
The flags to guide the lease request. |
private byte |
reqProtocol
The protocol to request for our lease. |
private int |
requestedPort
A specific port that we'd like to request. |
private java.net.InetAddress |
serverIP
The IP address of the server that will give us the goods. |
private int |
serverPort
The port on the server to connect to. |
Fields inherited from class java.lang.Thread |
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ |
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 | |
DPRPClientSession(DPRPClient pcp)
Constructs a new DPRPClientSession out of a DPRPClient object instance. |
Method Summary | |
private void |
allocNewMySock()
Allocates a new socket. |
private DPRPMessage |
createNewMessage()
Simply creates a new DPRPMessage, and fills it in with the parameters that we know. |
java.lang.Thread |
getThreadID()
Used by the parent DPRPClient in order to interrupt us when (and if) needed. |
private int |
maintainCurrentLease()
Looks after the upkeep of the current lease, by renewing it before it expires. |
private DPRPLease |
renewLease(DPRPLease lea)
Attempts to renew an outstanding lease. |
private DPRPLease |
requestLease()
Uses lower-level methods to request a lease from the server. |
void |
run()
The method invoked at thread creation, to start things off. |
private DPRPMessage |
sendAndRecvMessage(DPRPMessage outMessage)
Keep sending the given message until an appropriate response is received from the server. |
private DPRPMessage |
sendCliRequest()
Sends a DPRP_CLI_REQUEST message to the server. |
private DPRPMessage |
sendPortAck(DPRPMessage sentMessage)
Accepts an offered port from the server. |
private DPRPMessage |
sendPortNack(DPRPMessage msg)
Sends 'CLI_OFFER_NACK' in response to offer contained in parameter 'msg'. |
private DPRPLease |
terminateLease(DPRPLease lea)
Sends a CLI_TERMINATE_LEASE message, immediately
revoking the given lease. |
Methods inherited from class java.lang.Thread |
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private java.net.InetAddress serverIP
private int serverPort
private int requestedPort
private java.net.InetAddress myIP
private int myPort
private DPRPSocket mySock
private DPRPClient client
private int reqDuration
private short reqFlags
private byte reqProtocol
private DPRPLease curLease
Constructor Detail |
public DPRPClientSession(DPRPClient pcp)
pcp
- A DPRPClient instance, to base ourselves
off of.Method Detail |
public java.lang.Thread getThreadID()
public void run()
run
in class java.lang.Thread
private int maintainCurrentLease() throws DPRPErrorMessageException
DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPLease requestLease() throws DPRPErrorMessageException
DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPLease renewLease(DPRPLease lea) throws DPRPErrorMessageException
lea
- The current outstanding lease to be renewed.DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPMessage sendCliRequest() throws DPRPErrorMessageException
DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPMessage sendPortAck(DPRPMessage sentMessage) throws DPRPErrorMessageException
sentMessage
- A skeleton of the message to send (type and
addresses are not correct).DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPMessage sendPortNack(DPRPMessage msg) throws DPRPErrorMessageException
msg
- An offer message that we don't like. Basis for the Nack.DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPLease terminateLease(DPRPLease lea) throws DPRPErrorMessageException
CLI_TERMINATE_LEASE
message, immediately
revoking the given lease.lea
- A lease for which we want to immediately revoke our
handle.null
.DPRPErrorMessageException
- This is passed on from the call to
sendAndRecvMessage().private DPRPMessage sendAndRecvMessage(DPRPMessage outMessage) throws DPRPErrorMessageException
null
in the event that the server cannot be contacted, or if there
is a socket error. Of course, I chould just make up new
DPRPErrors for these situations, which is an
interesting thought. I could throw UNKNOWN_ERRORS for the time being.
The problem with this idea is that in the catch, I'd have to check to see if this is a 'soft error' (i.e., I should retry), or if it is a 'hard error' (i.e., we got an error message). So, I'm going to leave the status quo for now.
outMessage
- The outgoing DPRPMessage to be sent.DPRPErrorMessageException
- If an actual, honest-to-goodness,
error message is received from the server.private DPRPMessage createNewMessage()
private void allocNewMySock()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |