@Override
public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) throws Exception {
if (evt instanceof IdleStateHandlerTomP2P) {
LOG.warn("channel timeout for channel {} {}", name, ctx.channel());
final PeerAddress recipient;
if (futureResponse != null) {
LOG.warn("Request status is {}", futureResponse.request());
ctx.channel().close().addListener(new GenericFutureListener<ChannelFuture>() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
futureResponse.failed("channel is idle " + evt);
}
});
recipient = futureResponse.request().recipient();
} else {
ctx.close();
// check if we have set an attribute at least (if we have
// already decoded the header)
final Attribute<PeerAddress> pa = ctx.attr(Decoder.PEER_ADDRESS_KEY);
recipient = pa.get();
}
if (peerStatusListeners == null) {
return;
}
synchronized (peerStatusListeners) {
for (PeerStatusListener peerStatusListener : peerStatusListeners) {
if (recipient != null) {
peerStatusListener.peerFailed(recipient, new PeerException(AbortCause.TIMEOUT, "timeout!"));
} else {
InetSocketAddress inetSocketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
if (inetSocketAddress == null) {
final Attribute<InetSocketAddress> pa = ctx.attr(Decoder.INET_ADDRESS_KEY);
inetSocketAddress = pa.get();
}
if (inetSocketAddress != null) {
peerStatusListener.peerFailed(
new PeerAddress(Number160.ZERO, inetSocketAddress.getAddress()),
new PeerException(AbortCause.TIMEOUT, "timeout!"));
} else {
LOG.warn("Cannot determine the address!");
}
}