java.lang.Object
de.haumacher.msgbuf.graph.DefaultScope
- All Implemented Interfaces:
Scope,ScopeMixin,Listener
The default
Scope of an AbstractSharedGraphNode.
After adding this instance as listener to a node, the node is
observed for changes. Changes can be externalized to a patch and transmitted over
network to another DefaultScope containing a corresponding instance of the node. There, the patch an be
applied bringing both shared object graphs in sync.
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.haumacher.msgbuf.observer.Listener
Listener.MultiplexListener -
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultScope(int totalParticipants, int participantId) Creates aDefaultScope. -
Method Summary
Modifier and TypeMethodDescriptionvoidafterRemove(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.voidRemoves all recorded changes.voidenter(SharedGraphNode node, int id) Assigns the given ID to the given node.booleanChecks whether there are changes to create a patch.intid(SharedGraphNode node) Looks up the ID of the given node in thisScope.index()The index implementation associating object with IDs.voidinitId(SharedGraphNode node, int id) Assigns the given ID to the given node.static DefaultScopeCreates aDefaultScopefor the client , where the graph is only shared between two participants, theclientand theserver.intnewId()Creates a fresh ID.static DefaultScopeCreates 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, waitMethods inherited from interface de.haumacher.msgbuf.observer.Listener
afterRemove, beforeAddMethods inherited from interface de.haumacher.msgbuf.graph.ScopeMixin
resolveOrFail, writeRefOrData
-
Constructor Details
-
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 Details
-
newServerInstance
Creates aDefaultScopefor the server, where the graph is only shared between two participants, theclientand the server. -
newClientInstance
Creates aDefaultScopefor the client , where the graph is only shared between two participants, theclientand theserver. -
beforeSet
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
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
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.
-
hasChanges
public boolean hasChanges()Checks whether there are changes to create a patch. -
dropChanges
public void dropChanges()Removes all recorded changes. -
createPatch
Exports recorded changes to the givenJsonWriter.The recored changes are reset when this method completes.
The patch is a list containing an entry for each command. Each entry is a list with the command configuration at position 0 followed by optional additional arguments for the command.
- Throws:
IOException- See Also:
-
applyChanges
Applies changes read from the givenJsonReader.It is expected that the patch has the format as in
createPatch(JsonWriter).- Throws:
IOException- See Also:
-
newId
public int newId()Description copied from interface:ScopeMixinCreates a fresh ID.- Specified by:
newIdin interfaceScopeMixin
-
index
Description copied from interface:ScopeMixinThe index implementation associating object with IDs.- Specified by:
indexin interfaceScopeMixin
-