All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wavesplatform.network.WriteErrorHandler.scala Maven / Gradle / Ivy

The newest version!
package com.wavesplatform.network

import java.nio.channels.ClosedChannelException

import com.wavesplatform.utils.ScorexLogging
import io.netty.channel.ChannelHandler.Sharable
import io.netty.channel._

@Sharable
class WriteErrorHandler extends ChannelOutboundHandlerAdapter with ScorexLogging {
  override def write(ctx: ChannelHandlerContext, msg: AnyRef, promise: ChannelPromise): Unit =
    ctx.write(
      msg,
      promise.unvoid().addListener { (chf: ChannelFuture) =>
        if (!chf.isSuccess) {
          chf.cause() match {
            case _: ClosedChannelException =>
              log.trace(s"${id(ctx.channel())} Channel closed while writing (${msg.getClass.getCanonicalName})")
            case _: java.io.IOException =>
              log.trace(s"java.io.IOException on ${id(ctx.channel())} Write failed (${msg.getClass.getCanonicalName})")
            case other =>
              log.debug(s"${id(ctx.channel())} Write failed (${msg.getClass.getCanonicalName})", other)
          }
        }
      }
    )
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy