tapestry.patchwork
Class Patch

java.lang.Object
  |
  +--tapestry.patchwork.Patch
Direct Known Subclasses:
LatencyPatch, LossPatch, RecalcPatch

public abstract class Patch
extends Object

Abstract class from which all measurements modules (Patches) extend. Contains a large amount of functionality that all Patches share. Also defines the types used to identify different types of measurements to the outside world (and the inside world, as well).

Version:
$Id: Patch.java,v 1.1.1.1 2004/03/26 19:57:10 hweather Exp $
Author:
Jeremy Stribling

Nested Class Summary
protected  class Patch.SeqNo
          Internal class for wrapping sequence numbers
 
Field Summary
protected  Classifier _classifier
           
protected  FaultAdmin _fault_admin
           
protected  Period _period
           
protected  HashMap _probe_times
           
protected  PriorityQueue _queue
           
protected  HashMap _quick_stats
           
protected  NodeId _self_node_id
           
protected  HashMap _seq_nos
           
protected  PatchworkTable _table
           
protected  byte _type
           
protected static Object _udp_lock
           
protected static NonblockingDatagramSocket _udp_socket
           
protected  HashMap _userdata_sinks
           
protected static SelectItem _write_selitem
           
protected static SelectSet _write_selset
           
protected  String class_tag
           
protected  boolean DEBUG
           
static int NUM_TYPES
          The total number of measurement types
protected static boolean sim_running
           
static byte TYPE_BANDWIDTH
          Measurement type for bandwidth
static byte TYPE_LATENCY
          Measurement type for latency
static byte TYPE_LOSS
          Measurement type for loss rate
protected static byte TYPE_RECALC
          Measurement type for recalculation (internal use only)
protected static boolean use_tcp
           
 
Constructor Summary
Patch(NodeId self_node_id, Classifier classifier, PatchworkTable table, FaultAdmin fault_admin, Period period)
          Create a new Patch.
 
Method Summary
 void addMonitorAll(Object userData, SinkIF sink)
          Tells this patch that a node wants to hear about status messages from everyone.
 void addNode(NodeId node, int level, Object userData, SinkIF sink)
          Tell this Patch to begin monitoring a node at some probing level
protected  void addToQueue(NodeId node)
          Add this node back on the queue.
protected  void dispatch(ProbeMsg event)
          An internal method used for dispatching probe messages (UDP)
protected  void dispatch(QueueElementIF event)
          An internal method used for dispatching events
protected  void enqueue(QueueElementIF event, SinkIF sink)
           
protected  int getAndUpdateSeqNo(NodeId node)
          Get the next sequence number for this node, and update it for next time.
protected abstract  void handleAlarm(AlarmMsg alarm)
           
 void handleEvent(PatchMsg msg, long timeReceived)
          Handle events given the exact time they were received by Patchwork.
protected  void handleProbe(ProbeMsg inProbe)
           
protected abstract  void handleProbeResponse(ProbeMsg response, long timeRecvd)
          Handle the response to a probe.
protected  void handleQuickStatProbeResp(NodeId peer, long value)
          Got a response to a quick stat probe, with the given observed measurement.
protected  void handleQuickStatReq(QuickStatReq msg)
           
protected  void handleQuickStatTimeout(QuickStatTimeout msg)
           
protected abstract  void handleTimeout(ProbeTimeout timeout)
           
protected  void handleUnknown(PatchMsg msg)
          Got a message we weren't expecting, did we?
protected  void makeObservation(NodeId peer, long value)
          Record an observation (of the Patch's type) in the table
protected  void makeObservation(NodeId peer, long value, byte type)
          Record an observation (of arbitrary type) in the table
protected  long registerResponse(ProbeMsg response)
          We received a response, so figure out state
protected  boolean registerTimeout(ProbeTimeout pt)
          Got a timeout for a probe.
 void removeNode(NodeId node, Object userData, SinkIF sink)
          Tell this Patch to stop monitoring a node
protected  void sendProbe(ProbeMsg probe)
          Send a probe to another node, expecting a response back.
protected  void sendQuickStatProbe(NodeId peer)
          Send a standard quick probe to the given node.
protected  void setNextAlarm()
          Pick the node from the queue that needs to be probed the soonest, and set the alarm for it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

class_tag

protected String class_tag

DEBUG

protected boolean DEBUG

sim_running

protected static boolean sim_running

use_tcp

protected static boolean use_tcp

TYPE_LOSS

public static final byte TYPE_LOSS
Measurement type for loss rate

See Also:
Constant Field Values

TYPE_LATENCY

public static final byte TYPE_LATENCY
Measurement type for latency

See Also:
Constant Field Values

TYPE_BANDWIDTH

public static final byte TYPE_BANDWIDTH
Measurement type for bandwidth

See Also:
Constant Field Values

TYPE_RECALC

protected static final byte TYPE_RECALC
Measurement type for recalculation (internal use only)

See Also:
Constant Field Values

NUM_TYPES

public static final int NUM_TYPES
The total number of measurement types

See Also:
Constant Field Values

_self_node_id

protected NodeId _self_node_id

_classifier

protected Classifier _classifier

_table

protected PatchworkTable _table

_fault_admin

protected FaultAdmin _fault_admin

_type

protected byte _type

_seq_nos

protected HashMap _seq_nos

_probe_times

protected HashMap _probe_times

_quick_stats

protected HashMap _quick_stats

_userdata_sinks

protected HashMap _userdata_sinks

_udp_socket

protected static NonblockingDatagramSocket _udp_socket

_write_selset

protected static SelectSet _write_selset

_write_selitem

protected static SelectItem _write_selitem

_udp_lock

protected static Object _udp_lock

_queue

protected PriorityQueue _queue

_period

protected Period _period
Constructor Detail

Patch

public Patch(NodeId self_node_id,
             Classifier classifier,
             PatchworkTable table,
             FaultAdmin fault_admin,
             Period period)
Create a new Patch.

Parameters:
self_node_id - this node's id
classifier - this node's classifier
table - the collection of measurements from this node to other nodes
period - defines the periodic function governing the probes of this Patch
Method Detail

addNode

public void addNode(NodeId node,
                    int level,
                    Object userData,
                    SinkIF sink)
Tell this Patch to begin monitoring a node at some probing level

Parameters:
node - the node to begin monitoring
level - the probing level for that node
userData - an object that will identify this monitoring instance to the calling application
sink - the sink on which to enqueue status responses

addMonitorAll

public void addMonitorAll(Object userData,
                          SinkIF sink)
Tells this patch that a node wants to hear about status messages from everyone.

Parameters:
userData - an object that will identify this monitoring instance to the calling application
sink - the sink on which to enqueue status responses

removeNode

public void removeNode(NodeId node,
                       Object userData,
                       SinkIF sink)
Tell this Patch to stop monitoring a node

Parameters:
node - the node to stop monitoring
userData - an object that will identify this monitoring instance to the calling application
sink - the sink on which to enqueue status responses

addToQueue

protected void addToQueue(NodeId node)
Add this node back on the queue. If it is supposed to be probed before the node that currently has the alarm set, interrupt that alarm and set it for the new guy.

Parameters:
node - the node to add

setNextAlarm

protected void setNextAlarm()
Pick the node from the queue that needs to be probed the soonest, and set the alarm for it.


handleEvent

public void handleEvent(PatchMsg msg,
                        long timeReceived)
Handle events given the exact time they were received by Patchwork.

Parameters:
msg - the msg to handle
timeReceived - the absolute time (in microseconds) msg was received

handleUnknown

protected void handleUnknown(PatchMsg msg)
Got a message we weren't expecting, did we?


handleQuickStatReq

protected void handleQuickStatReq(QuickStatReq msg)

handleQuickStatProbeResp

protected void handleQuickStatProbeResp(NodeId peer,
                                        long value)
Got a response to a quick stat probe, with the given observed measurement.


handleQuickStatTimeout

protected void handleQuickStatTimeout(QuickStatTimeout msg)

sendQuickStatProbe

protected void sendQuickStatProbe(NodeId peer)
Send a standard quick probe to the given node.


makeObservation

protected void makeObservation(NodeId peer,
                               long value)
Record an observation (of the Patch's type) in the table

Parameters:
peer - the node being observed
value - the value of the observed measurement

makeObservation

protected void makeObservation(NodeId peer,
                               long value,
                               byte type)
Record an observation (of arbitrary type) in the table

Parameters:
peer - the node being observed
value - the value of the observed measurement
type - the type of the observation

handleProbeResponse

protected abstract void handleProbeResponse(ProbeMsg response,
                                            long timeRecvd)
Handle the response to a probe.

Parameters:
response - the response
timeRecvd - the absolute time the repsonse was received (in microseconds)

handleAlarm

protected abstract void handleAlarm(AlarmMsg alarm)

handleTimeout

protected abstract void handleTimeout(ProbeTimeout timeout)

handleProbe

protected void handleProbe(ProbeMsg inProbe)

sendProbe

protected void sendProbe(ProbeMsg probe)
Send a probe to another node, expecting a response back.


registerResponse

protected long registerResponse(ProbeMsg response)
We received a response, so figure out state

Returns:
the time the probe was sent to which this was a response (in microseconds)

registerTimeout

protected boolean registerTimeout(ProbeTimeout pt)
Got a timeout for a probe.

Returns:
true iff a response was not yet received for the probe connected with this timeout

getAndUpdateSeqNo

protected int getAndUpdateSeqNo(NodeId node)
Get the next sequence number for this node, and update it for next time.

Returns:
the sequence number to use for the next probe.

dispatch

protected void dispatch(QueueElementIF event)
An internal method used for dispatching events


dispatch

protected void dispatch(ProbeMsg event)
An internal method used for dispatching probe messages (UDP)


enqueue

protected void enqueue(QueueElementIF event,
                       SinkIF sink)