From 302feddcb5d429d14f5a5e85559a7fff55b79f2c Mon Sep 17 00:00:00 2001 From: Pepe Garcia Date: Mon, 4 Jun 2018 11:41:01 +0200 Subject: [PATCH 1/3] replace all occurrences of @tagless annotation with the manual impl Currently, most of the implementaitions only needed the `Handler[F]` type in the companion. --- .../client/src/main/scala/ClientProgram.scala | 5 ++- .../main/scala/clients/PingPongClient.scala | 7 ++-- .../src/main/scala/clients/TagClient.scala | 6 ++-- .../main/scala/clients/TodoItemClient.scala | 8 +++-- .../main/scala/clients/TodoListClient.scala | 9 ++--- .../server/src/main/scala/GrpcServer.scala | 36 +++++++++++++++++-- .../src/test/scala/protocol/Utils.scala | 12 +++++-- 7 files changed, 65 insertions(+), 18 deletions(-) diff --git a/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala b/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala index 7ceb7ea7b..fc6266364 100644 --- a/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala +++ b/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala @@ -23,7 +23,6 @@ import freestyle.tagless._ import example.routeguide.protocol.Protocols._ import example.routeguide.common.Utils -@tagless(false) trait RouteGuideClient[F[_]] { def getFeature(lat: Int, lon: Int): F[Unit] def listFeatures(lowLat: Int, lowLon: Int, hiLat: Int, hiLon: Int): F[Unit] @@ -31,6 +30,10 @@ trait RouteGuideClient[F[_]] { def routeChat: F[Unit] } +object RouteGuideClient { + trait Handler[G[_]] extends RouteGuideClient[G] +} + object ClientProgram { def clientProgram[M[_]: Monad](implicit APP: RouteGuideClient[M]): M[Unit] = { diff --git a/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala b/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala index c84999498..854ebd70e 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala @@ -17,9 +17,10 @@ package examples.todolist.client package clients -import freestyle.tagless.tagless - -@tagless(true) trait PingPongClient[F[_]] { def ping(): F[Unit] } + +object PingPongClient { + trait Handler[G[_]] extends PingPongClient[G] +} diff --git a/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala b/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala index b37a8e86d..91b9c2539 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala @@ -18,9 +18,7 @@ package examples.todolist.client package clients import examples.todolist.protocol.Protocols._ -import freestyle.tagless.tagless -@tagless(true) trait TagClient[F[_]] { def reset(): F[Int] @@ -36,3 +34,7 @@ trait TagClient[F[_]] { def remove(id: Int): F[Int] } + +object TagClient { + trait Handler[G[_]] extends TagClient[G] +} diff --git a/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala b/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala index e741653a9..6eaa7be5f 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala @@ -18,9 +18,7 @@ package examples.todolist.client package clients import examples.todolist.protocol.Protocols._ -import freestyle.tagless.tagless -@tagless(true) trait TodoItemClient[F[_]] { def reset(): F[Int] @@ -35,4 +33,8 @@ trait TodoItemClient[F[_]] { def remove(id: Int): F[Int] -} \ No newline at end of file +} + +object TodoItemClient { + trait Handler[G[_]] extends TodoItemClient[G] +} diff --git a/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala b/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala index 31f667652..b1c1ffc4f 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala @@ -17,11 +17,8 @@ package examples.todolist.client package clients -import freestyle.tagless.tagless - import examples.todolist.protocol.Protocols._ -@tagless(true) trait TodoListClient[F[_]] { def reset(): F[Int] @@ -36,4 +33,8 @@ trait TodoListClient[F[_]] { def remove(id: Int): F[Int] -} \ No newline at end of file +} + +object TodoListClient { + trait Handler[G[_]] extends TodoListClient[G] +} diff --git a/modules/server/src/main/scala/GrpcServer.scala b/modules/server/src/main/scala/GrpcServer.scala index 7c63e9382..86320da36 100644 --- a/modules/server/src/main/scala/GrpcServer.scala +++ b/modules/server/src/main/scala/GrpcServer.scala @@ -18,12 +18,12 @@ package freestyle.rpc package server import freestyle.tagless.tagless +import cats.~> import io.grpc._ import scala.concurrent.duration.TimeUnit -@tagless(true) -trait GrpcServer[F[_]] { +trait GrpcServer[F[_]] { self => def start(): F[Server] @@ -47,4 +47,36 @@ trait GrpcServer[F[_]] { def awaitTermination(): F[Unit] + def mapK[G[_]](fk: F ~> G): GrpcServer[G] = new GrpcServer[G] { + def start(): G[Server] = fk(self.start) + + def getPort: G[Int] = fk(self.getPort) + + def getServices: G[List[ServerServiceDefinition]] = fk(self.getServices) + + def getImmutableServices: G[List[ServerServiceDefinition]] = fk(self.getImmutableServices) + + def getMutableServices: G[List[ServerServiceDefinition]] = fk(self.getMutableServices) + + def shutdown(): G[Server] = fk(self.shutdown) + + def shutdownNow(): G[Server] = fk(self.shutdownNow) + + def isShutdown: G[Boolean] = fk(self.isShutdown) + + def isTerminated: G[Boolean] = fk(self.isTerminated) + + def awaitTerminationTimeout(timeout: Long, unit: TimeUnit): G[Boolean] = + fk(self.awaitTerminationTimeout(timeout, unit)) + + def awaitTermination(): G[Unit] = fk(self.awaitTermination) + } +} + +object GrpcServer { + + trait Handler[G[_]] extends GrpcServer[G] + + def apply[F[_]](implicit F: GrpcServer[F]): GrpcServer[F] = F + } diff --git a/modules/server/src/test/scala/protocol/Utils.scala b/modules/server/src/test/scala/protocol/Utils.scala index 776b14528..f9bd2b67b 100644 --- a/modules/server/src/test/scala/protocol/Utils.scala +++ b/modules/server/src/test/scala/protocol/Utils.scala @@ -22,7 +22,6 @@ import cats.effect.Async import cats.syntax.applicative._ import freestyle.rpc.common._ import freestyle.rpc.server.implicits._ -import freestyle.tagless.tagless import io.grpc.Status import monix.reactive.Observable @@ -142,8 +141,7 @@ object Utils extends CommonUtils { object client { - @tagless(true) - trait MyRPCClient[F[_]] { + trait MyRPCClient[F[_]] { self => def notAllowed(b: Boolean): F[C] def empty: F[Empty.type] def emptyParam(a: A): F[Empty.type] @@ -165,6 +163,14 @@ object Utils extends CommonUtils { def bsws(eList: List[E]): F[E] } + object MyRPCClient { + + trait Handler[G[_]] extends MyRPCClient[G] + + def apply[F[_]](implicit F: MyRPCClient[F]): MyRPCClient[F] = F + + } + } object handlers { From a57fcc6be17ee0ed7faf9ce10177a6176565e1bf Mon Sep 17 00:00:00 2001 From: Pepe Garcia Date: Mon, 4 Jun 2018 12:49:44 +0200 Subject: [PATCH 2/3] remove useless Handler traits in companions --- .../routeguide/client/src/main/scala/ClientProgram.scala | 5 ----- .../src/main/scala/handlers/RouteGuideClientHandler.scala | 2 +- .../client/src/main/scala/clients/PingPongClient.scala | 4 ---- .../todolist/client/src/main/scala/clients/TagClient.scala | 4 ---- .../client/src/main/scala/clients/TodoItemClient.scala | 4 ---- .../client/src/main/scala/clients/TodoListClient.scala | 4 ---- .../src/main/scala/handlers/PingPongClientHandler.scala | 2 +- .../client/src/main/scala/handlers/TagClientHandler.scala | 2 +- .../src/main/scala/handlers/TodoItemClientHandler.scala | 2 +- .../src/main/scala/handlers/TodoListClientHandler.scala | 2 +- modules/server/src/main/scala/GrpcServer.scala | 5 ----- .../server/src/main/scala/handlers/GrpcServerHandler.scala | 2 +- 12 files changed, 6 insertions(+), 32 deletions(-) diff --git a/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala b/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala index fc6266364..408bd4cf8 100644 --- a/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala +++ b/modules/examples/routeguide/client/src/main/scala/ClientProgram.scala @@ -19,7 +19,6 @@ package example.routeguide.client import cats.Monad import cats.syntax.flatMap._ import cats.syntax.functor._ -import freestyle.tagless._ import example.routeguide.protocol.Protocols._ import example.routeguide.common.Utils @@ -30,10 +29,6 @@ trait RouteGuideClient[F[_]] { def routeChat: F[Unit] } -object RouteGuideClient { - trait Handler[G[_]] extends RouteGuideClient[G] -} - object ClientProgram { def clientProgram[M[_]: Monad](implicit APP: RouteGuideClient[M]): M[Unit] = { diff --git a/modules/examples/routeguide/client/src/main/scala/handlers/RouteGuideClientHandler.scala b/modules/examples/routeguide/client/src/main/scala/handlers/RouteGuideClientHandler.scala index f521ac6f2..b216b97ba 100644 --- a/modules/examples/routeguide/client/src/main/scala/handlers/RouteGuideClientHandler.scala +++ b/modules/examples/routeguide/client/src/main/scala/handlers/RouteGuideClientHandler.scala @@ -32,7 +32,7 @@ class RouteGuideClientHandler[F[_]: Monad]( implicit client: RouteGuideService.Client[F], M: MonadError[F, Throwable], T2F: Task ~> F) - extends RouteGuideClient.Handler[F] { + extends RouteGuideClient[F] { val logger = getLogger diff --git a/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala b/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala index 854ebd70e..0d2b41693 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/PingPongClient.scala @@ -20,7 +20,3 @@ package clients trait PingPongClient[F[_]] { def ping(): F[Unit] } - -object PingPongClient { - trait Handler[G[_]] extends PingPongClient[G] -} diff --git a/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala b/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala index 91b9c2539..df44e482a 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/TagClient.scala @@ -34,7 +34,3 @@ trait TagClient[F[_]] { def remove(id: Int): F[Int] } - -object TagClient { - trait Handler[G[_]] extends TagClient[G] -} diff --git a/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala b/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala index 6eaa7be5f..e537d6f0c 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/TodoItemClient.scala @@ -34,7 +34,3 @@ trait TodoItemClient[F[_]] { def remove(id: Int): F[Int] } - -object TodoItemClient { - trait Handler[G[_]] extends TodoItemClient[G] -} diff --git a/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala b/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala index b1c1ffc4f..5015a2f4e 100644 --- a/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala +++ b/modules/examples/todolist/client/src/main/scala/clients/TodoListClient.scala @@ -34,7 +34,3 @@ trait TodoListClient[F[_]] { def remove(id: Int): F[Int] } - -object TodoListClient { - trait Handler[G[_]] extends TodoListClient[G] -} diff --git a/modules/examples/todolist/client/src/main/scala/handlers/PingPongClientHandler.scala b/modules/examples/todolist/client/src/main/scala/handlers/PingPongClientHandler.scala index 8bd86e059..a32295ae3 100644 --- a/modules/examples/todolist/client/src/main/scala/handlers/PingPongClientHandler.scala +++ b/modules/examples/todolist/client/src/main/scala/handlers/PingPongClientHandler.scala @@ -25,7 +25,7 @@ import freestyle.rpc.protocol.Empty import org.log4s._ class PingPongClientHandler[F[_]](implicit M: Functor[F], client: PingPongService.Client[F]) - extends PingPongClient.Handler[F] { + extends PingPongClient[F] { val logger: Logger = getLogger diff --git a/modules/examples/todolist/client/src/main/scala/handlers/TagClientHandler.scala b/modules/examples/todolist/client/src/main/scala/handlers/TagClientHandler.scala index c8a82a11e..16dc61a1a 100644 --- a/modules/examples/todolist/client/src/main/scala/handlers/TagClientHandler.scala +++ b/modules/examples/todolist/client/src/main/scala/handlers/TagClientHandler.scala @@ -29,7 +29,7 @@ class TagClientHandler[F[_]]( implicit M: Monad[F], log: LoggingM[F], client: TagRpcService.Client[F]) - extends TagClient.Handler[F] { + extends TagClient[F] { override def reset(): F[Int] = for { diff --git a/modules/examples/todolist/client/src/main/scala/handlers/TodoItemClientHandler.scala b/modules/examples/todolist/client/src/main/scala/handlers/TodoItemClientHandler.scala index a4e43c080..175e712d1 100644 --- a/modules/examples/todolist/client/src/main/scala/handlers/TodoItemClientHandler.scala +++ b/modules/examples/todolist/client/src/main/scala/handlers/TodoItemClientHandler.scala @@ -29,7 +29,7 @@ class TodoItemClientHandler[F[_]]( implicit M: Monad[F], log: LoggingM[F], client: TodoItemRpcService.Client[F]) - extends TodoItemClient.Handler[F] { + extends TodoItemClient[F] { override def reset(): F[Int] = for { diff --git a/modules/examples/todolist/client/src/main/scala/handlers/TodoListClientHandler.scala b/modules/examples/todolist/client/src/main/scala/handlers/TodoListClientHandler.scala index 51148b4a6..c4183b66b 100644 --- a/modules/examples/todolist/client/src/main/scala/handlers/TodoListClientHandler.scala +++ b/modules/examples/todolist/client/src/main/scala/handlers/TodoListClientHandler.scala @@ -29,7 +29,7 @@ class TodoListClientHandler[F[_]]( implicit M: Monad[F], log: LoggingM[F], client: TodoListRpcService.Client[F]) - extends TodoListClient.Handler[F] { + extends TodoListClient[F] { override def reset(): F[Int] = for { diff --git a/modules/server/src/main/scala/GrpcServer.scala b/modules/server/src/main/scala/GrpcServer.scala index 86320da36..0d1e8d6fd 100644 --- a/modules/server/src/main/scala/GrpcServer.scala +++ b/modules/server/src/main/scala/GrpcServer.scala @@ -17,7 +17,6 @@ package freestyle.rpc package server -import freestyle.tagless.tagless import cats.~> import io.grpc._ @@ -74,9 +73,5 @@ trait GrpcServer[F[_]] { self => } object GrpcServer { - - trait Handler[G[_]] extends GrpcServer[G] - def apply[F[_]](implicit F: GrpcServer[F]): GrpcServer[F] = F - } diff --git a/modules/server/src/main/scala/handlers/GrpcServerHandler.scala b/modules/server/src/main/scala/handlers/GrpcServerHandler.scala index 66ed90adb..629812b5e 100644 --- a/modules/server/src/main/scala/handlers/GrpcServerHandler.scala +++ b/modules/server/src/main/scala/handlers/GrpcServerHandler.scala @@ -25,7 +25,7 @@ import io.grpc.{Server, ServerServiceDefinition} import scala.collection.JavaConverters._ import scala.concurrent.duration.TimeUnit -class GrpcServerHandler[F[_]: Applicative] extends GrpcServer.Handler[GrpcServerOps[F, ?]] { +class GrpcServerHandler[F[_]: Applicative] extends GrpcServer[GrpcServerOps[F, ?]] { def start: GrpcServerOps[F, Server] = captureWithServer { server => Runtime.getRuntime.addShutdownHook(new Thread() { From 24d73bc7ce879200365d255acea0971344d28ee7 Mon Sep 17 00:00:00 2001 From: Pepe Garcia Date: Mon, 4 Jun 2018 13:00:15 +0200 Subject: [PATCH 3/3] completely delete the companion object for MyRPCClient --- modules/server/src/test/scala/protocol/Utils.scala | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/server/src/test/scala/protocol/Utils.scala b/modules/server/src/test/scala/protocol/Utils.scala index f9bd2b67b..e784e826d 100644 --- a/modules/server/src/test/scala/protocol/Utils.scala +++ b/modules/server/src/test/scala/protocol/Utils.scala @@ -141,7 +141,7 @@ object Utils extends CommonUtils { object client { - trait MyRPCClient[F[_]] { self => + trait MyRPCClient[F[_]] { def notAllowed(b: Boolean): F[C] def empty: F[Empty.type] def emptyParam(a: A): F[Empty.type] @@ -163,14 +163,6 @@ object Utils extends CommonUtils { def bsws(eList: List[E]): F[E] } - object MyRPCClient { - - trait Handler[G[_]] extends MyRPCClient[G] - - def apply[F[_]](implicit F: MyRPCClient[F]): MyRPCClient[F] = F - - } - } object handlers { @@ -313,7 +305,7 @@ object Utils extends CommonUtils { class FreesRPCServiceClientHandler[F[_]: Async]( implicit client: RPCService.Client[F], M: MonadError[F, Throwable]) - extends MyRPCClient.Handler[F] { + extends MyRPCClient[F] { override def notAllowed(b: Boolean): F[C] = client.notAllowed(b) @@ -419,7 +411,7 @@ object Utils extends CommonUtils { class FreesRPCServiceClientCompressedHandler[F[_]: Async]( implicit client: RPCService.Client[F], M: MonadError[F, Throwable]) - extends MyRPCClient.Handler[F] { + extends MyRPCClient[F] { override def notAllowed(b: Boolean): F[C] = client.notAllowedCompressed(b)