ostore.update
Class Update

java.lang.Object
  |
  +--ostore.update.Update
All Implemented Interfaces:
QueueElementIF, QuickSerializable

public class Update
extends Object
implements QuickSerializable, QueueElementIF

All OceanStore updates are represented as an Update object. An Update is an ordered list of predicate/action tuples which are represented by UpdateTuple objects. Each tuple contains one Predicate and one Action. The Predicate is the root of a boolean expression of predicates. An Action is the first of a list of actions.

To apply an update, the update stage examines each UpdateTuple in turn. If the Predicate of the tuple evaluates to true, the corresponding Action is applied and the Update is said to have committed. After an Update has committed, no other tuples are examined. If all Predicates evaluate to false, no Action is applied. The Update is said to have aborted.

Version:
$Id: Update.java,v 1.49 2003/11/17 23:52:43 emilong Exp $
Author:
Patrick R. Eaton
See Also:
UpdateTuple, Predicate, Action

Field Summary
static boolean DEBUG
           
 
Constructor Summary
Update(InputBuffer buffer)
           
Update(SecureHash principal, SecureHash client)
          Create a new Update.
Update(SecureHash principal, SecureHash client, UpdateTuple tuple)
          Create a new Update containing the specified tuple.
Update(SecureHash principal, SecureHash client, UpdateTuple[] tuples)
          Create a new Update containing the specified tuples.
 
Method Summary
 void appendTuple(UpdateTuple tuple)
          Add a tuple to the update.
 UpdateResult apply(UpdateRequest request, DataCache cache)
          Apply the update.
 UpdateResult apply(UpdateRequest update_request, UpdateContinuation continuation, DataCache cache)
          Apply a previously-started update.
 SecureHash getClient()
          Return the hash of the client machine from which the update originated.
 SecureHash getFirstTarget()
           
 SecureHash getPrincipal()
          Return the hash of the principal that created the update.
 Set getTargets()
          Returns the set of potential targets of this update.
 QSDate getTimestamp()
          Return the timestamp of the update.
 UpdateTuple getTuple(int index)
          Return a specified tuple.
 Iterator getTuples()
          Return an iterator of the tuples in the update.
 int numTargets()
          Return the number of potential targets of the update.
 int numTuples()
          Return the number of tuples in the update.
 void prependTuple(UpdateTuple tuple)
          Add a tuple to the update.
 void serialize(OutputBuffer buffer)
          Add the object to the buffer.
 String toString()
          Return the string representation of the update.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values
Constructor Detail

Update

public Update(SecureHash principal,
              SecureHash client)
Create a new Update.

Parameters:
principal - the hash of the principal that created this update
client - the hash of the client machine from where this update originated

Update

public Update(SecureHash principal,
              SecureHash client,
              UpdateTuple tuple)
Create a new Update containing the specified tuple.

Parameters:
principal - the hash of the principal that created this Update
client - the hash of the client machine from where this update originated
tuple - a tuple to be included in the update

Update

public Update(SecureHash principal,
              SecureHash client,
              UpdateTuple[] tuples)
Create a new Update containing the specified tuples.

Parameters:
principal - the hash of the principal that created this Update
client - the hash of the client machine from where this update originated
tuples - an array of tuples to be included in the update. The ordering of the tuples in the array will be maintained in the update

Update

public Update(InputBuffer buffer)
       throws QSException
Method Detail

serialize

public void serialize(OutputBuffer buffer)
Description copied from interface: QuickSerializable
Add the object to the buffer.

Specified by:
serialize in interface QuickSerializable
Parameters:
buffer - the output buffer to add the object to

getPrincipal

public SecureHash getPrincipal()
Return the hash of the principal that created the update.

Returns:
the hash of the principal that created the update

getClient

public SecureHash getClient()
Return the hash of the client machine from which the update originated.

Returns:
the hash of the client machine from which the update originated

numTuples

public int numTuples()
Return the number of tuples in the update.

Returns:
the number of tuples in the update

appendTuple

public void appendTuple(UpdateTuple tuple)
Add a tuple to the update. The tuple is ordered as the last tuple in the update.

Parameters:
tuple - a tuple to add to the update

prependTuple

public void prependTuple(UpdateTuple tuple)
Add a tuple to the update. The tuple is ordered as the first tuple in the Update; all other tuples are shifted one spot down in the order.

Parameters:
tuple - a tuple to add to the update

getTuples

public Iterator getTuples()
Return an iterator of the tuples in the update.

Returns:
an iterator of tuples

getTuple

public UpdateTuple getTuple(int index)
Return a specified tuple.

Parameters:
index - the index (0-based) of the desired tuple.
Returns:
The specified UpdateTuple.

numTargets

public int numTargets()
Return the number of potential targets of the update.

Returns:
the number of potential targets of the Update

getFirstTarget

public SecureHash getFirstTarget()

getTargets

public Set getTargets()
Returns the set of potential targets of this update.

Returns:
a set which contains the potential targets of this update

getTimestamp

public QSDate getTimestamp()
Return the timestamp of the update.

Returns:
the timestamp of this update

toString

public String toString()
Return the string representation of the update.

Overrides:
toString in class Object
Returns:
the string representation of the update

apply

public UpdateResult apply(UpdateRequest request,
                          DataCache cache)
                   throws ostore.update.UpdateException
Apply the update.

Parameters:
request - the update request currently being serviced
cache - TODO
Returns:
the result of the update
Throws:
ostore.update.UpdateException - if the update interrupted for any reason

apply

public UpdateResult apply(UpdateRequest update_request,
                          UpdateContinuation continuation,
                          DataCache cache)
                   throws ostore.update.UpdateException
Apply a previously-started update.

Parameters:
update_request - the update request currently being serviced
continuation - the state of update so that it may be restarted
Returns:
the result of the update
Throws:
ostore.update.UpdateException - if the update interrupted for any reason