Skip to content

Commit

Permalink
Drop deprecated ways to build connection and client (#1008)
Browse files Browse the repository at this point in the history
  • Loading branch information
geirolz authored Oct 31, 2024
1 parent de9623d commit 2ed7d7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import dev.profunktor.fs2rabbit.model.AMQPConnection
import dev.profunktor.fs2rabbit.model.RabbitChannel
import dev.profunktor.fs2rabbit.model.RabbitConnection

import java.util
import java.util.Collections
import java.util.concurrent.AbstractExecutorService
import java.util.concurrent.ExecutorService
Expand All @@ -46,47 +47,6 @@ import java.util.concurrent.Executors
object ConnectionResource {
type ConnectionResource[F[_]] = Connection[Resource[F, *]]

@deprecated(message = "Use `make` with explicit ExecutionContext", since = "5.0.0")
def make[F[_]: Sync: Log](
conf: Fs2RabbitConfig,
sslCtx: Option[SSLContext] = None,
// Unlike SSLContext, SaslConfig is not optional because it is always set
// by the underlying Java library, even if the user doesn't set it.
saslConf: SaslConfig = DefaultSaslConfig.PLAIN,
metricsCollector: Option[MetricsCollector] = None,
threadFactory: Option[F[ThreadFactory]] = None
): F[Connection[Resource[F, *]]] = {
val addThreadFactory: F[ConnectionFactory => Unit] =
threadFactory.fold(Sync[F].pure((_: ConnectionFactory) => ())) { threadFact =>
threadFact.map { tf => (cf: ConnectionFactory) =>
cf.setThreadFactory(tf)
}
}

val numOfThreads = Runtime.getRuntime().availableProcessors() * 2
val esF: F[ExecutorService] = threadFactory
.fold(Executors.newFixedThreadPool(numOfThreads).pure[F]) {
_.map(Executors.newFixedThreadPool(numOfThreads, _))
}
.map { es =>
val _ = sys.addShutdownHook(es.shutdown())
es
}

for {
es <- esF
fn <- addThreadFactory
conn <- _make(
conf,
Some(ExecutionContext.fromExecutorService(es)),
sslCtx,
saslConf,
metricsCollector,
fn
)
} yield conn
}

def make[F[_]: Sync: Log](
conf: Fs2RabbitConfig,
executionContext: ExecutionContext,
Expand Down Expand Up @@ -185,10 +145,10 @@ object ConnectionResource {
case es: ExecutorService => es
case _ =>
new AbstractExecutorService {
override def isShutdown = false
override def isTerminated = false
override def shutdown() = ()
override def shutdownNow() = Collections.emptyList[Runnable]
override def isShutdown: Boolean = false
override def isTerminated: Boolean = false
override def shutdown(): Unit = ()
override def shutdownNow(): util.List[Runnable] = Collections.emptyList[Runnable]
override def execute(runnable: Runnable): Unit = ec execute runnable
override def awaitTermination(length: Long, unit: TimeUnit): Boolean = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,49 +40,6 @@ import javax.net.ssl.SSLContext
import scala.concurrent.ExecutionContext

object RabbitClient {
@deprecated(message = "Use `default` to create Builder instead", since = "5.0.0")
def apply[F[_]: Async](
config: Fs2RabbitConfig,
dispatcher: Dispatcher[F],
sslContext: Option[SSLContext] = None,
// Unlike SSLContext, SaslConfig is not optional because it is always set
// by the underlying Java library, even if the user doesn't set it.
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
metricsCollector: Option[MetricsCollector] = None,
threadFactory: Option[F[ThreadFactory]] = None
): F[RabbitClient[F]] = {
val internalQ = new LiveInternalQueue[F](config.internalQueueSize.getOrElse(500))
val connection = ConnectionResource.make(config, sslContext, saslConfig, metricsCollector, threadFactory)
val consumingProgram = AckConsumingProgram.make[F](config, internalQ, dispatcher)
val publishingProgram = PublishingProgram.make[F](dispatcher)
val bindingClient = Binding.make[F]
val declarationClient = Declaration.make[F]
val deletionClient = Deletion.make[F]

connection.map { conn =>
new RabbitClient[F](
conn,
bindingClient,
declarationClient,
deletionClient,
consumingProgram,
publishingProgram
)
}
}

@deprecated(message = "Use `default` to create Builder instead", since = "5.0.0")
def resource[F[_]: Async](
config: Fs2RabbitConfig,
sslContext: Option[SSLContext] = None,
// Unlike SSLContext, SaslConfig is not optional because it is always set
// by the underlying Java library, even if the user doesn't set it.
saslConfig: SaslConfig = DefaultSaslConfig.PLAIN,
metricsCollector: Option[MetricsCollector] = None,
threadFactory: Option[F[ThreadFactory]] = None
): Resource[F, RabbitClient[F]] = Dispatcher.parallel[F](await = false).evalMap { dispatcher =>
apply[F](config, dispatcher, sslContext, saslConfig, metricsCollector, threadFactory)
}

sealed abstract class Builder[F[_]: Async] private[RabbitClient] (
config: Fs2RabbitConfig,
Expand Down

0 comments on commit 2ed7d7e

Please sign in to comment.