no.ntnu.item.router.utilities
Class SessionPinger

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

public class SessionPinger
extends java.lang.Thread

This class will obtain ping measurements for the given ServiceSession

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
(package private)  java.lang.Double[] pingValues
          Holds the 5 last ping values for computing average
private  ServiceSession serviceSession
          The ServiceSession for which this class will sample ping
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SessionPinger(ServiceSession session)
          Constructor.
 
Method Summary
private  void addPingValue(java.lang.Double pingAddress)
          Updates the array of ping values with a new one
private static void close(java.io.Closeable c)
          Closes the object given as parameter
 java.lang.Double getPing()
          Uses the array of ping values.
Summarizes and averages them.
private  boolean haveNoPingValues()
          Checks if the pingValues array is empty(all 0)
private  java.lang.Double pingAddress(java.net.InetSocketAddress addr)
          /** Running ping command in linux.
 void run()
          The running method
 
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

serviceSession

private ServiceSession serviceSession
The ServiceSession for which this class will sample ping


pingValues

java.lang.Double[] pingValues
Holds the 5 last ping values for computing average

Constructor Detail

SessionPinger

public SessionPinger(ServiceSession session)
Constructor. Set local variable, start thread

Parameters:
session - the session to ping for
Method Detail

run

public void run()
The running method

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

getPing

public java.lang.Double getPing()
Uses the array of ping values.
Summarizes and averages them.

Returns:
ping as double

addPingValue

private void addPingValue(java.lang.Double pingAddress)
Updates the array of ping values with a new one

Parameters:
pingAddress - to add

pingAddress

private java.lang.Double pingAddress(java.net.InetSocketAddress addr)
/** Running ping command in linux. Will return the ping value

Parameters:
addr - address of the server to ping
Returns:
decimal ping value

haveNoPingValues

private boolean haveNoPingValues()
Checks if the pingValues array is empty(all 0)

Returns:
true if all elements are 0, false otherwise

close

private static void close(java.io.Closeable c)
Closes the object given as parameter

Parameters:
c - a closable object