final case class Server(muxer: StackServer[Request, Response] = Server.defaultMuxer) extends StackBasedServer[Array[Byte], Array[Byte]] with ThriftRichServer with Parameterized[Server] with CommonParams[Server] with WithServerTransport[Server] with WithServerSession[Server] with WithServerAdmissionControl[Server] with OpportunisticTlsParams[Server] with WithCompressionPreferences[Server] with Product with Serializable
A ThriftMux com.twitter.finagle.Server
.
- See also
Configuration documentation
Thrift documentation
Mux documentation
- Alphabetic
- By Inheritance
- Server
- Serializable
- Product
- Equals
- WithCompressionPreferences
- OpportunisticTlsParams
- WithServerAdmissionControl
- WithServerSession
- WithServerTransport
- CommonParams
- ThriftRichServer
- StackBasedServer
- Transformable
- Parameterized
- Server
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Server(muxer: StackServer[Request, Response] = Server.defaultMuxer)
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def configured[P](psp: (P, Param[P])): Server
Java friendly API for
configured
.Java friendly API for
configured
.The
Tuple2
can often be created by calls to amk(): (P, Stack.Param[P])
method on parameters (see com.twitter.finagle.loadbalancer.LoadBalancerFactory.Param.mk() as an example).- Definition Classes
- Server → Parameterized
- def configured[P](p: P)(implicit sp: Param[P]): Server
Add the parameter,
p
, to the current Params.Add the parameter,
p
, to the current Params.Java users may find it easier to use the
Tuple2
version below.- Definition Classes
- Parameterized
- def configuredParams(newParams: Params): Server
Adds all parameters,
newParams
, to the current Params.Adds all parameters,
newParams
, to the current Params.- Definition Classes
- Parameterized
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def filtered(filter: Filter[Request, Response, Request, Response]): Server
Prepends
filter
to the top of the server.Prepends
filter
to the top of the server. That is, after materializing the server (newService)filter
will be the first element which requests flow through. This is a familiar chaining combinator for filters. - def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def maxThriftBufferSize: Int
- Attributes
- protected
- Definition Classes
- ThriftRichServer
- val muxer: StackServer[Request, Response]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def params: Params
- Definition Classes
- Server → ThriftRichServer → Parameterized
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- def serve(addr: SocketAddress, factory: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
- final def serve(addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
Serve
service
ataddr
- Definition Classes
- Server
- final def serve(addr: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
Serve
service
ataddr
- Definition Classes
- Server
- final def serve(addr: SocketAddress, service: Service[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
Serve
service
ataddr
- Definition Classes
- Server
- def serveAndAnnounce(name: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
and announce withname
.Serve
service
ataddr
and announce withname
. Announcements will be removed when the service is closed. Omitting theaddr
will bind to an ephemeral port.- Definition Classes
- Server
- def serveAndAnnounce(name: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
and announce withname
.Serve
service
ataddr
and announce withname
. Announcements will be removed when the service is closed. Omitting theaddr
will bind to an ephemeral port.- Definition Classes
- Server
- def serveAndAnnounce(name: String, addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
and announce withname
.Serve
service
ataddr
and announce withname
. Announcements will be removed when the service is closed. Omitting theaddr
will bind to an ephemeral port.- Definition Classes
- Server
- def serveAndAnnounce(name: String, addr: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
and announce withname
.Serve
service
ataddr
and announce withname
. Announcements will be removed when the service is closed. Omitting theaddr
will bind to an ephemeral port.- Definition Classes
- Server
- def serveAndAnnounce(name: String, addr: SocketAddress, service: Service[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
and announce withname
.Serve
service
ataddr
and announce withname
. Announcements will be removed when the service is closed. Omitting theaddr
will bind to an ephemeral port.- Definition Classes
- Server
- def serveAndAnnounce(name: String, addr: SocketAddress, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
Serve
service
ataddr
and announce withname
.Serve
service
ataddr
and announce withname
. Announcements will be removed when the service is closed. Omitting theaddr
will bind to an ephemeral port.- Definition Classes
- Server
- def serveIface(addr: SocketAddress, iface: AnyRef): ListeningServer
Serve the interface implementation
iface
, which must be generated by either Scrooge or thrift-finagle.Serve the interface implementation
iface
, which must be generated by either Scrooge or thrift-finagle.Given the IDL:
service TestService { string query(1: string x) }
Scrooge will generate an interface,
TestService.MethodPerEndpoint
, implementing the above IDL.TestService.MethodPerEndpoint
must be implemented and passed intoserveIface
:ThriftMuxRichServer .serveIface(":*", new TestService.MethodPerEndpoint { def query(x: String) = Future.value(x) // (echo service) })
Note that this interface is discovered by reflection. Passing an invalid interface implementation will result in a runtime error.
- Definition Classes
- ThriftRichServer
- def serveIface(addr: String, iface: AnyRef): ListeningServer
Serve the interface implementation
iface
, which must be generated by either Scrooge or thrift-finagle.Serve the interface implementation
iface
, which must be generated by either Scrooge or thrift-finagle.Given the IDL:
service TestService { string query(1: string x) }
Scrooge will generate an interface,
TestService.MethodPerEndpoint
, implementing the above IDL.TestService.MethodPerEndpoint
must be implemented and passed intoserveIface
:ThriftMuxRichServer .serveIface(":*", new TestService.MethodPerEndpoint { def query(x: String) = Future.value(x) // (echo service) })
Note that this interface is discovered by reflection. Passing an invalid interface implementation will result in a runtime error.
- Definition Classes
- ThriftRichServer
- def serveIfaces(addr: SocketAddress, ifaces: Map[String, AnyRef], defaultService: Option[String]): ListeningServer
Serve multiple interfaces:
Serve multiple interfaces:
val serviceMap = Map( "echo" -> new EchoService(), "extendedEcho" -> new ExtendedEchoService() ) val server = Thrift.server.serveIfaces(address, serviceMap)
A default service name can be specified, so we can upgrade an existing non-multiplexed server to a multiplexed one without breaking the old clients:
val server = Thrift.server.serveIfaces( address, serviceMap, defaultService = Some("extendedEcho"))
- Definition Classes
- ThriftRichServer
- def serveIfaces(addr: SocketAddress, ifaces: Map[String, AnyRef]): ListeningServer
Serve multiple interfaces:
Serve multiple interfaces:
val serviceMap = Map( "echo" -> new EchoService(), "extendedEcho" -> new ExtendedEchoService() ) val server = Thrift.server.serveIfaces(address, serviceMap)
A default service name can be specified, so we can upgrade an existing non-multiplexed server to a multiplexed one without breaking the old clients:
val server = Thrift.server.serveIfaces( address, serviceMap, defaultService = Some("extendedEcho"))
- Definition Classes
- ThriftRichServer
- def serveIfaces(addr: String, ifaces: Map[String, AnyRef], defaultService: Option[String] = None): ListeningServer
Serve multiple interfaces:
Serve multiple interfaces:
val serviceMap = Map( "echo" -> new EchoService(), "extendedEcho" -> new ExtendedEchoService() ) val server = Thrift.server.serveIfaces(address, serviceMap)
A default service name can be specified, so we can upgrade an existing non-multiplexed server to a multiplexed one without breaking the old clients:
val server = Thrift.server.serveIfaces( address, serviceMap, defaultService = Some("extendedEcho"))
- Definition Classes
- ThriftRichServer
- def serverLabel: String
- Attributes
- protected
- Definition Classes
- ThriftRichServer
- val serverParam: RichServerParam
- Attributes
- protected[twitter]
- Definition Classes
- Server → ThriftRichServer
- def serverStats: StatsReceiver
- Attributes
- protected
- Definition Classes
- ThriftRichServer
- def stack: Stack[ServiceFactory[Request, Response]]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def transformed(t: Transformer): Server
Transform the stack using the given
Transformer
.Transform the stack using the given
Transformer
.- Definition Classes
- Server → Transformable
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- val withAdmissionControl: ServerAdmissionControlParams[Server]
An entry point for configuring the servers' admission control.
An entry point for configuring the servers' admission control.
- Definition Classes
- Server → WithServerAdmissionControl
- val withCompressionPreferences: CompressionParams[Server]
An entry point for configuring the client or server's compression.
An entry point for configuring the client or server's compression.
- Definition Classes
- WithCompressionPreferences
- def withExceptionStatsHandler(exceptionStatsHandler: ExceptionStatsHandler): Server
Configures this server or client with given exception stats handler.
Configures this server or client with given exception stats handler.
- Definition Classes
- Server → CommonParams
- def withExecutionOffloaded(pool: FuturePool): Server
Configures this server or client to shift user-defined computation (com.twitter.util.Future callbacks and transformations) off of IO threads into a given FuturePool.
Configures this server or client to shift user-defined computation (com.twitter.util.Future callbacks and transformations) off of IO threads into a given FuturePool.
By default, Finagle executes all futures in the IO threads, minimizing context switches. Given there is usually a fixed number of IO threads shared across a JVM process, it's critically important to ensure they aren't being blocked by the application code, affecting system's responsiveness. Shifting application-level work onto a dedicated FuturePool or ExecutorService offloads IO threads, which may improve throughput in CPU-bound systems.
As always, run your own tests before enabling this feature.
- Definition Classes
- Server → CommonParams
- def withExecutionOffloaded(executor: ExecutorService): Server
Configures this server or client to shift user-defined computation (com.twitter.util.Future callbacks and transformations) off of IO threads into a given ExecutorService.
Configures this server or client to shift user-defined computation (com.twitter.util.Future callbacks and transformations) off of IO threads into a given ExecutorService.
By default, Finagle executes all futures in the IO threads, minimizing context switches. Given there is usually a fixed number of IO threads shared across a JVM process, it's critically important to ensure they aren't being blocked by the application code, affecting system's responsiveness. Shifting application-level work onto a dedicated FuturePool or ExecutorService offloads IO threads, which may improve throughput in CPU-bound systems.
As always, run your own tests before enabling this feature.
- Definition Classes
- Server → CommonParams
- def withLabel(label: String): Server
Configures this server or client with given
label
(default: empty string).Configures this server or client with given
label
(default: empty string).The
label
value is used for stats reporting to scope stats reported from different clients/servers to a single stats receiver.- Definition Classes
- Server → CommonParams
- def withLabels(keywords: String*): Server
- Definition Classes
- CommonParams
- def withMaxReusableBufferSize(size: Int): Server
Produce a com.twitter.finagle.ThriftMux.Server with the specified max size of the reusable buffer for thrift responses.
Produce a com.twitter.finagle.ThriftMux.Server with the specified max size of the reusable buffer for thrift responses. If this size is exceeded, the buffer is not reused and a new buffer is allocated for the next thrift response. The default max size is 16Kb.
- size
Max size of the reusable buffer for thrift responses in bytes.
- def withMonitor(monitor: Monitor): Server
Configures this server or client with given util.Monitor (default: com.twitter.finagle.util.NullMonitor).
Configures this server or client with given util.Monitor (default: com.twitter.finagle.util.NullMonitor).
Monitors are Finagle's out-of-band exception reporters. Whenever an exception is thrown on a request path, it's reported to the monitor. The configured
Monitor
is composed (see below for how composition works) with the default monitor implementation, com.twitter.finagle.util.DefaultMonitor, which logs these exceptions.Monitors are wired into the server or client stacks via com.twitter.finagle.filter.MonitorFilter and are applied to the following kinds of exceptions:
- Synchronous exceptions thrown on request path,
Service.apply(request)
- Asynchronous exceptions (failed futures) thrown on request path,
Service.apply(request)
- Exceptions thrown from
respond
,onSuccess
,onFailure
future callbacks - Fatal exceptions thrown from
map
,flatMap
,transform
future continuations
Put it this way, we apply
Monitor.handle
to an exception if we would otherwise "lose" it, i.e. when it's not connected to theFuture
, nor is it connected to the call stack.You can compose multiple monitors if you want to extend or override the standard behavior, defined in
DefaultMonitor
.import com.twitter.util.Monitor val consoleMonitor = new Monitor { def handle(exc: Throwable): Boolean = { Console.err.println(exc.toString) false // continue handling with the next monitor (usually DefaultMonitor) } } $.withMonitor(consoleMonitor)
Returning
true
form within a monitor effectively terminates the monitor chain so no exceptions are propagated down to the next monitor.- Definition Classes
- Server → CommonParams
- Synchronous exceptions thrown on request path,
- def withNoOpportunisticTls: Server
Disables opportunistic TLS.
Disables opportunistic TLS.
If this is still TLS configured, it will speak mux over TLS. To instead configure this to be
Off
, usewithOpportunisticTls(OpportunisticTls.Off)
.- Definition Classes
- Server → OpportunisticTlsParams
- def withOpportunisticTls(level: Level): Server
Configures whether to speak TLS or not.
Configures whether to speak TLS or not.
By default, don't use opportunistic TLS, and instead try to speak mux over TLS if TLS has been configured.
The valid levels are Off, which indicates this will never speak TLS, Desired, which indicates it may speak TLS, but may also not speak TLS, and Required, which indicates it must speak TLS.
Peers that are configured with level
Required
cannot speak to peers that are configured with levelOff
.Note that opportunistic TLS is negotiated in a cleartext handshake, and is incompatible with mux over TLS.
- Definition Classes
- Server → OpportunisticTlsParams
- def withParams(ps: Params): Server
- Definition Classes
- Server → Parameterized
- def withPerEndpointStats: Server
Produce a com.twitter.finagle.ThriftMux.Server with per-endpoint stats filters
- def withProtocolFactory(pf: TProtocolFactory): Server
Produce a com.twitter.finagle.ThriftMux.Server using the provided
TProtocolFactory
. - def withRequestTimeout(timeout: Duration): Server
Configures the request
timeout
of this server or client (default: unbounded).Configures the request
timeout
of this server or client (default: unbounded).If the request has not completed within the given
timeout
, the pending work will be interrupted via com.twitter.util.Future.raise.Client's Request Timeout
The client request timeout is the maximum amount of time given to a single request (if there are retries, they each get a fresh request timeout). The timeout is applied only after a connection has been acquired. That is: it is applied to the interval between the dispatch of the request and the receipt of the response.
Server's Request Timeout
The server request timeout is the maximum amount of time, a server is allowed to spend handling the incoming request. Using the Finagle terminology, this is an amount of time after which a non-satisfied future returned from the user-defined service times out.
- Definition Classes
- Server → CommonParams
- See also
https://twitter.github.io/finagle/guide/Clients.html#timeouts-expiration
- def withRequestTimeout(timeout: Tunable[Duration]): Server
Configures the Tunable request
timeout
of this server or client (if applying the Tunable produces a value ofNone
, an unbounded timeout is used for the request).Configures the Tunable request
timeout
of this server or client (if applying the Tunable produces a value ofNone
, an unbounded timeout is used for the request).If the request has not completed within the Duration resulting from
timeout.apply()
, the pending work will be interrupted via com.twitter.util.Future.raise.Client's Request Timeout
The client request timeout is the maximum amount of time given to a single request (if there are retries, they each get a fresh request timeout). The timeout is applied only after a connection has been acquired. That is: it is applied to the interval between the dispatch of the request and the receipt of the response.
Server's Request Timeout
The server request timeout is the maximum amount of time, a server is allowed to spend handling the incoming request. Using the Finagle terminology, this is an amount of time after which a non-satisfied future returned from the user-defined service times out.
- def withResponseClassifier(responseClassifier: ResponseClassifier): Server
Configure a com.twitter.finagle.service.ResponseClassifier which is used to determine the result of a request/response.
Configure a com.twitter.finagle.service.ResponseClassifier which is used to determine the result of a request/response.
This allows developers to give Finagle the additional application-specific knowledge necessary in order to properly classify responses. Without this, Finagle cannot make judgements about application-level failures as it only has a narrow understanding of failures (for example: transport level, timeouts, and nacks).
As an example take an HTTP server that returns a response with a 500 status code. To Finagle this is a successful request/response. However, the application developer may want to treat all 500 status codes as failures and can do so via setting a com.twitter.finagle.service.ResponseClassifier.
ResponseClassifier is a PartialFunction and as such multiple classifiers can be composed together via PartialFunction.orElse.
Response classification is independently configured on the client and server. For client-side response classification using com.twitter.finagle.builder.ClientBuilder, see
com.twitter.finagle.builder.ClientBuilder.responseClassifier
- Definition Classes
- CommonParams
- Note
If unspecified, the default classifier is com.twitter.finagle.service.ResponseClassifier.Default which is a total function fully covering the input domain.
- See also
com.twitter.finagle.http.service.HttpResponseClassifier
for some HTTP classification tools.
- def withServiceClass(clazz: Class[_]): Server
Configure the service class that may be used with this server to collect instrumentation metadata.
Configure the service class that may be used with this server to collect instrumentation metadata. This is not necessary to run a service.
- Note
that when using the
.serveIface
methods this is unnecessary.
- val withSession: ServerSessionParams[Server]
An entry point for configuring the client's sessions.
An entry point for configuring the client's sessions.
Session might be viewed as logical connection that wraps a physical connection (i.e., transport) and controls its lifecycle. Sessions are used in Finagle to maintain liveness, requests cancellation, draining, and many more.
The default setup for a Finagle server's sessions is to not put any timeouts on it.
- Definition Classes
- Server → WithServerSession
- def withStack(fn: (Stack[ServiceFactory[Request, Response]]) => Stack[ServiceFactory[Request, Response]]): Server
- def withStack(stack: Stack[ServiceFactory[Request, Response]]): Server
Produce a com.twitter.finagle.ThriftMux.Server using the provided stack.
- def withStatsReceiver(statsReceiver: StatsReceiver): Server
Configures this server or client with given stats.StatsReceiver (default: stats.DefaultStatsReceiver).
Configures this server or client with given stats.StatsReceiver (default: stats.DefaultStatsReceiver).
- Definition Classes
- Server → CommonParams
- def withTracer(tracer: Tracer): Server
Configures this server or client with given tracing.Tracer (default: com.twitter.finagle.tracing.DefaultTracer).
Configures this server or client with given tracing.Tracer (default: com.twitter.finagle.tracing.DefaultTracer).
- Definition Classes
- Server → CommonParams
- Note
if you supply com.twitter.finagle.tracing.NullTracer, no trace information will be written, but this does not disable Finagle from propagating trace information. Instead, if traces are being aggregated across your fleet, it will orphan subsequent spans.
- val withTransport: ServerTransportParams[Server]
An entry point for configuring servers' com.twitter.finagle.transport.Transport.
An entry point for configuring servers' com.twitter.finagle.transport.Transport.
Transport
is a Finagle abstraction over the network connection (i.e., a TCP connection).- Definition Classes
- Server → WithServerTransport