Class JniYDoc

java.lang.Object
net.carcdr.ycrdt.jni.JniYDoc
All Implemented Interfaces:
AutoCloseable, net.carcdr.ycrdt.YDoc

public class JniYDoc extends Object implements net.carcdr.ycrdt.YDoc
JniYDoc represents a Y-CRDT document, which is a shared data structure that supports concurrent editing and automatic conflict resolution.

This class wraps the native Rust implementation of y-crdt (yrs) and provides a Java API for working with collaborative documents.

Usage example:


 try (YDoc doc = new JniYDoc()) {
     long clientId = doc.getClientId();
     String guid = doc.getGuid();

     // Get document state as update
     byte[] state = doc.encodeStateAsUpdate();

     // Apply update to another document
     try (YDoc doc2 = new JniYDoc()) {
         doc2.applyUpdate(state);
     }
 }
 

Thread Safety: JniYDoc instances are not thread-safe. If you need to access a document from multiple threads, you must provide external synchronization.

Memory Management: JniYDoc implements Closeable and must be closed when no longer needed to free native resources. Use try-with-resources to ensure proper cleanup.