MultiHostExtension

com.github.cloudfiles.core.http.MultiHostExtension

An actor implementation that can send HTTP requests to multiple hosts.

Being a layer on top of Akka HTTP's host level API, HttpRequestSender is configured with a single host, to which all requests are sent. This actor implementation overcomes this limitation by creating request actors dynamically whenever a request to a new host is encountered. All request actors managed by an instance are hold in a map, so they are reused. The creation of new child actors is done via a factory function, so it can be customized if necessary.

Note that this implementation is not intended to be used as a generic mechanism for sending arbitrary HTTP requests; keeping all the different request actors around would be rather ineffective. Some protocols, however, require that requests are sent to different hosts, for instance when file downloads are handled by a different server than other API calls.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Type members

Types

type RequestActorCreator = ActorContext[HttpCommand] => ActorRef[HttpCommand]

A function type that supports the creation of new request actors. This type is used as result by RequestActorFactory. It is passed an actor context that can be used to create a new request actor reference.

A function type that supports the creation of new request actors. This type is used as result by RequestActorFactory. It is passed an actor context that can be used to create a new request actor reference.

Note that this indirection via this function type is necessary because RequestActorFactory is supposed to return a ''Future''. Running in its own thread, from this future no actors can be created (the ''spawn()'' function of ''ActorContext'' is not thread-safe).

Attributes

A function type to create new request actors. This function is used by the multi-host extension when it encounters a new host for the first time to create the request actor for this host. The function is passed the URI of the current request, the configured size of the request queue, and the configured ''ProxySelectorFunc''. As collecting all the data of the new actor instance may be expensive (e.g. credentials may need to be loaded), it returns a ''Future'' with a RequestActorCreator. The multi-host extension then invokes this creator to actually create the new request actor.

A function type to create new request actors. This function is used by the multi-host extension when it encounters a new host for the first time to create the request actor for this host. The function is passed the URI of the current request, the configured size of the request queue, and the configured ''ProxySelectorFunc''. As collecting all the data of the new actor instance may be expensive (e.g. credentials may need to be loaded), it returns a ''Future'' with a RequestActorCreator. The multi-host extension then invokes this creator to actually create the new request actor.

Attributes

Value members

Concrete methods

def apply(requestQueueSize: Int, proxy: ProxySelectorFunc, requestActorFactory: RequestActorFactory): Behavior[HttpCommand]

Creates a new instance of this actor class.

Creates a new instance of this actor class.

Value parameters

proxy

a function to select the proxy for requests

requestActorFactory

the function to create new request actors

requestQueueSize

the size of the request queue

Attributes

Returns

the initial behavior of the new actor instance

def defaultRequestActorFactory(uri: Uri, requestQueueSize: Int, proxy: ProxySelectorFunc): Future[RequestActorCreator]

The default factory function for creating new request actors. This function spawns an anonymous, plain HttpRequestSender actor.

The default factory function for creating new request actors. This function spawns an anonymous, plain HttpRequestSender actor.

Value parameters

proxy

the function to select a proxy

requestQueueSize

the size of the request queue

uri

the URI of the current request

Attributes

Returns

a reference to the newly created actor