org.coweb.oe
Class Operation

java.lang.Object
  extended by org.coweb.oe.Operation
Direct Known Subclasses:
DeleteOperation, InsertOperation, UpdateOperation

public abstract class Operation
extends Object


Field Summary
protected  ContextVector contextVector
           
protected  boolean immutable
           
protected static int infinity
           
protected  String key
           
protected  boolean local
           
protected  int order
           
protected  int position
           
protected  int seqId
           
protected  int siteId
           
protected  String type
           
protected  String value
           
protected  Vector<Operation> xCache
           
 
Constructor Summary
protected Operation(Map<String,Object> args)
          Contains information about a local or remote event for transformation.
 
Method Summary
 void addToCache(int siteCount)
          Caches a transformed copy of this original operation for faster future transformations.
 int compareByContext(Operation op)
          Computes an ordered comparison of this op and another based on their context vectors.
 int compareByOrder(Operation op)
          Computes an ordered comparison of this op and another based on their position in the total op order.
 Operation copy()
          Makes a copy of this operation object.
static String createHistoryKey(int site, int seq)
           
static Operation createOperationFromState(Object[] state)
           
static Operation createOperationFromType(String type, Map<String,Object> args)
           
 ContextVector getContextVector()
           
 Operation getFromCache(ContextVector cv)
          Gets a version of the given operation previously transformed into the given context if available.
 int getPosition()
           
 int getSeqId()
           
 int getSiteId()
           
 Object[] getState()
          Serializes the operation as an array of values for transmission.
 String getValue()
           
 void setImmutable(boolean immutable)
           
 void setState(Object[] arr)
          Unserializes operation data and sets it as the instance data.
 String toString()
           
 Operation transformWith(Operation op)
          Transforms this operation to include the effects of the operation provided as a parameter IT(this, op).
abstract  Operation transformWithDelete(Operation op)
           
abstract  Operation transformWithInsert(Operation op)
           
abstract  Operation transformWithUpdate(Operation op)
           
 void upgradeContextTo(Operation op)
          Upgrades the context of this operation to reflect the inclusion of a single other operation from some site.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

infinity

protected static final int infinity
See Also:
Constant Field Values

siteId

protected int siteId

seqId

protected int seqId

type

protected String type

local

protected boolean local

contextVector

protected ContextVector contextVector

key

protected String key

value

protected String value

position

protected int position

order

protected int order

immutable

protected boolean immutable

xCache

protected Vector<Operation> xCache
Constructor Detail

Operation

protected Operation(Map<String,Object> args)
             throws OperationEngineException
Contains information about a local or remote event for transformation. Initializes the operation from serialized state or individual props if state is not defined in the args parameter.

Parameters:
{Object[]} - args.state Array in format returned by getState bundling the following individual parameter values
{Number} - args.siteId Integer site ID where the op originated
{ContextVector} - args.contextVector Context in which the op occurred
{String} - args.key Name of the property the op affected
{String} - args.value Value of the op
{Number} - args.position Integer position of the op in a linear collection
{Number} - args.order Integer sequence number of the op in the total op order across all sites
{Number} - args.seqId Integer sequence number of the op at its originating site. If undefined, computed from the context vector and site ID.
{Boolean} - args.immutable True if the op cannot be changed, most likely because it is in a history buffer somewhere to this instance
Throws:
OperationEngineException
Method Detail

createOperationFromType

public static Operation createOperationFromType(String type,
                                                Map<String,Object> args)
                                         throws OperationEngineException
Throws:
OperationEngineException

createOperationFromState

public static Operation createOperationFromState(Object[] state)
                                          throws OperationEngineException
Throws:
OperationEngineException

createHistoryKey

public static String createHistoryKey(int site,
                                      int seq)

toString

public String toString()
Overrides:
toString in class Object

transformWithDelete

public abstract Operation transformWithDelete(Operation op)

transformWithInsert

public abstract Operation transformWithInsert(Operation op)

transformWithUpdate

public abstract Operation transformWithUpdate(Operation op)

getState

public Object[] getState()
Serializes the operation as an array of values for transmission.

Returns:
{Object[]} Array with the name of the operation type and all of its instance variables as primitive JS types

setState

public void setState(Object[] arr)
              throws OperationEngineException
Unserializes operation data and sets it as the instance data. Throws an exception if the state is not from an operation of the same type.

Parameters:
{Object[]} - arr Array in the format returned by getState
Throws:
OperationEngineException

copy

public Operation copy()
               throws OperationEngineException
Makes a copy of this operation object. Takes a shortcut and returns a ref to this instance if the op is marked as mutable.

Throws:
OperationEngineException

getFromCache

public Operation getFromCache(ContextVector cv)
                       throws OperationEngineException
Gets a version of the given operation previously transformed into the given context if available.

Parameters:
{ContextVector} - cv Context of the transformed op to seek
Throws:
OperationEngineException

addToCache

public void addToCache(int siteCount)
                throws OperationEngineException
Caches a transformed copy of this original operation for faster future transformations.

Parameters:
{Number} - Integer count of active sites, including the local one
Throws:
OperationEngineException

compareByContext

public int compareByContext(Operation op)
Computes an ordered comparison of this op and another based on their context vectors. Used for sorting operations by their contexts.

Parameters:
{Operation} - op Other operation

compareByOrder

public int compareByOrder(Operation op)
Computes an ordered comparison of this op and another based on their position in the total op order.

Parameters:
{Operation} - op Other operation

transformWith

public Operation transformWith(Operation op)
                        throws OperationEngineException
Transforms this operation to include the effects of the operation provided as a parameter IT(this, op). Upgrade the context of this op to reflect the inclusion of the other.

Throws:
OperationEngineException
{Error} - If this op to be transformed is immutable or if the this operation subclass does not implement the transform method needed to handle the passed op

upgradeContextTo

public void upgradeContextTo(Operation op)
                      throws OperationEngineException
Upgrades the context of this operation to reflect the inclusion of a single other operation from some site.

Parameters:
{Operation} - The operation to include in the context of this op
Throws:
OperationEngineException
{Error} - If this op to be upgraded is immutable

getSiteId

public int getSiteId()

getSeqId

public int getSeqId()

getValue

public String getValue()

getPosition

public int getPosition()

getContextVector

public ContextVector getContextVector()

setImmutable

public void setImmutable(boolean immutable)


Copyright © 2011-2012 The Dojo Foundation. All Rights Reserved.