Package net.carcdr.ycrdt
Interface YDoc
- All Superinterfaces:
AutoCloseable
A collaborative document containing shared types.
YDoc is the root container for all Y-CRDT data structures.
-
Method Summary
Modifier and TypeMethodDescriptionvoidapplyUpdate(byte[] update) Applies an update to this document.voidapplyUpdate(YTransaction txn, byte[] update) Applies an update to this document within a transaction.Begins a new transaction for batching operations.voidclose()Closes this document and releases all resources.byte[]encodeDiff(byte[] stateVector) Encodes the difference between this document and the given state vector.byte[]encodeDiff(YTransaction txn, byte[] stateVector) Encodes the difference between this document and the given state vector within a transaction.byte[]Encodes the entire document state as an update.byte[]Encodes the entire document state as an update within a transaction.byte[]Encodes the state vector of this document.byte[]Encodes the state vector of this document within a transaction.Gets or creates a collaborative array with the given name.longReturns the client ID for this document.getGuid()Returns the globally unique identifier for this document.Gets or creates a collaborative map with the given name.Gets the current error handler for observer exceptions.Gets or creates a collaborative text with the given name.getXmlElement(String name) Gets or creates a collaborative XML element with the given name.getXmlFragment(String name) Gets or creates a collaborative XML fragment with the given name.getXmlText(String name) Gets or creates a collaborative XML text with the given name.booleanisClosed()Checks if this document has been closed.observeUpdateV1(UpdateObserver observer) Registers an observer for document updates.voidSets the error handler for observer exceptions.voidExecutes a function within a transaction.
-
Method Details
-
getClientId
long getClientId()Returns the client ID for this document.- Returns:
- the client ID
-
getGuid
-
encodeStateAsUpdate
byte[] encodeStateAsUpdate()Encodes the entire document state as an update.- Returns:
- the encoded update
-
encodeStateAsUpdate
Encodes the entire document state as an update within a transaction.- Parameters:
txn- the transaction- Returns:
- the encoded update
-
applyUpdate
void applyUpdate(byte[] update) Applies an update to this document.- Parameters:
update- the update to apply
-
applyUpdate
Applies an update to this document within a transaction.- Parameters:
txn- the transactionupdate- the update to apply
-
encodeStateVector
byte[] encodeStateVector()Encodes the state vector of this document.- Returns:
- the encoded state vector
-
encodeStateVector
Encodes the state vector of this document within a transaction.- Parameters:
txn- the transaction- Returns:
- the encoded state vector
-
encodeDiff
byte[] encodeDiff(byte[] stateVector) Encodes the difference between this document and the given state vector.- Parameters:
stateVector- the remote state vector- Returns:
- the encoded diff
-
encodeDiff
Encodes the difference between this document and the given state vector within a transaction.- Parameters:
txn- the transactionstateVector- the remote state vector- Returns:
- the encoded diff
-
getText
-
getArray
-
getMap
-
getXmlText
-
getXmlElement
Gets or creates a collaborative XML element with the given name.- Parameters:
name- the name of the XML element- Returns:
- the XML element instance
-
getXmlFragment
Gets or creates a collaborative XML fragment with the given name.- Parameters:
name- the name of the XML fragment- Returns:
- the XML fragment instance
-
beginTransaction
YTransaction beginTransaction()Begins a new transaction for batching operations.- Returns:
- the transaction
-
transaction
Executes a function within a transaction.- Parameters:
fn- the function to execute
-
observeUpdateV1
Registers an observer for document updates.- Parameters:
observer- the observer to register- Returns:
- a subscription handle for unregistering
-
setObserverErrorHandler
Sets the error handler for observer exceptions.When an observer throws an exception, this handler will be called instead of letting the exception propagate. The default handler prints to stderr for backwards compatibility.
- Parameters:
handler- the error handler to use, or null to use the default handler- See Also:
-
getObserverErrorHandler
ObserverErrorHandler getObserverErrorHandler()Gets the current error handler for observer exceptions.- Returns:
- the current error handler (never null)
-
close
void close()Closes this document and releases all resources.- Specified by:
closein interfaceAutoCloseable
-
isClosed
boolean isClosed()Checks if this document has been closed.- Returns:
- true if closed, false otherwise
-