Class OtService

java.lang.Object
com.arms.api.wiki.service.OtService

@Service public class OtService extends Object
  • Constructor Details

    • OtService

      @Autowired public OtService(org.springframework.data.redis.core.RedisTemplate<String,Object> redisTemplate, org.springframework.data.redis.core.script.RedisScript<Boolean> updateContentAndHistoryScript, com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • getDocumentContent

      public String getDocumentContent(String sessionId, String documentId)
      Gets the current content for a specific document from Redis.
      Parameters:
      sessionId - The identifier of the session.
      documentId - The identifier of the document.
      Returns:
      The content of the document, or empty string if not found.
    • getRevision

      public int getRevision(String sessionId, String documentId)
      Gets the current server revision number (size of history list) from Redis.
      Parameters:
      sessionId - The identifier of the session.
      documentId - The identifier of the document.
      Returns:
      The revision number for the document (0 if history list doesn't exist).
    • receiveOperation

      public TextOperation receiveOperation(String sessionId, String documentId, int clientRevision, TextOperation operation) throws IllegalArgumentException
      Process an incoming operation from a client against a specified revision for a specific document using Redis state. Transforms the operation against concurrent operations, applies it, updates Redis, and adds it to the history list in Redis. NOTE: Updates to content and history are NOT atomic across Redis keys without using MULTI/EXEC or Lua scripts. The instance-level lock prevents races within this single instance, but not across multiple instances.
      Parameters:
      sessionId - The identifier of the session.
      documentId - The identifier of the document being modified.
      clientRevision - The revision number the client based their operation on.
      operation - The operation from the client.
      Returns:
      The transformed operation that was applied.
      Throws:
      IllegalArgumentException - if the clientRevision is invalid or transformation/application fails.
    • setDocumentContent

      public void setDocumentContent(String sessionId, String documentId, String content)
      Sets the document content directly in Redis and clears its history list.
      Parameters:
      sessionId - The identifier of the session.
      documentId - The identifier of the document.
      content - The new document content.
    • resetSessionDocument

      public void resetSessionDocument(String sessionId, String documentId)
      Resets the state (content and history) for a specific document in Redis.
      Parameters:
      sessionId - The identifier of the session.
      documentId - The identifier of the document to reset.
    • getOperationHistory

      public List<TextOperation> getOperationHistory(String sessionId, String documentId)
      Gets a copy of the operation history (List) from the Redis list.
      Parameters:
      sessionId - The identifier of the session.
      documentId - The identifier of the document.
      Returns:
      A list of all operations in the document's history, or an empty list if not found or on error.