use of java.nio.channels.ClosedChannelException in project hbase by apache.
the class CallRunner method drop.
/**
* When we want to drop this call because of server is overloaded.
*/
public void drop() {
try {
if (call.disconnectSince() >= 0) {
if (RpcServer.LOG.isDebugEnabled()) {
RpcServer.LOG.debug(Thread.currentThread().getName() + ": skipped " + call);
}
return;
}
// Set the response
InetSocketAddress address = rpcServer.getListenerAddress();
call.setResponse(null, null, CALL_DROPPED_EXCEPTION, "Call dropped, server " + (address != null ? address : "(channel closed)") + " is overloaded, please retry.");
call.sendResponseIfReady();
} catch (ClosedChannelException cce) {
InetSocketAddress address = rpcServer.getListenerAddress();
RpcServer.LOG.warn(Thread.currentThread().getName() + ": caught a ClosedChannelException, " + "this means that the server " + (address != null ? address : "(channel closed)") + " was processing a request but the client went away. The error message was: " + cce.getMessage());
} catch (Exception e) {
RpcServer.LOG.warn(Thread.currentThread().getName() + ": caught: " + StringUtils.stringifyException(e));
} finally {
if (!sucessful) {
this.rpcServer.addCallSize(call.getSize() * -1);
}
cleanup();
}
}
use of java.nio.channels.ClosedChannelException in project NabAlive by jcheype.
the class HttpApiServerHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
if (e.getCause() instanceof ClosedChannelException) {
return;
}
String errorid = UUID.randomUUID().toString();
logger.error("ERROR HTTP: {}\n", errorid, e.getCause());
HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
httpResponse.setHeader("id", errorid);
if (logger.isDebugEnabled()) {
ChannelBuffer channelBuffer = ChannelBuffers.dynamicBuffer();
PrintWriter printWriter = new PrintWriter(new ChannelBufferOutputStream(channelBuffer));
e.getCause().printStackTrace(printWriter);
printWriter.close();
httpResponse.setContent(channelBuffer);
}
ctx.getChannel().write(httpResponse).addListener(ChannelFutureListener.CLOSE);
Channel ch = e.getChannel();
ch.close();
}
use of java.nio.channels.ClosedChannelException in project Openfire by igniterealtime.
the class MemberReceiver method register.
public SelectionKey register(Selector selector) throws IOException {
try {
selectionKey = datagramChannel.register(selector, SelectionKey.OP_READ);
} catch (ClosedChannelException e) {
callHandler.cancelRequest("register failed, channel closed!");
throw new IOException("register failed, channel closed!");
} catch (Exception e) {
Logger.println("register exception! " + e.getMessage());
throw new IOException("register exception! " + e.getMessage());
}
datagramChannelRegistered = true;
selectionKey.attach(this);
return selectionKey;
}
use of java.nio.channels.ClosedChannelException in project hs4j by killme2008.
the class AbstractNioSession method flush0.
protected final void flush0() {
SelectionKey tmpKey = null;
Selector writeSelector = null;
int attempts = 0;
try {
while (true) {
if (writeSelector == null) {
writeSelector = SelectorFactory.getSelector();
if (writeSelector == null) {
return;
}
tmpKey = selectableChannel.register(writeSelector, SelectionKey.OP_WRITE);
}
if (writeSelector.select(1000) == 0) {
attempts++;
if (attempts > 2) {
return;
}
} else {
break;
}
}
onWrite(selectableChannel.keyFor(writeSelector));
} catch (ClosedChannelException cce) {
onException(cce);
log.error("Flush error", cce);
close();
} catch (IOException ioe) {
onException(ioe);
log.error("Flush error", ioe);
close();
} finally {
if (tmpKey != null) {
// Cancel the key.
tmpKey.cancel();
tmpKey = null;
}
if (writeSelector != null) {
try {
writeSelector.selectNow();
} catch (IOException e) {
log.error("Temp selector selectNow error", e);
}
// return selector
SelectorFactory.returnSelector(writeSelector);
}
}
}
use of java.nio.channels.ClosedChannelException in project hadoop by apache.
the class TestSerializedExceptionPBImpl method testDeserializeWithDefaultConstructor.
@Test
public void testDeserializeWithDefaultConstructor() {
// Init SerializedException with an Exception with default constructor.
ClosedChannelException ex = new ClosedChannelException();
SerializedExceptionPBImpl pb = new SerializedExceptionPBImpl();
pb.init(ex);
Assert.assertEquals(ex.getClass(), pb.deSerialize().getClass());
}
Aggregations