no.ntnu.item.router
Class ActionReasoner

java.lang.Object
  extended by java.lang.Thread
      extended by no.ntnu.item.router.ActionReasoner
All Implemented Interfaces:
java.lang.Runnable

public class ActionReasoner
extends java.lang.Thread

This class will have an overview of the ServiceSession objects
that have a target bit rate set. It will, based on this information
change parameters in the click router to facilitate the wanted effect.
It will continuously communicate with click and decide when to do what.

Author:
Kristian Haugene

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean listHasChanged
          Indicates if the list has been changed since last configuration
private  java.util.List<ServiceSession> markedSessions
          Holds the list of ServiceSession objects to monitor for
private  java.util.List<SessionHandlerInfo> sessionHandlerInfoList
          Current string that is written to the Click handler file
private  java.util.List<ServiceSession> updatedSessions
          list of ServiceSession to store updates before processing
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ActionReasoner()
          Constructor.
 
Method Summary
private  java.lang.Boolean areListsEqual(java.util.List<SessionHandlerInfo> newList)
          Will compare the given list with this.sessionHandlerInfoList
Will determine if the lists are approximately equal.
The reason we say approximately equal is that we allow some margins on ping.
private  void calculateClickHandlerChange()
          This method will check all sessions.
private  void decrementClickTargetRate(ServiceSession session)
          This method will decrement click target rate for a session.
private  void doListHasChangedRoutine()
          A neat little method to clean and refactor the code.
private  java.util.List<SessionHandlerInfo> getNewListOfSessionHandlerInfo()
          This method will based on the sessions in the markedSessions list generate a list of SessionHandlerInfo objects.
These objects will represent the session information relevant to the handler
private  void increaseSessionRate(ServiceSession markedSession)
          This method will increase the click target rate for a given session.
private  void incrementClickTargetRate(ServiceSession session)
          This method will increment click target rate for a session.
private  boolean isTargetVideoBitrateChanged(ServiceSession markedSession)
          Checks if the session has changed targetVideoBitrate since last time we read it.
private  void lowerSessionRate(ServiceSession session)
          This method will tell click to lower the rate for this session
 void run()
          The thread main method.
private  void setFirstLoweredClickTargetRate(ServiceSession session)
          This method will set an initial click target value for a session.
private  java.lang.Boolean targetRateIsLowerThanCurrentRate(ServiceSession session)
          Checks if the target rate is lower than the actual rate, ie if we need to inhibit it.
private  java.lang.Boolean targetRateIsMet(ServiceSession session)
          Checks if a ServiceSession is downloading at its target rate
 void updateListOfMarkedSessions(java.util.List<ServiceSession> newList)
          Update the ActionReasoner list of sessions.
private  void writeFile(java.lang.String filename, java.lang.String text)
          Takes a path and text as paramters.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

markedSessions

private java.util.List<ServiceSession> markedSessions
Holds the list of ServiceSession objects to monitor for


updatedSessions

private java.util.List<ServiceSession> updatedSessions
list of ServiceSession to store updates before processing


listHasChanged

private boolean listHasChanged
Indicates if the list has been changed since last configuration


sessionHandlerInfoList

private java.util.List<SessionHandlerInfo> sessionHandlerInfoList
Current string that is written to the Click handler file

Constructor Detail

ActionReasoner

public ActionReasoner()
Constructor. Start the thread

Method Detail

run

public void run()
The thread main method. Loop to check for changes and calculate action.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

updateListOfMarkedSessions

public void updateListOfMarkedSessions(java.util.List<ServiceSession> newList)
Update the ActionReasoner list of sessions.

Parameters:
newList - the updated list

increaseSessionRate

private void increaseSessionRate(ServiceSession markedSession)
This method will increase the click target rate for a given session.

Parameters:
markedSession - to increase click rate for

incrementClickTargetRate

private void incrementClickTargetRate(ServiceSession session)
This method will increment click target rate for a session. It will be incremented given that there is at least 10 seconds since last change to the rate. If not enough time has passed, do nothing

Parameters:
session - to increment click target rate for

lowerSessionRate

private void lowerSessionRate(ServiceSession session)
This method will tell click to lower the rate for this session

Parameters:
session - the session to slow down

decrementClickTargetRate

private void decrementClickTargetRate(ServiceSession session)
This method will decrement click target rate for a session. It will be decremented given that there is at least 10 seconds since last change to the rate. If not enough time has passed, do nothing

Parameters:
session - to decrement click target rate for

setFirstLoweredClickTargetRate

private void setFirstLoweredClickTargetRate(ServiceSession session)
This method will set an initial click target value for a session. We have a distinct click target value so that we can vary this to obtain the user target value without actually changing the user target value and show this in the GUI. The initial click target is determined to be in between the user target and the next available bit rate. That is, if the user wants a quality level 800, and the next quality level is 1000 we will set 900. This is to give room for the 800 stream to function well, but not enough bandwidth to run the 1000 quality level.

Parameters:
session - the session to set initial click target value for

targetRateIsMet

private java.lang.Boolean targetRateIsMet(ServiceSession session)
Checks if a ServiceSession is downloading at its target rate

Parameters:
session - session to check for
Returns:
returns true if target rate is equal to download rate OR target rate is not set. False otherwise

targetRateIsLowerThanCurrentRate

private java.lang.Boolean targetRateIsLowerThanCurrentRate(ServiceSession session)
Checks if the target rate is lower than the actual rate, ie if we need to inhibit it.

Parameters:
session - session to check for
Returns:
returns true if target rate is less than actual, false if equal or greater

calculateClickHandlerChange

private void calculateClickHandlerChange()
This method will check all sessions. Based on this info it will calculate the wanted parameter to pass to the Click handler. For each time this method is called it will do this calculation. If the calculated handler parameter varies from earlier values, the handler will be rewritten.

The Click handler expects clientIp, sourceIp, RTT and targetRate. Values are separated by ':' and sets of values are separated by ','


areListsEqual

private java.lang.Boolean areListsEqual(java.util.List<SessionHandlerInfo> newList)
Will compare the given list with this.sessionHandlerInfoList
Will determine if the lists are approximately equal.
The reason we say approximately equal is that we allow some margins on ping. We want the ping to have changed more than a certain threshold before we rewrite the Click handler.

The lists will have to be of equal length, containing the same objects, with the same target click rate. The ping values should also be relatively close. If they are equal, except from a small change in ping, we return true.

Parameters:
newList - the list to compare to this.sessionHandlerInfoList
Returns:
true if they are equal or have a small difference in ping values, false otherwise

getNewListOfSessionHandlerInfo

private java.util.List<SessionHandlerInfo> getNewListOfSessionHandlerInfo()
This method will based on the sessions in the markedSessions list generate a list of SessionHandlerInfo objects.
These objects will represent the session information relevant to the handler

Returns:
list of information representing the wanted sessions

doListHasChangedRoutine

private void doListHasChangedRoutine()
A neat little method to clean and refactor the code. Will be called if the listHasChanged flag i set.Should then update the list we are working on and set the flag false. We set the updatedList to null, so that if anyone ever uses that list they will know it's wrong


isTargetVideoBitrateChanged

private boolean isTargetVideoBitrateChanged(ServiceSession markedSession)
Checks if the session has changed targetVideoBitrate since last time we read it.

Parameters:
markedSession - to retrieve oldTarget and Target from
Returns:
true if changed, false otherwise

writeFile

private void writeFile(java.lang.String filename,
                       java.lang.String text)
Takes a path and text as paramters. Writes the text to the given path.

Parameters:
filename - path to file
text - String to write