Search in sources :

Example 46 with ClosedChannelException

use of java.nio.channels.ClosedChannelException in project netty by netty.

the class UnpooledUnsafeDirectByteBuf method setBytes.

@Override
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
    ensureAccessible();
    ByteBuffer tmpBuf = internalNioBuffer();
    tmpBuf.clear().position(index).limit(index + length);
    try {
        return in.read(tmpBuf);
    } catch (ClosedChannelException ignored) {
        return -1;
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) ByteBuffer(java.nio.ByteBuffer)

Example 47 with ClosedChannelException

use of java.nio.channels.ClosedChannelException in project netty by netty.

the class UnpooledDirectByteBuf method setBytes.

@Override
public int setBytes(int index, FileChannel in, long position, int length) throws IOException {
    ensureAccessible();
    ByteBuffer tmpBuf = internalNioBuffer();
    tmpBuf.clear().position(index).limit(index + length);
    try {
        return in.read(tmpNioBuf, position);
    } catch (ClosedChannelException ignored) {
        return -1;
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) ByteBuffer(java.nio.ByteBuffer)

Example 48 with ClosedChannelException

use of java.nio.channels.ClosedChannelException in project graphdb by neo4j-attic.

the class Client method sendRequest.

protected <R> Response<R> sendRequest(RequestType<M> type, SlaveContext context, Serializer serializer, Deserializer<R> deserializer) {
    Triplet<Channel, ChannelBuffer, ByteBuffer> channelContext = null;
    try {
        // Send 'em over the wire
        channelContext = getChannel();
        Channel channel = channelContext.first();
        channelContext.second().clear();
        ChunkingChannelBuffer chunkingBuffer = new ChunkingChannelBuffer(channelContext.second(), channel, Protocol.MAX_FRAME_LENGTH);
        chunkingBuffer.writeByte(type.id());
        writeContext(type, context, chunkingBuffer);
        serializer.write(chunkingBuffer, channelContext.third());
        chunkingBuffer.done();
        // Read the response
        @SuppressWarnings("unchecked") BlockingReadHandler<ChannelBuffer> reader = (BlockingReadHandler<ChannelBuffer>) channel.getPipeline().get("blockingHandler");
        final Triplet<Channel, ChannelBuffer, ByteBuffer> finalChannelContext = channelContext;
        DechunkingChannelBuffer dechunkingBuffer = new DechunkingChannelBuffer(reader, DEFAULT_READ_RESPONSE_TIMEOUT_SECONDS) {

            @Override
            protected ChannelBuffer readNext() {
                ChannelBuffer result = super.readNext();
                if (result == null) {
                    channelPool.dispose(finalChannelContext);
                    throw new ComException("Channel has been closed");
                }
                return result;
            }
        };
        R response = deserializer.read(dechunkingBuffer, channelContext.third());
        StoreId storeId = readStoreId(dechunkingBuffer, channelContext.third());
        if (shouldCheckStoreId(type)) {
            assertCorrectStoreId(storeId);
        }
        TransactionStream txStreams = readTransactionStreams(dechunkingBuffer);
        return new Response<R>(response, storeId, txStreams);
    } catch (ClosedChannelException e) {
        channelPool.dispose(channelContext);
        throw new ComException(e);
    } catch (IOException e) {
        throw new ComException(e);
    } catch (InterruptedException e) {
        throw new ComException(e);
    } catch (Exception e) {
        throw new ComException(e);
    } finally {
        releaseChannel();
    }
}
Also used : BlockingReadHandler(org.jboss.netty.handler.queue.BlockingReadHandler) ClosedChannelException(java.nio.channels.ClosedChannelException) Channel(org.jboss.netty.channel.Channel) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) StoreId(org.neo4j.kernel.impl.nioneo.store.StoreId)

Example 49 with ClosedChannelException

use of java.nio.channels.ClosedChannelException in project neo4j by neo4j.

the class PhysicalFlushableChannel method prepareForFlush.

/**
     * External synchronization between this method and close is required so that they aren't called concurrently.
     * Currently that's done by acquiring the PhysicalLogFile monitor.
     */
@Override
public Flushable prepareForFlush() throws IOException {
    buffer.flip();
    StoreChannel channel = this.channel;
    try {
        channel.writeAll(buffer);
    } catch (ClosedChannelException e) {
        handleClosedChannelException(e);
    }
    buffer.clear();
    return channel;
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) StoreChannel(org.neo4j.io.fs.StoreChannel)

Example 50 with ClosedChannelException

use of java.nio.channels.ClosedChannelException in project neo4j by neo4j.

the class SingleFilePageSwapper method write.

@Override
public long write(long filePageId, Page page) throws IOException {
    long fileOffset = pageIdToPosition(filePageId);
    increaseFileSizeTo(fileOffset + filePageSize);
    try {
        StoreChannel channel = channel(filePageId);
        return swapOut(page, fileOffset, channel);
    } catch (ClosedChannelException e) {
        // AsynchronousCloseException is a subclass of
        // ClosedChannelException, and ClosedByInterruptException is in
        // turn a subclass of AsynchronousCloseException.
        tryReopen(filePageId, e);
        boolean interrupted = Thread.interrupted();
        // Recurse because this is hopefully a very rare occurrence.
        long bytesWritten = write(filePageId, page);
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
        return bytesWritten;
    }
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) StoreChannel(org.neo4j.io.fs.StoreChannel)

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