ostore.oil.patchwork
Class PatchworkModel

java.lang.Object
  |
  +--ostore.oil.patchwork.PatchworkModel
All Implemented Interfaces:
Model, QuickSerializable

public class PatchworkModel
extends Object
implements Model

The PatchworkModel is built by the PatchworkStage code, and is used for collecting network statistics. It implements the ostore.oil.Model interface, although not all methods are currently implemented. It remembers observations sent to it (only up to MAX_OBSERVATIONS of them, which is currently set at 1000), and when recalculate is called it produces a PatchworkModel.Delta that contains the difference between the current model and the last one produced from a call to recalculate.

The values contained in the model represent averages of the statistics over the number of observations that existed for that node when recalculate was called. It only considers a change worthy of noting if it is greater than VALID_DELTA_CHANGE percent, currently set at 5%.

Currently, the integer values and their corresponding types are as follows:

latency: PatchworkModel.LATENCY

bandwidth: PatchworkModel.BANDWIDTH

loss: PatchworkModel.LOSS

For a more complete description of these statistics, see PatchworkStage.

Version:
$Id: PatchworkModel.java,v 1.2 2001/12/04 19:43:17 strib Exp $
Author:
Jeremy Stribling
See Also:
Model

Inner Class Summary
static class PatchworkModel.Delta
          A PatchworkModel.Delta object contains a diff of the sufficient statistics for a PatchworkModel.
static class PatchworkModel.InvalidTypeException
          A Patchwork.InvalidTypeException notes that an invalid type has been given to the PatchworkModel system
static class PatchworkModel.Observation
          A Patchwork.Observation object contains an observation recorded by the patchwork stage.
 
Inner classes inherited from class ostore.oil.Model
Model.Delta, Model.Prediction
 
Field Summary
static int BANDWIDTH
           
static int LATENCY
           
static int LOSS
           
 
Constructor Summary
PatchworkModel()
          Create a new PatchworkModel.
PatchworkModel(byte[] data, int[] offset)
          Create a PatchworkModel from its QuickSerializable form.
 
Method Summary
 void add_delta(Model.Delta d)
          Specified by ostore.oil.Model interface
 void clear()
          Specified by ostore.oil.Model interface
 void clear(int num)
          Specified by ostore.oil.Model interface
 double loglikelihood()
          Not yet implemented.
 double lookupDouble(NodeId peer, int type)
          Returns the most recently calculated double value of type type for the specified node id peer.
 QuickSerializable[] outliers()
          Not yet implemented.
 Model.Prediction predict(int horizon)
          Not yet implemented.
 Model.Delta recalculate()
          Specified by ostore.oil.Model interface
 void record(QuickSerializable observation)
          Specified by ostore.oil.Model interface
 void record(QuickSerializable[] observations)
          Specified by ostore.oil.Model interface
 void to_bytes(byte[] data, int[] offset)
          Specified by ostore.util.QuickSerializable
 String toString()
          Returns a string representation of the object
 int type_code()
          Specified by ostore.util.QuickSerializable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LATENCY

public static final int LATENCY

BANDWIDTH

public static final int BANDWIDTH

LOSS

public static final int LOSS
Constructor Detail

PatchworkModel

public PatchworkModel(byte[] data,
                      int[] offset)
               throws QSException
Create a PatchworkModel from its QuickSerializable form.

PatchworkModel

public PatchworkModel()
Create a new PatchworkModel.
Method Detail

record

public void record(QuickSerializable[] observations)
Specified by ostore.oil.Model interface
Specified by:
record in interface Model
Following copied from interface: ostore.oil.Model
Parameters:
observations - An array of events, values, etc., not necessarily all the same type, that this Model understands.
Throws:
IllegalArgumentException - if the particular subclass of Model cannot process the observation.

record

public void record(QuickSerializable observation)
Specified by ostore.oil.Model interface
Specified by:
record in interface Model
Following copied from interface: ostore.oil.Model
Parameters:
observation - Any event, value, etc. that this Model understands.
Throws:
IllegalArgumentException - if the particular subclass of Model cannot process the observation.

clear

public void clear(int num)
Specified by ostore.oil.Model interface
Specified by:
clear in interface Model

clear

public void clear()
Specified by ostore.oil.Model interface
Specified by:
clear in interface Model

lookupDouble

public double lookupDouble(NodeId peer,
                           int type)
Returns the most recently calculated double value of type type for the specified node id peer. Returns Double.NaN if a value is not recorded.
Parameters:
peer - the node for which to lookup the statistic
type - the type of statistic to collect (i.e. LATENCY, BANDWIDTH, etc)
Returns:
the statistic if it exists, Double.NaN otherwise
Throws:
PatchworkModel.InvalidTypeException - if an invalid type is passed in

outliers

public QuickSerializable[] outliers()
Not yet implemented. Specified by ostore.oil.Model interface
Specified by:
outliers in interface Model
Following copied from interface: ostore.oil.Model
Returns:
an array containing recent observations which the model did not expect.

add_delta

public void add_delta(Model.Delta d)
Specified by ostore.oil.Model interface
Specified by:
add_delta in interface Model
Following copied from interface: ostore.oil.Model
Throws:
IllegalArgumentException - if the Delta object is not of the correct subclass.

loglikelihood

public double loglikelihood()
Not yet implemented. Specified by ostore.oil.Model interface
Specified by:
loglikelihood in interface Model
Following copied from interface: ostore.oil.Model
Returns:
a non-positive number equal to the logarithm of the probability of the observations (D) given the current model (M); log(p(D|M)). If no observations exist, it returns Double.NaN.

recalculate

public Model.Delta recalculate()
Specified by ostore.oil.Model interface
Specified by:
recalculate in interface Model
Following copied from interface: ostore.oil.Model
Returns:
A Delta storing the difference between the new model parameters and the old.

predict

public Model.Prediction predict(int horizon)
Not yet implemented. Specified by ostore.oil.Model interface
Specified by:
predict in interface Model
Following copied from interface: ostore.oil.Model
Returns:
A Prediction, whose semantics depends on the particular subclass of Model.

to_bytes

public void to_bytes(byte[] data,
                     int[] offset)
Specified by ostore.util.QuickSerializable
Specified by:
to_bytes in interface QuickSerializable
Following copied from interface: ostore.util.QuickSerializable
Parameters:
data - The byte array to store into, or null.
offset - A single element array whose first element is the index in data to begin writing at on function entry, and which on function exit has been incremented by the number of bytes written.

type_code

public int type_code()
Specified by ostore.util.QuickSerializable
Specified by:
type_code in interface QuickSerializable
Following copied from interface: ostore.util.QuickSerializable
Returns:
an integer unique to this class

toString

public String toString()
Returns a string representation of the object
Overrides:
toString in class Object