Hello,
  I'm working on a client-side application atop tcp streams, and I'm 
curious what is the recommended approach for handling reconnects. I'm 
thinking to wrap the underlying transport flow in an AsyncStage, and then 
rematerialize the transport on completion. It would look something like 
this:

class ReconnectionStage[In, Out](transport: Flow[In, Out, Any], 
maxInFlight: Int) extends AsyncStage[In, Out, Any] {
  private var inFlight = 0
  private val buffer = FixedSizeBuffer[Out](maxInFlight)

  private var fm: FlowMaterializer = _
  private var callback: AsyncCallback[Any] = _
  private var runnableFlow: RunnableFlow[(ActorRef, Future[Unit])] = _

  private var input: ActorRef = _

  private def connect() {
    val (ref, future) = runnableFlow.run()(fm)
    input = ref
    future.onComplete( _ => callback.invoke(Reconnect))(fm.executionContext)
  }
  
  override def preStart(ctx: AsyncContext[Out, Any]) {
    fm = ctx.materializer
    callback = ctx.getAsyncCallback()
    runnableFlow = Source.actorRef(maxInFlight, OverflowStrategy.fail)
      .via(transport).toMat(Sink.foreach(callback.invoke))(Keep.both)
  }
  ...
}

It's a bit involved, and I haven't yet finished -- so I guess I'm just here 
to check if I'm even on the right track :)

Cheers,
Peter

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to