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;
}
}
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;
}
}
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();
}
}
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;
}
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;
}
}
Aggregations