Permalink
Browse files

privacy annotations for finagle-core

  • Loading branch information...
1 parent 5874ce1 commit 6d8fc6ab2e9392e946e2069617083e1690812ae4 Nick Kallen committed Mar 21, 2011
Showing with 118 additions and 216 deletions.
  1. +28 −19 finagle-core/src/main/scala/com/twitter/finagle/builder/ClientBuilder.scala
  2. +0 −2 finagle-core/src/main/scala/com/twitter/finagle/builder/Common.scala
  3. +27 −19 finagle-core/src/main/scala/com/twitter/finagle/builder/ServerBuilder.scala
  4. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/channel/ChannelClosingHandler.scala
  5. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/channel/ChannelRequestStatsHandler.scala
  6. +2 −2 finagle-core/src/main/scala/com/twitter/finagle/channel/ChannelService.scala
  7. +2 −2 finagle-core/src/main/scala/com/twitter/finagle/channel/ConnectionLifecycleHandler.scala
  8. +6 −7 finagle-core/src/main/scala/com/twitter/finagle/channel/ServiceToChannelHandler.scala
  9. +7 −9 finagle-core/src/main/scala/com/twitter/finagle/channel/WriteCompletionTimeoutHandler.scala
  10. +8 −14 finagle-core/src/main/scala/com/twitter/finagle/http/AggregateHttpRequest.scala
  11. +1 −4 finagle-core/src/main/scala/com/twitter/finagle/http/ClientConnectionManager.scala
  12. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/http/ConnectionManager.scala
  13. +1 −3 finagle-core/src/main/scala/com/twitter/finagle/http/ServerConnectionManager.scala
  14. +10 −10 finagle-core/src/main/scala/com/twitter/finagle/service/ExpiringService.scala
  15. +0 −4 finagle-core/src/main/scala/com/twitter/finagle/service/FailureAccrualFactory.scala
  16. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/service/RefcountedService.scala
  17. +0 −1 finagle-core/src/main/scala/com/twitter/finagle/service/RetryingFilter.scala
  18. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/service/SingletonFactory.scala
  19. +7 −7 finagle-core/src/main/scala/com/twitter/finagle/stats/CumulativeGauge.scala
  20. +0 −33 finagle-core/src/main/scala/com/twitter/finagle/test/HttpClient.scala
  21. +0 −35 finagle-core/src/main/scala/com/twitter/finagle/test/HttpServer.scala
  22. +0 −15 finagle-core/src/main/scala/com/twitter/finagle/tracing/Trace.scala
  23. +7 −7 finagle-core/src/main/scala/com/twitter/finagle/util/ChannelFuture.scala
  24. +0 −1 finagle-core/src/main/scala/com/twitter/finagle/util/ChannelSnooper.scala
  25. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/util/Conversions.scala
  26. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/util/InetSocketAddressUtil.scala
  27. +0 −4 finagle-core/src/main/scala/com/twitter/finagle/util/ReferenceCountedTimer.scala
  28. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/util/RichFuture.scala
  29. +1 −1 finagle-core/src/main/scala/com/twitter/finagle/util/Timer.scala
  30. +3 −9 finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ThriftServerFramedCodec.scala
@@ -34,30 +34,32 @@ object ClientBuilder {
}
/**
- * A word about the default values:
+ * A handy way to construct an RPC Client.
+ *
+ * ''Note'': A word about the default values:
*
* o connectionTimeout: optimized for within a datanceter
* o by default, no request timeout
*/
case class ClientBuilder[Req, Rep](
- _cluster: Option[Cluster],
- _protocol: Option[Protocol[Req, Rep]],
- _connectionTimeout: Duration,
- _requestTimeout: Duration,
- _statsReceiver: Option[StatsReceiver],
- _loadStatistics: (Int, Duration),
- _name: Option[String],
- _hostConnectionCoresize: Option[Int],
- _hostConnectionLimit: Option[Int],
- _hostConnectionIdleTime: Option[Duration],
- _hostConnectionMaxIdleTime: Option[Duration],
- _sendBufferSize: Option[Int],
- _recvBufferSize: Option[Int],
- _retries: Option[Int],
- _logger: Option[Logger],
- _channelFactory: Option[ReferenceCountedChannelFactory],
- _tls: Option[SSLContext],
- _startTls: Boolean)
+ private val _cluster: Option[Cluster],
+ private val _protocol: Option[Protocol[Req, Rep]],
+ private val _connectionTimeout: Duration,
+ private val _requestTimeout: Duration,
+ private val _statsReceiver: Option[StatsReceiver],
+ private val _loadStatistics: (Int, Duration),
+ private val _name: Option[String],
+ private val _hostConnectionCoresize: Option[Int],
+ private val _hostConnectionLimit: Option[Int],
+ private val _hostConnectionIdleTime: Option[Duration],
+ private val _hostConnectionMaxIdleTime: Option[Duration],
+ private val _sendBufferSize: Option[Int],
+ private val _recvBufferSize: Option[Int],
+ private val _retries: Option[Int],
+ private val _logger: Option[Logger],
+ private val _channelFactory: Option[ReferenceCountedChannelFactory],
+ private val _tls: Option[SSLContext],
+ private val _startTls: Boolean)
{
def this() = this(
None, // cluster
@@ -251,6 +253,10 @@ case class ClientBuilder[Req, Rep](
future
}
+ /**
+ * Construct a ServiceFactory. This is useful for stateful protocols (e.g.,
+ * those that support transactions or authentication).
+ */
def buildFactory(): ServiceFactory[Req, Rep] = {
if (!_cluster.isDefined)
throw new IncompleteSpecification("No hosts were specified")
@@ -308,6 +314,9 @@ case class ClientBuilder[Req, Rep](
}
}
+ /**
+ * Construct a Service.
+ */
def build(): Service[Req, Rep] = {
var service: Service[Req, Rep] = new FactoryToService[Req, Rep](buildFactory())
@@ -1,5 +1,3 @@
package com.twitter.finagle.builder
-import org.jboss.netty.channel.ChannelPipelineFactory
-
class IncompleteSpecification(message: String) extends Exception(message)
@@ -53,26 +53,26 @@ object ServerBuilder {
Executors.newCachedThreadPool())))
}
-// TODO: common superclass between client & server builders for common
-// concerns.
-
+/**
+ * A handy Builder for constructing Servers (i.e., binding Services to a port).
+ */
case class ServerBuilder[Req, Rep](
- _codec: Option[Codec[Req, Rep]],
- _statsReceiver: Option[StatsReceiver],
- _name: Option[String],
- _sendBufferSize: Option[Int],
- _recvBufferSize: Option[Int],
- _bindTo: Option[SocketAddress],
- _logger: Option[Logger],
- _tls: Option[(String, String)],
- _startTls: Boolean,
- _channelFactory: Option[ReferenceCountedChannelFactory],
- _maxConcurrentRequests: Option[Int],
- _hostConnectionMaxIdleTime: Option[Duration],
- _requestTimeout: Option[Duration],
- _readTimeout: Option[Duration],
- _writeCompletionTimeout: Option[Duration],
- _traceReceiver: TraceReceiver)
+ private val _codec: Option[Codec[Req, Rep]],
+ private val _statsReceiver: Option[StatsReceiver],
+ private val _name: Option[String],
+ private val _sendBufferSize: Option[Int],
+ private val _recvBufferSize: Option[Int],
+ private val _bindTo: Option[SocketAddress],
+ private val _logger: Option[Logger],
+ private val _tls: Option[(String, String)],
+ private val _startTls: Boolean,
+ private val _channelFactory: Option[ReferenceCountedChannelFactory],
+ private val _maxConcurrentRequests: Option[Int],
+ private val _hostConnectionMaxIdleTime: Option[Duration],
+ private val _requestTimeout: Option[Duration],
+ private val _readTimeout: Option[Duration],
+ private val _writeCompletionTimeout: Option[Duration],
+ private val _traceReceiver: TraceReceiver)
{
import ServerBuilder._
@@ -168,8 +168,16 @@ case class ServerBuilder[Req, Rep](
private[this] def scopedStatsReceiver =
_statsReceiver map { sr => _name map (sr.scope(_)) getOrElse sr }
+ /**
+ * Construct the Server, given the provided Service.
+ */
def build(service: Service[Req, Rep]): Server = build(() => service)
+ /**
+ * Construct the Server, given the provided ServiceFactory. This
+ * is useful if the protocol is stateful (e.g., requires authentication
+ * or supports transactions).
+ */
def build(serviceFactory: () => Service[Req, Rep]): Server = {
val codec = _codec.getOrElse {
throw new IncompleteSpecification("No codec was specified")
@@ -12,7 +12,7 @@ import org.jboss.netty.channel.{
import com.twitter.finagle.util.Conversions._
import com.twitter.finagle.util.LatentChannelFuture
-class ChannelClosingHandler
+private[finagle] class ChannelClosingHandler
extends SimpleChannelUpstreamHandler
with LifeCycleAwareChannelHandler
{
@@ -14,7 +14,7 @@ import org.jboss.netty.channel.{
import com.twitter.util.Future
import com.twitter.finagle.stats.StatsReceiver
-class ChannelRequestStatsHandler(statsReceiver: StatsReceiver)
+private[finagle] class ChannelRequestStatsHandler(statsReceiver: StatsReceiver)
extends SimpleChannelHandler
with ConnectionLifecycleHandler
{
@@ -19,7 +19,7 @@ import com.twitter.finagle.util.{Ok, Error, Cancelled, AsyncLatch}
* channel. It is responsible for requests dispatched to a given
* (connected) channel during its lifetime.
*/
-class ChannelService[Req, Rep](channel: Channel, factory: ChannelServiceFactory[Req, Rep])
+private[finagle] class ChannelService[Req, Rep](channel: Channel, factory: ChannelServiceFactory[Req, Rep])
extends Service[Req, Rep]
{
private[this] val currentReplyFuture = new AtomicReference[Promise[Rep]]
@@ -88,7 +88,7 @@ class ChannelService[Req, Rep](channel: Channel, factory: ChannelServiceFactory[
/**
* A factory for ChannelService instances, given a bootstrap.
*/
-class ChannelServiceFactory[Req, Rep](
+private[finagle] class ChannelServiceFactory[Req, Rep](
bootstrap: ClientBootstrap,
prepareChannel: Service[Req, Rep] => Future[Service[Req, Rep]],
statsReceiver: StatsReceiver = NullStatsReceiver)
@@ -2,13 +2,13 @@ package com.twitter.finagle.channel
import org.jboss.netty.channel.{
SimpleChannelHandler, LifeCycleAwareChannelHandler,
- Channel, ChannelHandlerContext, ChannelStateEvent}
+ ChannelHandlerContext, ChannelStateEvent}
import com.twitter.util.{Future, Promise, Return}
import com.twitter.finagle.util.Conversions._
-trait ConnectionLifecycleHandler
+private[finagle] trait ConnectionLifecycleHandler
extends SimpleChannelHandler
with LifeCycleAwareChannelHandler
{
@@ -10,11 +10,10 @@ import org.jboss.netty.handler.timeout.ReadTimeoutException
import com.twitter.util.{Future, Promise, Return, Throw}
import com.twitter.finagle.util.Conversions._
-import com.twitter.finagle.util.AsyncLatch
import com.twitter.finagle.stats.{StatsReceiver, NullStatsReceiver}
import com.twitter.finagle.{CodecException, Service, WriteTimedOutException}
-class ServiceToChannelHandler[Req, Rep](
+private[finagle] class ServiceToChannelHandler[Req, Rep](
service: Service[Req, Rep],
statsReceiver: StatsReceiver,
log: Logger)
@@ -25,7 +24,7 @@ class ServiceToChannelHandler[Req, Rep](
def this(service: Service[Req, Rep]) =
this(service, NullStatsReceiver)
- private[this] sealed trait State
+ private[this] sealed abstract class State
// valid transitions are:
//
@@ -46,15 +45,15 @@ class ServiceToChannelHandler[Req, Rep](
service.release()
}
- /**
+ /**
* onShutdown: this Future is satisfied when the channel has been
* closed.
- */
+ */
val onShutdown: Future[Unit] = onShutdownPromise
- /**
+ /**
* drain(): admit no new requests.
- */
+ */
def drain() = {
var continue = false
do {
@@ -1,23 +1,21 @@
package com.twitter.finagle.channel
-/**
- * A simple handler that times out a write if it fails to complete
- * within the given time. This can be used to ensure that clients
- * complete reception within a certain time, preventing a resource DoS
- * on a server.
- */
-
import org.jboss.netty.channel.{
SimpleChannelDownstreamHandler, Channels,
ChannelHandlerContext, MessageEvent}
import com.twitter.util.{Time, Duration, Timer}
-import com.twitter.conversions.time._
import com.twitter.finagle.util.Conversions._
import com.twitter.finagle.WriteTimedOutException
-class WriteCompletionTimeoutHandler(timer: Timer, timeout: Duration)
+/**
+ * A simple handler that times out a write if it fails to complete
+ * within the given time. This can be used to ensure that clients
+ * complete reception within a certain time, preventing a resource DoS
+ * on a server.
+ */
+private[finagle] class WriteCompletionTimeoutHandler(timer: Timer, timeout: Duration)
extends SimpleChannelDownstreamHandler
{
override def writeRequested(ctx: ChannelHandlerContext, e: MessageEvent) {
@@ -6,44 +6,38 @@ package com.twitter.finagle.http
import scala.collection.JavaConversions._
-import java.nio.ByteOrder
-
import org.jboss.netty.channel.{
- MessageEvent, Channels,
- SimpleChannelUpstreamHandler,
- ChannelHandlerContext}
+ MessageEvent, Channels, ChannelHandlerContext}
import org.jboss.netty.handler.codec.http.{
HttpHeaders, HttpRequest,
- HttpResponse, HttpChunk,
- DefaultHttpResponse,
+ HttpChunk, DefaultHttpResponse,
HttpVersion, HttpResponseStatus}
import org.jboss.netty.buffer.{
- ChannelBuffer, ChannelBuffers,
- CompositeChannelBuffer}
+ ChannelBuffer, ChannelBuffers}
import com.twitter.finagle.util.Conversions._
import com.twitter.finagle.channel.LeftFoldUpstreamHandler
-object OneHundredContinueResponse
+private[finagle] object OneHundredContinueResponse
extends DefaultHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.CONTINUE)
-class HttpFailure(ctx: ChannelHandlerContext, status: HttpResponseStatus)
+private[finagle] class HttpFailure(ctx: ChannelHandlerContext, status: HttpResponseStatus)
extends LeftFoldUpstreamHandler
{
{
val response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status)
val future = Channels.future(ctx.getChannel)
- Channels.write(ctx, future, response, ctx.getChannel.getRemoteAddress)
+ Channels.write(ctx, future, response, ctx.getChannel.getRemoteAddress)
future onSuccessOrFailure { ctx.getChannel.close() }
}
override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) =
this // (swallow the message)
}
-case class AggregateHttpChunks(
+private[finagle] case class AggregateHttpChunks(
whenDone: LeftFoldUpstreamHandler,
request: HttpRequest,
bufferBudget: Int,
@@ -85,7 +79,7 @@ case class AggregateHttpChunks(
}
}
-class AggregateHttpRequest(maxBufferSize: Int)
+private[finagle] class AggregateHttpRequest(maxBufferSize: Int)
extends LeftFoldUpstreamHandler
{
override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) =
@@ -1,11 +1,8 @@
package com.twitter.finagle.http
import org.jboss.netty.channel._
-import org.jboss.netty.handler.codec.http._
-import com.twitter.finagle.util.Conversions._
-
-class ClientConnectionManager extends SimpleChannelHandler {
+private[finagle] class ClientConnectionManager extends SimpleChannelHandler {
private[this] val manager = new ConnectionManager
// Note that for HTTP requests without a content length, the
@@ -8,7 +8,7 @@ package com.twitter.finagle.http
import org.jboss.netty.handler.codec.http._
-class ConnectionManager {
+private[finagle] class ConnectionManager {
private[this] var isKeepAlive = false
private[this] var isIdle = true
@@ -1,8 +1,6 @@
package com.twitter.finagle.http
import org.jboss.netty.channel._
-import org.jboss.netty.handler.codec.http._
-
import com.twitter.finagle.util.Conversions._
/**
@@ -20,7 +18,7 @@ import com.twitter.finagle.util.Conversions._
// the Connection header, that request becomes the last one for the
// connection."
-class ServerConnectionManager extends SimpleChannelHandler {
+private[finagle] class ServerConnectionManager extends SimpleChannelHandler {
private[this] val manager = new ConnectionManager
override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
Oops, something went wrong.

0 comments on commit 6d8fc6a

Please sign in to comment.