Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace all occurrences of @tagless annotation with the manual impl #296

Merged
merged 3 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ 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

@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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
package examples.todolist.client
package clients

import freestyle.tagless.tagless

@tagless(true)
trait PingPongClient[F[_]] {
def ping(): F[Unit]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -35,4 +33,4 @@ trait TodoItemClient[F[_]] {

def remove(id: Int): F[Int]

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -36,4 +33,4 @@ trait TodoListClient[F[_]] {

def remove(id: Int): F[Int]

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 30 additions & 3 deletions modules/server/src/main/scala/GrpcServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,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]

Expand All @@ -47,4 +46,32 @@ 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 {
def apply[F[_]](implicit F: GrpcServer[F]): GrpcServer[F] = F
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 2 additions & 4 deletions modules/server/src/test/scala/protocol/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -142,7 +141,6 @@ object Utils extends CommonUtils {

object client {

@tagless(true)
trait MyRPCClient[F[_]] {
def notAllowed(b: Boolean): F[C]
def empty: F[Empty.type]
Expand Down Expand Up @@ -307,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)
Expand Down Expand Up @@ -413,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)
Expand Down