- java.lang.Object
-
- de.haumacher.msgbuf.graph.DefaultScope
-
- All Implemented Interfaces:
Scope,ScopeMixin,Listener
public class DefaultScope extends Object implements Listener, ScopeMixin
The defaultScopeof anAbstractSharedGraphNode.After adding this instance as
listenerto a node, the node is observed for changes. Changes can be externalized to apatchand transmitted over network to anotherDefaultScopecontaining a corresponding instance of the node. There, the patch an beappliedbringing both shared object graphs in sync.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface de.haumacher.msgbuf.observer.Listener
Listener.MultiplexListener
-
-
Constructor Summary
Constructors Constructor Description DefaultScope(int totalParticipants, int participantId)Creates aDefaultScope.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterRemove(Observable obj, String property, int index, Object element)Informs thisListenerthat an element was removed from a repeated property with the given name.voidapplyChanges(JsonReader json)Applies changes read from the givenJsonReader.voidbeforeAdd(Observable obj, String property, int index, Object element)Informs thisListenerthat an element will be added to the repeated property with the given name.voidbeforeSet(Observable obj, String property, Object value)Informs thisListenerthat the value of the given property is to be modified.voidcreatePatch(JsonWriter json)Exports recorded changes to the givenJsonWriter.voidenter(SharedGraphNode node, int id)Assigns the given ID to the given node.intid(SharedGraphNode node)Looks up the ID of the given node in thisScope.Map<Object,SharedGraphNode>index()The index implementation associating object with IDs.voidinitId(SharedGraphNode node, int id)Assigns the given ID to the given node.static DefaultScopenewClientInstance()Creates aDefaultScopefor the client , where the graph is only shared between two participants, theclientand theserver.intnewId()Creates a fresh ID.static DefaultScopenewServerInstance()Creates aDefaultScopefor the server, where the graph is only shared between two participants, theclientand the server.voidreadData(SharedGraphNode node, int id, JsonReader in)Reads object data of the given node and assigns the given ID to this node.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface de.haumacher.msgbuf.observer.Listener
afterRemove, beforeAdd
-
Methods inherited from interface de.haumacher.msgbuf.graph.ScopeMixin
resolveOrFail, writeRefOrData
-
-
-
-
Constructor Detail
-
DefaultScope
public DefaultScope(int totalParticipants, int participantId)Creates aDefaultScope.- Parameters:
totalParticipants- The total number of participants operating on the shared graph.participantId- The ID of this participant.
-
-
Method Detail
-
newServerInstance
public static DefaultScope newServerInstance()
Creates aDefaultScopefor the server, where the graph is only shared between two participants, theclientand the server.
-
newClientInstance
public static DefaultScope newClientInstance()
Creates aDefaultScopefor the client , where the graph is only shared between two participants, theclientand theserver.
-
beforeSet
public void beforeSet(Observable obj, String property, Object value)
Description copied from interface:ListenerInforms thisListenerthat the value of the given property is to be modified.- Specified by:
beforeSetin interfaceListener- Parameters:
obj- TheObservableobject.property- The name of the property to be modified.value- The new value that is being set to the given property.
-
beforeAdd
public void beforeAdd(Observable obj, String property, int index, Object element)
Description copied from interface:ListenerInforms thisListenerthat an element will be added to the repeated property with the given name.- Specified by:
beforeAddin interfaceListener- Parameters:
obj- TheObservableobject.property- The name of the property to be modified.index- The index where the new element will be added if the property is ordered,-1otherwise.element- The new element that is being added to the given property.
-
afterRemove
public void afterRemove(Observable obj, String property, int index, Object element)
Description copied from interface:ListenerInforms thisListenerthat an element was removed from a repeated property with the given name.- Specified by:
afterRemovein interfaceListener- Parameters:
obj- TheObservableobject.property- The name of the property to be modified.index- The index where the element was removed if the property is ordered,-1otherwise.element- The element that was removed from the given property.
-
createPatch
public void createPatch(JsonWriter json) throws IOException
Exports recorded changes to the givenJsonWriter.The recored changes are reset when this method completes.
- Throws:
IOException
-
applyChanges
public void applyChanges(JsonReader json) throws IOException
Applies changes read from the givenJsonReader.- Throws:
IOException
-
enter
public void enter(SharedGraphNode node, int id)
Description copied from interface:ScopeMixinAssigns the given ID to the given node.- Specified by:
enterin interfaceScopeMixin
-
readData
public void readData(SharedGraphNode node, int id, JsonReader in) throws IOException
Description copied from interface:ScopeReads object data of the given node and assigns the given ID to this node.- Specified by:
readDatain interfaceScope- Specified by:
readDatain interfaceScopeMixin- Parameters:
node- The node to read data for.id- The ID to assign ot the given node.- Throws:
IOException
-
id
public int id(SharedGraphNode node)
Description copied from interface:ScopeMixinLooks up the ID of the given node in thisScope.- Specified by:
idin interfaceScopeMixin- See Also:
ScopeMixin.initId(SharedGraphNode, int)
-
initId
public void initId(SharedGraphNode node, int id)
Description copied from interface:ScopeMixinAssigns the given ID to the given node.- Specified by:
initIdin interfaceScopeMixin- See Also:
ScopeMixin.id(SharedGraphNode)
-
newId
public int newId()
Description copied from interface:ScopeMixinCreates a fresh ID.- Specified by:
newIdin interfaceScopeMixin
-
index
public Map<Object,SharedGraphNode> index()
Description copied from interface:ScopeMixinThe index implementation associating object with IDs.- Specified by:
indexin interfaceScopeMixin
-
-