Interface LocalMessage<I extends Id<O>,​O,​E>

Type Parameters:
I - the Id Type
O - the Object Type
E - the Effect Type
All Superinterfaces:
Environment<I,​O,​E>, Message<I,​O,​E>, PreCondition<I,​O,​E>
All Known Subinterfaces:
AccountModule.AccountMsg, TestModule.LMsg<E>, TransferModule.TransferMsg
All Known Implementing Classes:
AccountModule.Deposit, AccountModule.Open, AccountModule.Withdraw, TestModule.LocalCopyId, TestModule.LocalSendSetMember, TestModule.LocalSetMember, TestModule.ThrowPstException, TransferModule.Book

public interface LocalMessage<I extends Id<O>,​O,​E>
extends Message<I,​O,​E>, Environment<I,​O,​E>

A LocalMessage wraps the Environment in a LocalEnv, and temporarily stores the LocalEnv in a ThreadLocal variable.

In turn, the LocalEnv can be referenced in the scope of a LocalMessage: a LocalMessage IS A Environment!

Example implementation usage:


 public Msg<I, O, E> local() { return
      pre(() -> ...).
      app(() -> ...).
      eff(() -> ...).
      pst(() -> ...);
 }
 

See also example AccountModule for an example.

  • Nested Class Summary

    Nested Classes
    Modifier and Type Interface Description
    static class  LocalMessage.LocalEnvironment<I extends Id<O>,​O,​E>
    LocalEnvironment implementation that sets the ThreadLocal variable at each Stage.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.ThreadLocal<java.lang.Object> localEnv  
  • Method Summary

    Modifier and Type Method Description
    default LocalMessage.LocalEnvironment<I,​O,​E> env()  
    Msg<I,​O,​E> local()
    Returns the Msg that has been build.
    default Msg<I,​O,​E> msg​(Environment<I,​O,​E> e)
    Builds a Msg, given an Environment
    default O obj()
    Returns the current Object O
    default <O2> O2 obj​(Id<? extends O2> id)
    Returns the current Object O2, given its id
    default O old()
    Returns the old Object O
    default <O2> O2 old​(Id<? extends O2> id)
    Returns the old Object O2, given its id
    default Apply<I,​O,​E> pre​(java.util.function.Supplier<java.lang.Boolean> pre)
    Build the next Apply stage, given a lazy pre-condition supplier.
    default I self()
    Returns the Object identifier that's in scope
    default <I2 extends Id<O2>,​ O2,​ R2>
    R2
    send​(I2 id, Message<I2,​O2,​R2> msg)
    Sends a Message to Object O, given an Object identifier
  • Field Details

    • localEnv

      static final java.lang.ThreadLocal<java.lang.Object> localEnv
  • Method Details

    • env

      default LocalMessage.LocalEnvironment<I,​O,​E> env()
    • local

      Msg<I,​O,​E> local()
      Returns the Msg that has been build.
      Returns:
      the Msg that has been build
    • msg

      default Msg<I,​O,​E> msg​(Environment<I,​O,​E> e)
      Description copied from interface: Message
      Builds a Msg, given an Environment
      Specified by:
      msg in interface Message<I extends Id<O>,​O,​E>
      Parameters:
      e - the environment
      Returns:
      the Msg
    • self

      default I self()
      Description copied from interface: Environment
      Returns the Object identifier that's in scope
      Specified by:
      self in interface Environment<I extends Id<O>,​O,​E>
      Returns:
      the Object identifier
    • obj

      default O obj()
      Description copied from interface: Environment
      Returns the current Object O
      Specified by:
      obj in interface Environment<I extends Id<O>,​O,​E>
      Returns:
      the Object O
    • old

      default O old()
      Description copied from interface: Environment
      Returns the old Object O
      Specified by:
      old in interface Environment<I extends Id<O>,​O,​E>
      Returns:
      the Object O
    • obj

      default <O2> O2 obj​(Id<? extends O2> id)
      Description copied from interface: Environment
      Returns the current Object O2, given its id
      Specified by:
      obj in interface Environment<I extends Id<O>,​O,​E>
      Type Parameters:
      O2 - the Object type
      Parameters:
      id - the Object identifier
      Returns:
      the current Object O2
    • old

      default <O2> O2 old​(Id<? extends O2> id)
      Description copied from interface: Environment
      Returns the old Object O2, given its id
      Specified by:
      old in interface Environment<I extends Id<O>,​O,​E>
      Type Parameters:
      O2 - the Object type
      Parameters:
      id - the Object identifier
      Returns:
      the current Object O2
    • pre

      default Apply<I,​O,​E> pre​(java.util.function.Supplier<java.lang.Boolean> pre)
      Description copied from interface: PreCondition
      Build the next Apply stage, given a lazy pre-condition supplier.
      Specified by:
      pre in interface PreCondition<I extends Id<O>,​O,​E>
      Parameters:
      pre - the supplier of the pre-condition
      Returns:
      the Apply stage
    • send

      default <I2 extends Id<O2>,​ O2,​ R2> R2 send​(I2 id, Message<I2,​O2,​R2> msg)
      Description copied from interface: Environment
      Sends a Message to Object O, given an Object identifier
      Specified by:
      send in interface Environment<I extends Id<O>,​O,​E>
      Type Parameters:
      I2 - the Id Type
      O2 - the Object Type
      R2 - the Reference Type
      Parameters:
      id - the Object identifier to send the Message to
      msg - the message to send to the Object
      Returns:
      the effect R of the Message send