Search in sources :

Example 36 with ClosedChannelException

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();
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) InetSocketAddress(java.net.InetSocketAddress) ClosedChannelException(java.nio.channels.ClosedChannelException) TimeoutIOException(org.apache.hadoop.hbase.exceptions.TimeoutIOException) CallDroppedException(org.apache.hadoop.hbase.CallDroppedException)

Example 37 with ClosedChannelException

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();
}
Also used : ChannelBufferOutputStream(org.jboss.netty.buffer.ChannelBufferOutputStream) ClosedChannelException(java.nio.channels.ClosedChannelException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PrintWriter(java.io.PrintWriter)

Example 38 with ClosedChannelException

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;
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) SpeexException(com.sun.voip.SpeexException) SocketException(java.net.SocketException) NoSuchElementException(java.util.NoSuchElementException) ParseException(java.text.ParseException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 39 with ClosedChannelException

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);
        }
    }
}
Also used : SelectionKey(java.nio.channels.SelectionKey) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) Selector(java.nio.channels.Selector)

Example 40 with ClosedChannelException

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());
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) Test(org.junit.Test)

Aggregations

ClosedChannelException (java.nio.channels.ClosedChannelException)211 ByteBuffer (java.nio.ByteBuffer)67 IOException (java.io.IOException)60 Test (org.junit.Test)23 InetSocketAddress (java.net.InetSocketAddress)19 SelectionKey (java.nio.channels.SelectionKey)18 SocketChannel (java.nio.channels.SocketChannel)15 ArrayList (java.util.ArrayList)13 NotYetConnectedException (java.nio.channels.NotYetConnectedException)11 InterruptedIOException (java.io.InterruptedIOException)10 CancelledKeyException (java.nio.channels.CancelledKeyException)10 ShutdownCommand (com.cloud.agent.api.ShutdownCommand)9 File (java.io.File)9 ServerSocketChannel (java.nio.channels.ServerSocketChannel)9 PooledByteBuffer (io.undertow.connector.PooledByteBuffer)8 FileChannel (java.nio.channels.FileChannel)8 ConnectException (java.net.ConnectException)7 FsVolumeReference (org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeReference)6 AgentControlCommand (com.cloud.agent.api.AgentControlCommand)5 Command (com.cloud.agent.api.Command)5