org.coweb.oe
Class OperationEngine

java.lang.Object
  extended by org.coweb.oe.OperationEngine

public class OperationEngine
extends Object


Constructor Summary
OperationEngine(int siteId)
          Controls the operational transformation algorithm.
 
Method Summary
 ContextVector copyContextVector()
          Makes a copy of the engine context vector representing the local document state.
 Operation createOp(boolean local, String key, String value, String type, int position, int site, int[] cv, int order)
          Factory method that creates an operation object initialized with the given values.
 void freezeSite(int site)
          Freezes a slot in the context vector table by inserting a reference to context vector of this engine.
 int getBufferSize()
          Gets the size of the history buffer in terms of stored operations.
 int getSiteCount()
          Gets the number of sites known to be participating, including this site.
 int getSiteId()
           
 Object[] getState()
          Gets the state of this engine instance to seed a new instance.
 boolean hasProcessedOp(Operation op)
          Gets if the engine has already processed the give operation based on its context vector and the context vector of this engine instance.
 ContextVector purge()
          Runs the garbage collection algorithm over the history buffer.
 Operation push(boolean local, String key, String value, String type, int position, int site, int[] cv, int order)
          Creates an operation object and pushes it into the operation engine algorithm.
 Operation pushLocalOp(Operation op)
          Procceses a local operation and adds it to the history buffer.
 Operation pushRemoteOp(Operation op)
          Procceses a remote operation, transforming it if required, and adds the original to the history buffer.
 void pushSync(int site, ContextVector cv)
          Processes an engine synchronization event.
 void pushSyncWithSites(int site, int[] sites)
          Processes an engine synchronization event.
 void setState(Object[] arr)
          Sets the state of this engine instance to state received from another instance.
 void thawSite(int site)
          Thaws a slot in the context vector table by inserting a zeroed context vector into the context vector table.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OperationEngine

public OperationEngine(int siteId)
                throws OperationEngineException
Controls the operational transformation algorithm. Provides a public API for operation processing, garbage collection, and engine synchronization.

Parameters:
{Number} - siteId Unique integer site ID for this engine instance
Throws:
OperationEngineException
Method Detail

toString

public String toString()
Overrides:
toString in class Object

getState

public Object[] getState()
Gets the state of this engine instance to seed a new instance.

Returns:
{Object[]} Array or serialized state

setState

public void setState(Object[] arr)
              throws OperationEngineException
Sets the state of this engine instance to state received from another instance.

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

copyContextVector

public ContextVector copyContextVector()
                                throws OperationEngineException
Makes a copy of the engine context vector representing the local document state.

Throws:
OperationEngineException

createOp

public Operation createOp(boolean local,
                          String key,
                          String value,
                          String type,
                          int position,
                          int site,
                          int[] cv,
                          int order)
                   throws OperationEngineException
Factory method that creates an operation object initialized with the given values.

Parameters:
{Boolean} - local True if the operation was originated locally, false if not
{String} - key Operation key
{String} - value Operation value
{String} - type Type of operation: update, insert, delete
{Number} - position Operation integer position
{Number} - site Integer site ID where a remote op originated. Ignored for local operations which adopt the local site ID.
{ContextVector} - cv Operation context. Ignored for local operations which adopt the local site context.
{Number} - order Place of the operation in the total order. Ignored for local operations which are not yet assigned a place in the order.
Throws:
OperationEngineException

push

public Operation push(boolean local,
                      String key,
                      String value,
                      String type,
                      int position,
                      int site,
                      int[] cv,
                      int order)
               throws OperationEngineException
Creates an operation object and pushes it into the operation engine algorithm. The parameters and return value are the same as those documented for createOp.

Throws:
OperationEngineException

pushLocalOp

public Operation pushLocalOp(Operation op)
Procceses a local operation and adds it to the history buffer.

Parameters:
{Operation} - Local operation

pushRemoteOp

public Operation pushRemoteOp(Operation op)
                       throws OperationEngineException
Procceses a remote operation, transforming it if required, and adds the original to the history buffer.

Parameters:
{Operation} - Remote operation
Throws:
OperationEngineException

pushSync

public void pushSync(int site,
                     ContextVector cv)
              throws OperationEngineException
Processes an engine synchronization event.

Parameters:
{Number} - site Integer site ID of where the sync originated
{ContextVector} - cv Context vector sent by the engine at that site
Throws:
OperationEngineException

pushSyncWithSites

public void pushSyncWithSites(int site,
                              int[] sites)
                       throws OperationEngineException
Processes an engine synchronization event.

Parameters:
{Number} - site Integer site ID of where the sync originated
{Number[]} - Array form of the context vector sent by the site
Throws:
OperationEngineException

purge

public ContextVector purge()
                    throws OperationEngineException
Runs the garbage collection algorithm over the history buffer.

Throws:
OperationEngineException

getBufferSize

public int getBufferSize()
Gets the size of the history buffer in terms of stored operations.


hasProcessedOp

public boolean hasProcessedOp(Operation op)
Gets if the engine has already processed the give operation based on its context vector and the context vector of this engine instance.

Parameters:
{Operation} - op Operation to check

freezeSite

public void freezeSite(int site)
                throws OperationEngineException
Freezes a slot in the context vector table by inserting a reference to context vector of this engine. Should be invoked when a remote site stops participating.

Parameters:
{Number} - site Integer ID of the site to freeze
Throws:
OperationEngineException

thawSite

public void thawSite(int site)
              throws OperationEngineException
Thaws a slot in the context vector table by inserting a zeroed context vector into the context vector table. Should be invoked before processing the first operation from a new remote site.

Parameters:
{Number} - site Integer ID of the site to thaw
Throws:
OperationEngineException

getSiteCount

public int getSiteCount()
Gets the number of sites known to be participating, including this site.


getSiteId

public int getSiteId()


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