public abstract class

Prop

extends JunctionExtra
implements IProp
java.lang.Object
   ↳ edu.stanford.junction.api.activity.JunctionExtra
     ↳ edu.stanford.junction.props2.Prop
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Note: The use of 'synchronized' is very deliberate. If you want to access the state of the prop, you must use the withState callback, which serializes your state read with respect to state changes resulting from addOperation or handleMessage.

Summary

Constants
boolean COMPRESS_STATE_SYNC
String EVT_ANY
String EVT_CHANGE
String EVT_SYNC
int MODE_NORM
int MODE_SYNC
int MSG_HELLO
int MSG_I_HAVE_STATE
int MSG_SEND_ME_STATE
int MSG_STATE_OPERATION
int MSG_STATE_SYNC
int MSG_WHO_HAS_STATE
Fields
protected boolean active
protected long bestSyncSeqNum
protected Vector<IPropChangeListener> changeListeners
protected IPropState cleanState
protected boolean enableChangeEvents
protected String lastOpUUID
protected int mode
protected Vector<JSONObject> opsSYNC
protected Vector<JSONObject> pendingLocals
protected String propName
protected String propReplicaName
protected PropStats propStats
protected long sequenceNum
protected long staleness
protected IPropState state
protected String syncId
protected Timer taskTimer
protected long timeOfLastHello
protected long timeOfLastSyncRequest
protected String uuid
Public Constructors
Prop(String propName, String propReplicaName, IPropState state, long seqNum)
Prop(String propName, String propReplicaName, IPropState state)
Prop(String propName, IPropState state, long seqNum)
Prop(String propName, IPropState state)
Public Methods
synchronized void addChangeListener(IPropChangeListener listener)
synchronized void addOperation(JSONObject operation)
Add an operation to the state managed by this Prop, with prediction
void afterActivityJoin()
boolean beforeOnMessageReceived(MessageHeader h, JSONObject m)
Returns true if the normal event handling should proceed; Return false to stop cascading.
PropStats getAndDisableStats()
String getPropName()
The name of the prop at large.
String getPropReplicaName()
long getSequenceNum()
The internal counter that tracks how many operations have been executed on this prop's state.
long getStaleness()
abstract IProp newFresh()
IProp newKeepingListeners()
synchronized void removeAllChangeListeners()
synchronized void removeChangeListener(IPropChangeListener listener)
synchronized void removeChangeListenersOfType(String type)
void startCollectingStats()
JSONObject stateToJSON()
String stateToString()
synchronized <T> T withState(IWithStateAction<T> action)
Protected Methods
void assertTrue(String s, boolean cond)
synchronized void broadcastSyncRequest()
synchronized void dispatchChangeNotification(String evtType, Object o)
void enterSYNCMode()
void exitSYNCMode()
void handleHello(JSONObject msg)
synchronized void handleMessage(JSONObject msg)
void handleReceivedOp(JSONObject opMsg)
What to do with a newly arrived operation? Depends on mode of operation.
void handleStateSyncMsg(JSONObject msg)
Install state received from peer.
long helloInterval()
boolean isActive()
boolean isSelfMsg(JSONObject msg)
void logErr(String s)
void logInfo(String s)
void logState(String s)
JSONObject newHelloMsg()
JSONObject newIHaveStateMsg(String syncId)
JSONObject newSendMeStateMsg(String syncId)
JSONObject newStateOperationMsg(JSONObject op)
JSONObject newStateSyncMsg(String syncId, boolean compress)
JSONObject newWhoHasStateMsg(String syncId)
abstract IPropState reifyState(JSONObject obj)
void removePendingLocal(JSONObject opMsg)
synchronized void sendHello()
void sendMessageToProp(JSONObject m)
Send a message to all prop-replicas in this prop
void sendMessageToPropReplica(String actorId, JSONObject m)
Send a message to the prop-replica hosted at the given actorId.
long syncRequestInterval()
[Expand]
Inherited Methods
From class edu.stanford.junction.api.activity.JunctionExtra
From class java.lang.Object
From interface edu.stanford.junction.props2.IProp

Constants

protected static final boolean COMPRESS_STATE_SYNC

Constant Value: true

public static final String EVT_ANY

Constant Value: "*"

public static final String EVT_CHANGE

Constant Value: "change"

public static final String EVT_SYNC

Constant Value: "sync"

protected static final int MODE_NORM

Constant Value: 1 (0x00000001)

protected static final int MODE_SYNC

Constant Value: 2 (0x00000002)

public static final int MSG_HELLO

Constant Value: 6 (0x00000006)

public static final int MSG_I_HAVE_STATE

Constant Value: 3 (0x00000003)

public static final int MSG_SEND_ME_STATE

Constant Value: 4 (0x00000004)

public static final int MSG_STATE_OPERATION

Constant Value: 1 (0x00000001)

public static final int MSG_STATE_SYNC

Constant Value: 5 (0x00000005)

public static final int MSG_WHO_HAS_STATE

Constant Value: 2 (0x00000002)

Fields

protected boolean active

protected long bestSyncSeqNum

protected Vector<IPropChangeListener> changeListeners

protected IPropState cleanState

protected boolean enableChangeEvents

protected String lastOpUUID

protected int mode

protected Vector<JSONObject> opsSYNC

protected Vector<JSONObject> pendingLocals

protected String propName

protected String propReplicaName

protected PropStats propStats

protected long sequenceNum

protected long staleness

protected IPropState state

protected String syncId

protected Timer taskTimer

protected long timeOfLastHello

protected long timeOfLastSyncRequest

protected String uuid

Public Constructors

public Prop (String propName, String propReplicaName, IPropState state, long seqNum)

public Prop (String propName, String propReplicaName, IPropState state)

public Prop (String propName, IPropState state, long seqNum)

public Prop (String propName, IPropState state)

Public Methods

public synchronized void addChangeListener (IPropChangeListener listener)

public synchronized void addOperation (JSONObject operation)

Add an operation to the state managed by this Prop, with prediction

public void afterActivityJoin ()

public boolean beforeOnMessageReceived (MessageHeader h, JSONObject m)

Returns true if the normal event handling should proceed; Return false to stop cascading.

public PropStats getAndDisableStats ()

public String getPropName ()

The name of the prop at large. All peers must share this name.

public String getPropReplicaName ()

public long getSequenceNum ()

The internal counter that tracks how many operations have been executed on this prop's state. For a given state, this number should be the same at all peers.

public long getStaleness ()

public abstract IProp newFresh ()

public IProp newKeepingListeners ()

public synchronized void removeAllChangeListeners ()

public synchronized void removeChangeListener (IPropChangeListener listener)

public synchronized void removeChangeListenersOfType (String type)

public void startCollectingStats ()

public JSONObject stateToJSON ()

public String stateToString ()

public synchronized T withState (IWithStateAction<T> action)

Protected Methods

protected void assertTrue (String s, boolean cond)

protected synchronized void broadcastSyncRequest ()

protected synchronized void dispatchChangeNotification (String evtType, Object o)

protected void enterSYNCMode ()

protected void exitSYNCMode ()

protected void handleHello (JSONObject msg)

protected synchronized void handleMessage (JSONObject msg)

protected void handleReceivedOp (JSONObject opMsg)

What to do with a newly arrived operation? Depends on mode of operation. Note, we must take care to make sure there is no sharing between this.cleanState and this.state. This means copying operations that must be applied to both states!

protected void handleStateSyncMsg (JSONObject msg)

Install state received from peer.

protected long helloInterval ()

protected boolean isActive ()

protected boolean isSelfMsg (JSONObject msg)

protected void logErr (String s)

protected void logInfo (String s)

protected void logState (String s)

protected JSONObject newHelloMsg ()

protected JSONObject newIHaveStateMsg (String syncId)

protected JSONObject newSendMeStateMsg (String syncId)

protected JSONObject newStateOperationMsg (JSONObject op)

protected JSONObject newStateSyncMsg (String syncId, boolean compress)

protected JSONObject newWhoHasStateMsg (String syncId)

protected abstract IPropState reifyState (JSONObject obj)

protected void removePendingLocal (JSONObject opMsg)

protected synchronized void sendHello ()

protected void sendMessageToProp (JSONObject m)

Send a message to all prop-replicas in this prop

protected void sendMessageToPropReplica (String actorId, JSONObject m)

Send a message to the prop-replica hosted at the given actorId.

protected long syncRequestInterval ()