From c0d574dc6134e4f406875ea5a1301ba46602a6ec Mon Sep 17 00:00:00 2001 From: vlad Date: Fri, 15 Jul 2016 19:41:26 -0400 Subject: Initial commit with standard lib, might be used a example of cake --- src/main/scala/com/drivergrp/core/Service.scala | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/scala/com/drivergrp/core/Service.scala (limited to 'src/main/scala/com/drivergrp/core/Service.scala') diff --git a/src/main/scala/com/drivergrp/core/Service.scala b/src/main/scala/com/drivergrp/core/Service.scala new file mode 100644 index 0000000..4404c9c --- /dev/null +++ b/src/main/scala/com/drivergrp/core/Service.scala @@ -0,0 +1,34 @@ +package com.drivergrp.core + +import akka.http.scaladsl.server.{Route, RouteConcatenation} + + +trait Service { + import scala.reflect.runtime.universe._ + + val name: String + def route: Route + def serviceTypes: Seq[Type] + + def activate(): Unit = {} + def deactivate(): Unit = {} +} + +/** + * Service implementation which may be used to composed a few + * + * @param name more general name of the composite service, + * must be provided as there is no good way to automatically + * generalize the name from the composed services' names + * @param services services to compose into a single one + */ +class CompositeService(val name: String, services: Seq[Service]) + extends Service with RouteConcatenation { + + def route: Route = services.map(_.route).reduce(_ ~ _) + + def serviceTypes = services.flatMap(_.serviceTypes) + + override def activate() = services.foreach(_.activate()) + override def deactivate() = services.reverse.foreach(_.deactivate()) +} \ No newline at end of file -- cgit v1.2.3