public class JsonMergePatchClientSynchronizer extends Object implements ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
ServerSynchronizer
implementation that can handle text documents.Constructor and Description |
---|
JsonMergePatchClientSynchronizer() |
Modifier and Type | Method and Description |
---|---|
void |
addContent(com.fasterxml.jackson.databind.JsonNode content,
com.fasterxml.jackson.databind.node.ObjectNode objectNode,
String fieldName)
Adds the content of the passed in
content to the ObjectNode . |
static String |
checksum(com.fasterxml.jackson.databind.JsonNode content) |
JsonMergePatchEdit |
clientDiff(ShadowDocument<com.fasterxml.jackson.databind.JsonNode> shadowDocument,
ClientDocument<com.fasterxml.jackson.databind.JsonNode> document)
|
PatchMessage<JsonMergePatchEdit> |
createPatchMessage(String documentId,
String clientId,
Queue<JsonMergePatchEdit> edits)
Creates a new
PatchMessage with the with the type of Edit that this
synchronizer can handle. |
ClientDocument<com.fasterxml.jackson.databind.JsonNode> |
patchDocument(JsonMergePatchEdit edit,
ClientDocument<com.fasterxml.jackson.databind.JsonNode> document)
Called when the document should be patched.
|
PatchMessage<JsonMergePatchEdit> |
patchMessageFromJson(String json)
Creates a {link PatchMessage} by parsing the passed-in json.
|
ShadowDocument<com.fasterxml.jackson.databind.JsonNode> |
patchShadow(JsonMergePatchEdit edit,
ShadowDocument<com.fasterxml.jackson.databind.JsonNode> shadowDocument)
Called when the shadow should be patched.
|
JsonMergePatchEdit |
serverDiff(ClientDocument<com.fasterxml.jackson.databind.JsonNode> document,
ShadowDocument<com.fasterxml.jackson.databind.JsonNode> shadowDocument)
|
public JsonMergePatchEdit clientDiff(ShadowDocument<com.fasterxml.jackson.databind.JsonNode> shadowDocument, ClientDocument<com.fasterxml.jackson.databind.JsonNode> document)
ClientSynchronizer
Edit
containing the changes between updated ShadowDocument
and the ClientDocument
.
This method would be called when the client receives an update from the server and need
to produce an Edit
to be able to patch the ClientDocument
.clientDiff
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
shadowDocument
- the ShadowDocument
patched with updates from the serverdocument
- the ClientDocument
Edit
the edit representing the diff between the shadow document and the client document.public JsonMergePatchEdit serverDiff(ClientDocument<com.fasterxml.jackson.databind.JsonNode> document, ShadowDocument<com.fasterxml.jackson.databind.JsonNode> shadowDocument)
ClientSynchronizer
Edit
containing the changes between the updated ClientDocument
and the ShadowDocument
.
Calling the method is the first step in when starting a client side synchronization. We need to
gather the changes between the updates made by the client and the shadow document.
The produced Edit
can then be passed to the server side.
serverDiff
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
document
- the ClientDocument
containing updates made by the clientshadowDocument
- the ShadowDocument
for the ClientDocument
Edit
the edit representing the diff between the client document and it's shadow document.public ShadowDocument<com.fasterxml.jackson.databind.JsonNode> patchShadow(JsonMergePatchEdit edit, ShadowDocument<com.fasterxml.jackson.databind.JsonNode> shadowDocument)
ClientSynchronizer
patchShadow
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
edit
- the Edit
containing the diffs/patchesshadowDocument
- the ShadowDocument
to be patchedShadowDocument
a new patched shadow documentpublic ClientDocument<com.fasterxml.jackson.databind.JsonNode> patchDocument(JsonMergePatchEdit edit, ClientDocument<com.fasterxml.jackson.databind.JsonNode> document)
ClientSynchronizer
patchDocument
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
edit
- the Edit
containing the diffs/patchesdocument
- the ClientDocument
to be patchedClientDocument
a new patched document.public PatchMessage<JsonMergePatchEdit> createPatchMessage(String documentId, String clientId, Queue<JsonMergePatchEdit> edits)
ClientSynchronizer
PatchMessage
with the with the type of Edit
that this
synchronizer can handle.createPatchMessage
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
documentId
- the document identifier for the PatchMessage
clientId
- the client identifier for the PatchMessage
edits
- the Edit
s for the PatchMessage
PatchMessage
the created {code PatchMessage}public PatchMessage<JsonMergePatchEdit> patchMessageFromJson(String json)
ClientSynchronizer
patchMessageFromJson
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
json
- the json representation of a PatchMessage
PatchMessage
the created {code PatchMessage}public void addContent(com.fasterxml.jackson.databind.JsonNode content, com.fasterxml.jackson.databind.node.ObjectNode objectNode, String fieldName)
ClientSynchronizer
content
to the ObjectNode
.
When a client initially adds a document to the engine it will also be sent across the
wire to the server. Before sending, the content of the document has to be added to the
JSON message payload. Different implementation will require different content types that
the engine can handle and this give them control over how the content is added to the JSON
ObjectNode
.
For example, a ClientEngine that stores simple text will just add the contents as a String,
but one that stores JsonNode object will want to add its content as an object.
addContent
in interface ClientSynchronizer<com.fasterxml.jackson.databind.JsonNode,JsonMergePatchEdit>
content
- the content to be addedobjectNode
- the ObjectNode
to add the content tofieldName
- the name of the fieldpublic static String checksum(com.fasterxml.jackson.databind.JsonNode content)
Copyright © 2015 JBoss by Red Hat. All Rights Reserved.