Created
January 31, 2018 17:34
-
-
Save kell18/1fafae0dd6e952eff6f416001d0aaeb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.itclover.streammachine.http.routes | |
import akka.actor.ActorSystem | |
import akka.http.scaladsl.server.Directives.{complete, path} | |
import akka.http.scaladsl.server.Route | |
import akka.http.scaladsl.server.Directives._ | |
import cats.data.Reader | |
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment | |
import ru.itclover.streammachine.http.domain.output.SuccessfulResponse | |
import ru.itclover.streammachine.http.protocols.JsonProtocols | |
import scala.concurrent.ExecutionContextExecutor | |
trait App { | |
implicit val as: ActorSystem | |
implicit val executionContext: ExecutionContextExecutor | |
implicit def streamEnvironment: StreamExecutionEnvironment | |
val composeRoutes: Reader[ExecutionContextExecutor, Route] = for { | |
streams <- FindStreamPatterns.fromExecutionContext | |
batches <- FindBatchPatterns.fromExecutionContext | |
} yield streams ~ batches | |
val route: Route = composeRoutes.run(executionContext) | |
// ... | |
} | |
trait FindStreamPatterns extends JsonProtocols { | |
implicit val streamEnv: StreamExecutionEnvironment | |
implicit val executionContext: ExecutionContextExecutor | |
val route: Route = { | |
path("find" / "stream") { | |
complete(SuccessfulResponse(1)) | |
} | |
} | |
} | |
object FindStreamPatterns { | |
def fromExecutionContext(implicit env: StreamExecutionEnvironment): Reader[ExecutionContextExecutor, Route] = Reader { executor => | |
new FindStreamPatterns { | |
implicit val streamEnv: StreamExecutionEnvironment = env | |
implicit val executionContext: ExecutionContextExecutor = executor | |
}.route | |
} | |
} | |
trait FindBatchPatterns extends JsonProtocols { | |
implicit val as: ActorSystem | |
implicit val executionContext: ExecutionContextExecutor | |
val route: Route = { | |
path("find" / "batch") { | |
complete(SuccessfulResponse(1)) | |
} | |
} | |
} | |
object FindBatchPatterns { | |
def fromExecutionContext: Reader[ExecutionContextExecutor, Route] = Reader { env => | |
new FindBatchPatterns { | |
implicit val as: ActorSystem = as | |
implicit val executionContext: ExecutionContextExecutor = env | |
}.route | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment