Permalink
Browse files

publish example project

  • Loading branch information...
1 parent 7d1cc36 commit a98b0bef1cef37a9b63ddec5967888adc3b3c9fd Nick Kallen committed Feb 22, 2011
View
12 finagle-core/src/main/scala/com/twitter/finagle/builder/ChannelFactory.scala
@@ -43,8 +43,18 @@ class LazyRevivableChannelFactory(make: () => ChannelFactory)
}
def releaseExternalResources() = synchronized {
+ var thread: Thread = null
+
if (underlying ne null) {
- underlying.releaseExternalResources()
+ // releaseExternalResources must be called in a non-Netty
+ // thread, otherwise it can lead to a deadlock.
+ val _underlying = underlying
+ thread = new Thread {
+ override def run = {
+ _underlying.releaseExternalResources()
+ }
+ }
+ thread.start()
underlying = null
}
}
View
6 finagle-core/src/main/scala/com/twitter/finagle/pool/CachingPool.scala
@@ -12,9 +12,9 @@ import com.twitter.finagle.util.Timer
* the given timeout amount of time.
*/
class CachingPool[Req, Rep](
- factory: ServiceFactory[Req, Rep],
- timeout: Duration,
- timer: com.twitter.util.Timer = Timer.default)
+ factory: ServiceFactory[Req, Rep],
+ timeout: Duration,
+ timer: com.twitter.util.Timer = Timer.default)
extends ServiceFactory[Req, Rep]
{
private[this] val deathRow = Queue[(Time, Service[Req, Rep])]()
View
4 finagle-example/src/main/scala/com/twitter/finagle/example/echo/EchoClient.scala
@@ -11,13 +11,13 @@ object EchoClient {
.build()
// Issue request:
- client("hi mom\n") onSuccess { result =>
+ val result = client("hi mom\n")
+ result onSuccess { result =>
println("Received result: " + result)
} onFailure { error =>
error.printStackTrace()
} ensure {
// All done! Close TCP connection:
- println("releasin")
client.release()
}
}
View
16 finagle-stream/src/main/scala/com/twitter/finagle/stream/ChannelToHttpChunk.scala
@@ -6,7 +6,7 @@ import org.jboss.netty.channel._
import java.util.concurrent.atomic.{AtomicReference, AtomicBoolean}
import com.twitter.concurrent.Observer
import com.twitter.finagle.util.Conversions._
-import com.twitter.finagle.util.Ok
+import com.twitter.finagle.util.{Ok, Error}
import org.jboss.netty.util.CharsetUtil
/**
@@ -28,8 +28,11 @@ class ChannelToHttpChunk extends SimpleChannelDownstreamHandler {
case channel: com.twitter.concurrent.Channel[ChannelBuffer] =>
require(state.compareAndSet(Idle, Open), "Channel is already open or busy.")
- val startMessage = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
- HttpHeaders.setHeader(startMessage, "Transfer-Encoding", "Chunked")
+ val startMessage = {
+ val startMessage = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
+ HttpHeaders.setHeader(startMessage, "Transfer-Encoding", "Chunked")
+ startMessage
+ }
val startFuture = new DefaultChannelFuture(ctx.getChannel, false)
Channels.write(ctx, startFuture, startMessage)
@@ -43,13 +46,12 @@ class ChannelToHttpChunk extends SimpleChannelDownstreamHandler {
}
state.set(Observing(observer))
channel.closes.respond { _ =>
- val closeFuture = new DefaultChannelFuture(ctx.getChannel, false)
- val result = closeFuture.toTwitterFuture
+ val closeFuture = e.getFuture
state.set(Idle)
Channels.write(ctx, closeFuture, new DefaultHttpChunkTrailer)
- result
}
- case _ =>
+ case Error(f) =>
+ e.getFuture.setFailure(f)
}
case _ =>
View
2 project/build/Project.scala
@@ -130,7 +130,7 @@ class Project(info: ProjectInfo) extends StandardParentProject(info)
}
class ExampleProject(info: ProjectInfo) extends StandardProject(info)
- with AdhocInlines
+ with SubversionPublisher with AdhocInlines
class OstrichProject(info: ProjectInfo) extends StandardProject(info)
with SubversionPublisher with AdhocInlines

0 comments on commit a98b0be

Please sign in to comment.