[split] finagle-mux: Record tracing info when Mux is enabled

We'd like to be able to track Mux rollout across the fleet. Similar to
how we record tracing info for the version of Finagle being run, this
change adds server- and client-send tracing info for Mux.

RB_ID=341543
[split] finagle-core: add Stack#remove

RB_ID=346303
[split] bump scrooge-generator and scrooge-maven-plugin to 3.14.1

RB_ID=347161
TBR=true
[split] finagle-core: liberate Failure

RB_ID=347753
[split] finagle-example: Add Java Thrift client and server

While investigating a Java compatibility issue reported on the external
finaglers list [1], I wrote a Java Thrift client+server pair within
finagle-example. The code is equivalent to the Scala client+server in
finagle-example.

[1] https://groups.google.com/forum/#!topic/finaglers/W4hhEcAbocI

RB_ID=348329
[split] ss2: reduce the number of intermediate datastructures

 *	Only convert to sets at the very end of the pipeline;
 *	push filtering and path reconstruction down to the client by
	introducing ZooKeeperReader.glob

This reduces allocation by about 40% per change in large serversets.

RB_ID=345699
[split] finagle-core: Invert the `cancelOnHangup` value passed to MaskCancelFilter.Param

Problem
In a recent change that removed `StackServer.transformed`, we inverted
the interpretation of the boolean Param that configures whether or not to
include a MaskCancelFilter. Since this inversion was not reflected in
`ServerBuilder.cancelOnHangup`, we effectively inverted the cancellation
behavior of any services that use ServerBuilder.

Solution
Invert the boolean argument passed to `MaskCancelFilter.Param` in
`ServerBuilder.cancelOnHangup`.

RB_ID=349129
[split] finagle-mux: refactor Session to make closing a Session uniform

Problem

MuxSession.connect and MuxSession.listen both return a (Session => Session). This makes closing a session and the releasing of resources difficult and non-obvious. You can close either instance of Session to terminate the Session, but cleaning up resources within the other instance of Session is difficult.

Solution

Rename Session to MuxService, and add a new Session which dispatches received messages and is provided to both connectors and listeners. If you wish to terminate a Session, you call close on Session. This will call close on the instances of MuxService, and then close the transport. Session.client (an instance of MuxService) is used to send rpcs/messages/pings/drain to the other party.

Result

The new interface provides a single way to close a session and clean up resources within an instance of MuxService.

RB_ID=317129
[split] finagle-core: Implement ClientBuilder in terms of StackClient

Problem:

Decrease barrier to entry for mux (and thriftmux) by making it
possible to use from ClientBuilder. This requires that
protocol implementations can manipulate the entire client stack.

Solution:

The crux of the change is a new `stack` method in ClientBuilder that takes
a com.twitter.finagle.StackClient[Req, Rep]. The previous `codec` endpoints
now translate a com.twitter.finagle.Codec into a StackClient.

RB_ID=279239
[split] finagle-core: properly close sockets on shutdown

Problem:
A recent fix on the connection-draining logic exposed the fact that we
don't start draining connections until all the connections are closed in
Netty3Listener.

Solution:
Sequence the close operations correctly based on their underlying
behavior.

Results:
This fixes the problem, but a better solution would be to clarify
Netty3Listener's close API.  Filed CSL-933

RB_ID=349237
[split] ExceptionFilter does not set the response content-length header to 0.

Problem

The com.twitter.finagle.http.filter.ExceptionFilter class in finagle-http module calls response.clearContent() to
return an empty response but does not set the content-length header to 0.

AWS load balancers are sensitive to missing content-length headers and translate such responses to 502s (Bad gateway).

Solution

Content-Length header is set to 0 in ExceptionFilter class for both 499 and 500 responses.

Results

Content-length is correctly set on empty responses returned by ExceptionFilter.

Signed-off-by: Ruben Oanta <roanta@twitter.com>

RB_ID=350399
[split] Mux: reflect reality in specification

While implementing Mux in another context and language, I discovered
an inconsistency.

The Mux specification did not accurately reflect the implementation in
the description of message types. The specification is "correct" --
this was a silly bug -- but unfortunately it is too late to correct
without bumping the version number. So we'll wait.

In the meantime, we can at least create a definition which is
consistent, and compensate for corner cases in the implementation.
Once new clients and servers are out, we can remove the aliases
introduced here.

RB_ID=307247
[split] Revert "Mux: reflect reality in specification"

RB_ID=351993
TBR=true
NO-QUEUE=true
[split] finagle-mux: GC Avoidance primitives Problem GC Avoidance is a tricky problem, and requires a small set of tools so we can talk about it in sophisticated ways.

Result
We have a simple toolkit to build GC Avoidance on top of.

RB_ID=343361
[split] add Csv,Xls,Zip to finagle MediaType

RB_ID=351849
[split] Added additional tests for redis MOVE command.

Additional testing was requested for the finagle-redis MOVE command impl.
Added tests to the ClientSpec and the ClientServerSpec.

Signed-off-by: Ruben Oanta <roanta@twitter.com>

RB_ID=352831
[split] finagle-http: Adds tls support to finagle 6 apis Problem finagle 6 apis don't support TLS, significantly hampering adoption

Solution
Exploit Stack{Client,Server}Like to make the finagle 6 api configurable.

Result
finagle-http's finagle 6 api supports TLS

RB_ID=352107
[split] Add Thrift support to Kestrel MultiReader in Finagle-Kestrel

Problem
Currently MultiReader uses the Kestrel memcache protocol which does not support using a ClientId.  As a result users who want to use ClientIds with MultiReader-like functionality are tempted to roll their own MultiReader-like client side code.

Solution
 - Created ThriftConnectedClient which implements the same Client trait that the existing ConnectedClient class implements.
   - ThriftConnectedClient implements the Client trait with the help of the FinagledClient class (a kestrel client)
   - Due to differences in the protocols and how the underlying service is called (ConnectedClient calls Service[Req, Rep] directly while ThriftConnectedClient needs the FinagledClient wrapper) the common class has several type parameters
 - Refactored code shared by both ThriftConnectedClient and ConnectedClient into a separate class
 - Refactored code from ClusterMultiReaderBuilder into a generic class that can be used for both the existing and new builder classes.
 - Added a copy of kestrel.thrift within finagle-kestrel for a couple reasons:
   1. Avoid taking a dependency of a very old OSS Kestrel with itself depends on old versions of Finagle
   2. Not be blocked by the process of updating OSS Kestrel to match the internal version
   The copied thrift definition is compatible with both the OSS and internal Kestrel versions and provides all the functionality needed by MultiReader.
   The namespace for the copied kestrel.thrift is distinguished from the one in Kestrel in order to avoid conflicts.  The classes/methods are only used internally by finagle-kestrel so no one else should need to import/use the namespace.

 Result
 - MultiReaderThrift and MultiReaderMemcache replace MultiReader which is now deprecated
 - The Client object has a makeThrift method which serves as a Factory for ThriftConnectedClient
 - Existing usages of ConnectedClient do not require any changes; this includes maintaining a compatible version of ClusterMultiReaderBuilder and ClusterMultiReaderConfig

RB_ID=340985
[split] update ruby finagle-thrift generated sources

RB_ID=353683
[split] finagle-core, thrift, mux: Clean up contexts, delimit Locals

The current code that deals with com.twitter.util.Local and
com.twitter.finagle.Context confuses a number of issues.

First, contexts are designed to pass-through -- thus, they are not
useful for inheriting client ids; instead they must be set explicitly
by clients. This change fixes finagle-thrift to always ignore a
context-provided client id, replacing it instead with whatever is
passed in to the client.

Secondly, we make sure that all dispatchers delimit Locals properly.
Without this, it is possible to "leak" locals between requests. Consider
the following scenario, for a single server dispatcher instance:

	service(req)
		sets client ids in filter
		...
	service(req)
		does not set client id in a filter (e.g. it was not provided)
		client id now leaks

this is made worse by the fact that the TTwitter *client* set the
client id local. (Why, I'm not sure; this is also fixed by this
change.)

Finally, we ensure that ClientIdContext does not pass-through. While
we use contexts to propagate client ids, they should not be passed
from server to client since, by their current definition, they
identify the closest client.

RB_ID=314891