Skip to content

Commit

Permalink
Merge pull request #179 from ahjohannessen/wip-fs2-netty-ops
Browse files Browse the repository at this point in the history
api: make ops discoverable
  • Loading branch information
ahjohannessen authored Oct 3, 2020
2 parents bb8aaa6 + 1670f57 commit fe6bf99
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/sec/api/endpoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ final case class Endpoint(
port: Int
)

private[sec] object Endpoint {
object Endpoint {

implicit val orderForEndpoint: Order[Endpoint] = Order.by(ep => (ep.address, ep.port))
implicit val orderingForEndpoint: Ordering[Endpoint] = orderForEndpoint.toOrdering
implicit val showForEndpoint: Show[Endpoint] = Show.show(ep => s"${ep.address}:${ep.port}")

implicit final class EndpointOps(val ep: Endpoint) extends AnyVal {
implicit final private[sec] class EndpointOps(val ep: Endpoint) extends AnyVal {
def toInetSocketAddress: InetSocketAddress = new InetSocketAddress(ep.address, ep.port)
def toEquivalentAddressGroup: EquivalentAddressGroup =
new EquivalentAddressGroup(ep.toInetSocketAddress, Attributes.EMPTY)
Expand Down
18 changes: 16 additions & 2 deletions fs2-netty/src/main/scala/sec/api/netty.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,21 @@ import io.grpc.netty.NettyChannelBuilder.{forAddress, forTarget}
import io.grpc.netty.GrpcSslContexts.forClient
import io.netty.handler.ssl.SslContext

private[sec] object netty {
object netty {

def mkBuilder[F[_]: Sync](p: ChannelBuilderParams): F[NettyChannelBuilder] = {
//======================================================================================================================

final class SingleNodeBuilderOps[F[_]: ConcurrentEffect: Timer](val b: SingleNodeBuilder[F]) {
def resource: Resource[F, EsClient[F]] = b.build(mkBuilder[F])
}

final class ClusterBuilderOps[F[_]: ConcurrentEffect: Timer](val b: ClusterBuilder[F]) {
def resource: Resource[F, EsClient[F]] = b.build(mkBuilder[F])
}

//======================================================================================================================

private[sec] def mkBuilder[F[_]: Sync](p: ChannelBuilderParams): F[NettyChannelBuilder] = {

def mkSslContext(chainPath: Path): F[SslContext] = Sync[F].delay {
forClient().trustManager(chainPath.toFile).build()
Expand All @@ -43,4 +55,6 @@ private[sec] object netty {

}

//======================================================================================================================

}
14 changes: 8 additions & 6 deletions fs2-netty/src/main/scala/sec/api/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ import cats.effect._

package object api {

implicit final class SingleNodeBuilderOps[F[_]: ConcurrentEffect: Timer](val b: SingleNodeBuilder[F]) {
def resource: Resource[F, EsClient[F]] = b.build(netty.mkBuilder[F])
}
import sec.api.netty._

implicit final class ClusterBuilderOps[F[_]: ConcurrentEffect: Timer](val b: ClusterBuilder[F]) {
def resource: Resource[F, EsClient[F]] = b.build(netty.mkBuilder[F])
}
implicit def singleNodeBuilderSyntax[F[_]: ConcurrentEffect: Timer](
snb: SingleNodeBuilder[F]
): SingleNodeBuilderOps[F] = new SingleNodeBuilderOps[F](snb)

implicit def clusterBuilderSyntax[F[_]: ConcurrentEffect: Timer](
cb: ClusterBuilder[F]
): ClusterBuilderOps[F] = new ClusterBuilderOps[F](cb)

}
1 change: 0 additions & 1 deletion tests/src/cit/scala/sec/api/spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import scala.concurrent.duration._
import cats.data.NonEmptySet
import cats.effect._
import io.chrisdavenport.log4cats.Logger
import sec.api._
import helpers.endpoint.endpointFrom

trait CSpec extends ClientSpec {
Expand Down
1 change: 0 additions & 1 deletion tests/src/sit/scala/sec/api/spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import cats.effect._
import io.chrisdavenport.log4cats.Logger
import org.scalacheck.Gen
import sec.arbitraries._
import sec.api._

trait SnSpec extends ClientSpec {

Expand Down

0 comments on commit fe6bf99

Please sign in to comment.