Packages

trait ServiceBindings extends ServiceActor

Declarative mapping from a service domain's protocol to implementations. Included in ServiceFragment.

In glngn server, the mapping of service domain protocol to implementations is refered to as the bindings: the binding of a domain term to an implementation. Logically similar to data binding in UI controller libraries. The bindings are determined by evaluating Instance.bindings for each service actor instance.

See Bindings for the EDSL for declaring bindings.

The ServiceBindings trait enforces this by requiring the ServiceActor object to define an Instance class implementing BindingsInstance. The ServiceFragment's Instance already satisfies this requirement.

object BalanceSheet extends ServiceActor with ServiceBindings {
  sealed trait Proto extends Message
  case class PrintAndMailBalance(accountId: Int) extends Proto with Command[Unit]
  case class PostBalanceToMessageBus(accountId: Int) extends Proto with Command[Balance]

  class Instance(val env: InstanceEnv) extends BindingsInstance {
    import Bindings._

    val behavior: Behavior[Envelope] = Behaviors.receiveMessagePartial {
      case Request(scope, PostBalanceToMessageBus(accountId)) => {
        val balance = getBalanceNonIO(accountId)
        postBalanceToMessageBus(balance)
        scope.provide(balance)
        Behaviors.same
      }
    }

    // chain sequences individual Bindings[_].
    def bindings: Bindings[_] = chain(
      // a Bindings[_] constructor from object Bindings
      // this performs the given IO on protocol match.
      responderIO {
        case PrintAndMailBalance(accountId) => requestBalanceSheet(accountId) >>= printInMailroom
      },
      // a Bindings[_] constructor from object Bindings
      // this delegates to an akka typed Behavior[Envelope]
      delegate(behavior)
    )
  }
}
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. ServiceBindings
  2. ServiceActor
  3. DirectLogging
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class Command[Response] extends Request[Response] with proto.ProtoDecl.Command with proto.ProtoDecl.Request

    All commands are Requests with Proto: extends Command[R] with Proto.

    All commands are Requests with Proto: extends Command[R] with Proto.

    sealed trait Proto extends Message
    case class ExampleCommand(msg: String) extends Command[ExampleResponse] with Proto
    Definition Classes
    ServiceActor
  2. sealed trait Envelope extends Product with Message with Serializable

    A Proto event with additional attributes and claims.

    A Proto event with additional attributes and claims. To pattern match on an Envelope use the Event.unapply or Request.unapply extractors.

    val behavior: Behavior[Envelope] = Behaviors.receiveMessagePartial {
      case Event(SomeEvent(eventData)) => ???
      case Request(scope, SomeCommand(eventData)) => ???
    }

    An Envelope can be implicitly constructed from any Proto.

    val delegate: ActorRef[Envelope] = ???
    val anEvent: Proto = SomeEvent(eventData)
    delegate ! anEvent
    Definition Classes
    ServiceActor
  3. abstract class Query[Response] extends Request[Response] with proto.ProtoDecl.Query with proto.ProtoDecl.Request

    All queries are Requests with Proto: extends Query[R] with Proto.

    All queries are Requests with Proto: extends Query[R] with Proto.

    sealed trait Proto extends Message
    case class ExampleQuery(msg: String) extends Query[ExampleResponse] with Proto
    Definition Classes
    ServiceActor
  4. sealed abstract class Request[R] extends AnyRef

    A protocol event can be declared as a Request using Command or Query.

    A protocol event can be declared as a Request using Command or Query. The type parameter is the response that resolves the request.

    sealed trait Proto extends Message
    case class ExampleCommand(msg: String) extends Command[ExampleResponse] with Proto
    case class ExampleQuery(msg: String) extends Query[ExampleResponse] with Proto
    Definition Classes
    ServiceActor
  5. final type AnyRequest = Proto with Request[_]

    AnyRequest is a Command or Query with no particular response type.

    AnyRequest is a Command or Query with no particular response type.

    Definition Classes
    ServiceActor
  6. final type Bindings[A] = FreeApplicative[BindingsOp, A]

    Type of bindings declaration.

  7. trait BindingsInstance extends AnyRef

  8. final type Delegate = ActorRef[Envelope]

    The delegate is an actor accepting events in Envelope messages.

  9. implicit class DelegateOps extends AnyRef

  10. abstract type Instance <: BindingsInstance

    This service actor object must contain a class Instance.

    This service actor object must contain a class Instance. This class must mix in, at least, BindingsInstance. Which contains the bindings value.

    The requirement on an Instance assists in parameterization of service actor behavior while keeping consideration of the Protocol separate.

    See ServiceFragment for high level API.

  11. abstract type InstanceEnv <: BindingsInstanceEnv

    Environment for instance of service actor using bindings.

    Environment for instance of service actor using bindings. This is data an Instance will always be provided.

  12. abstract type Proto <: Message

    The commands, queries and events all implement Proto.

    The commands, queries and events all implement Proto. Easy inferrence of operations schema and endpoint schema assumes the use of a sealed trait.

    Definition Classes
    ServiceActor
    Examples:
    1. a typical definition

      sealed trait Proto extends Message
    2. ,
    3. an event type AnEvent in Proto

      sealed trait Proto extends Message
      case class AnEvent(msg: String) extends Proto

Value Members

  1. object Envelope extends Serializable

    Definition Classes
    ServiceActor
  2. object Event

    Any statement in the protocol can be considered an Event not associated with any additional scope.

    Any statement in the protocol can be considered an Event not associated with any additional scope.

    - see also ServiceActor.RequestScope and Request.unapply

    Definition Classes
    ServiceActor
  3. object Request

    Definition Classes
    ServiceActor
  4. object StopEnvelope extends Envelope with Product with Serializable

    Definition Classes
    ServiceActor
  5. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def ##(): Int
    Definition Classes
    AnyRef → Any
  7. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  9. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  12. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  13. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  14. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  15. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  16. lazy val logger: prelude.external.Logger

    Attributes
    protected
    Definition Classes
    DirectLogging
  17. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  18. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  19. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  20. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  21. def toString(): String
    Definition Classes
    AnyRef → Any
  22. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  23. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  24. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  25. object Bindings

    Methods to bind this service's protocol to implementations.

    Methods to bind this service's protocol to implementations.

    If a binding is not provided for a protocol message the message is considered unhandled. Any endpoint for the protocol message will reply with HTTP 501 Not Implemented.

    // a hypothetical service for account balances
    final object AServiceFragment extends ServiceFragment {
    
      override def instantiate(env: InstanceEnv) = new Instance(env) {
        // the service event consumer is implemented using...
        val bindings = bindingsChain(
          // operations on a named entity
          entity(AnEntity) {
            case ServiceOperationOnEntity(entityId) => AnEntity.AnOperation -> accountId
          },
          // a daemon sending Proto messages back to this service
          async(OrdersOverSMSBehavior) // where OrdersOverSMSBehavior being a [[ServiceActorDaemon]]
        )
    }
    }

Inherited from ServiceActor

Inherited from AnyRef

Inherited from Any

Domain

Service Logic

Implementation Detail

Ungrouped