com.bazaarvoice.support.scala.service
Selects the fastest known provider and execute the body b
against that provider.
Selects the fastest known provider and execute the body b
against that provider.
We time the execution and maintain a running average of the execution times for each provider. This provides the basis for selecting the fasted provider.
If b(provider)
results in an exception, we average in Double.MaxValue
to that provider's
execution times, effectively putting it at the back of the priority queue. If you are aware of exceptions
that should not result in re-prioritizing the provider, it is your responsibility to capture them in b
and ensure that they are not thrown.
Example Usage:
val maybeResponse = pool.execute { host => try { Success(client(host + serviceUrl).get(classOf[Response])) } catch { case e: ExpectedExceptionType => Failure(e) case t: Throwable => throw t } } maybeResponse match { case Success(res) => () // do something with res case Failure(e) => throw e // assuming you actually need this thrown }
The return type of b
.
The function from (host: T)
to return type R
to evaluate against the selected host.
If b
returns normally, execute
will return b
's return value.
If b
terminates abnormally, execute
will rethrow the exception that b
threw.
If there was no available host, execute
will return None
Updates the providers list, preserving the statistics for existing hosts, adding new hosts, and dropping hosts that are not present in the new list.
Updates the providers list, preserving the statistics for existing hosts, adding new hosts, and dropping hosts that are not present in the new list.
the new list of service providers.
A lightweight service pool implementation with latency awareness.
Usage:
When you provide an updated providers list, the service pool will compare the new list with the current providers, preserving the statistics for hosts it already knows about, adding new hosts, and dropping hosts that are not present in the new list.
The type of the service to track. Can be anything.