Class/Object

com.bazaarvoice.support.scala.service

LatencyAwareServicePool

Related Docs: object LatencyAwareServicePool | package service

Permalink

class LatencyAwareServicePool[T] extends AnyRef

A lightweight service pool implementation with latency awareness.

Usage:

type Host = String
val pool = new LatencyAwareServicePool[Host]()
pool.setProviders(initialProvidersList)

def queryThing() = pool.execute { host =>
  LOG.info(s"querying $host")
  doQuery(host)
}

def renewProviderList(updatedProviders: Set[Host]) = pool.setProviders(updatedProviders)

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.

T

The type of the service to track. Can be anything.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. LatencyAwareServicePool
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new LatencyAwareServicePool()

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. def __debug_view(): Map[T, Map[String, AnyVal]]

    Permalink
    Annotations
    @Deprecated
  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  7. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  8. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  9. def execute[R](b: (T) ⇒ R): Option[R]

    Permalink

    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
    }
    R

    The return type of b.

    b

    The function from (host: T) to return type R to evaluate against the selected host.

    returns

    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

  10. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  14. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  15. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  17. def setProviders(providers: Set[T]): Unit

    Permalink

    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.

    providers

    the new list of service providers.

  18. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  19. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  20. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  22. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped