OT.Server v0.3.1 OT.Server.Adapter behaviour View Source

An adapter behaviour for interacting with peristed data in an operational transformation system.

Link to this section Summary

Callbacks

Get any conflicting operations for the given datum at the given version

Get the datum identified by the ID

Handle a submission error

Insert the given OT.Server.operation/0 into persistence

Roll a transaction back

Call a function inside of a transaction

Update the OT.Server.datum/0 with the given content and increment its OT.Server.version/0

Link to this section Callbacks

Link to this callback get_conflicting_operations(datum, arg1) View Source
get_conflicting_operations(datum :: OT.Server.datum, OT.Server.version) :: [OT.Server.operation_info]

Get any conflicting operations for the given datum at the given version.

In a proper OT system, this means any operation for the given datum whose version is greater than or equal to the given version.

The function must return a list of OT.Server.operation_info/0s.

Link to this callback get_datum(id) View Source
get_datum(id :: OT.Server.datum_id) ::
  {:ok, OT.Server.datum} |
  {:error, any}

Get the datum identified by the ID.

Link to this callback handle_submit_error(any, any, arg2) View Source
handle_submit_error(any, any, OT.Server.operation_info) ::
  :retry |
  {:error, any}

Handle a submission error.

If the error passed to this function constitutes a scenario in which the submission should be tried again, return :retry. Otherwise, return a tagged error tuple and the call to OT.Server.submit_operation/3 will fail.

Link to this callback insert_operation(datum, arg1, any) View Source
insert_operation(datum :: OT.Server.datum, OT.Server.operation_info, any) ::
  {:ok, any} |
  {:error, any}

Insert the given OT.Server.operation/0 into persistence.

Any metadata that was originally passed to OT.Server.submit_operation/3 will also be passed to the adapter.

On a successful submission, this value is what will be returned from OT.Server.submit_operation/3.

Link to this callback rollback(any) View Source
rollback(any) :: no_return

Roll a transaction back.

This will be called when the attempt to submit an operation fails—for adapters without real transaction support, they must choose how to repair their data at this stage, since update_datum/2 may have been called, but insert_operation/3 may have failed.

Link to this callback transact(id, function) View Source
transact(id :: OT.Server.datum_id, (() -> any)) ::
  {:ok, any} |
  {:error, any}

Call a function inside of a transaction.

This is useful for adapters that use databases that support transactions. All of the other adapter functions (other than handle_submit_error/3) will be call called in the function passed to this function.

This is a good place to implement locking to ensure that only a single operation is processed at a time per document, a requirement of this OT system.

Link to this callback update_datum(datum, any) View Source
update_datum(datum :: OT.Server.datum, any) ::
  {:ok, OT.Server.datum} |
  {:error, any}

Update the OT.Server.datum/0 with the given content and increment its OT.Server.version/0.