use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project alluxio by Alluxio.
the class RPCMessageIntegrationTest method beforeClass.
@BeforeClass
public static void beforeClass() {
sEventClient = new NioEventLoopGroup(1);
sEventServer = new NioEventLoopGroup(1);
sIncomingHandler = new MessageSavingHandler();
// Setup the server.
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(sEventServer);
bootstrap.channel(NioServerSocketChannel.class);
bootstrap.childHandler(new PipelineInitializer(sIncomingHandler));
InetSocketAddress address = new InetSocketAddress(NetworkAddressUtils.getLocalHostName(100), Integer.parseInt(PropertyKey.MASTER_RPC_PORT.getDefaultValue()));
ChannelFuture cf = bootstrap.bind(address).syncUninterruptibly();
sLocalAddress = cf.channel().localAddress();
// Setup the client.
sBootstrapClient = new Bootstrap();
sBootstrapClient.group(sEventClient);
sBootstrapClient.channel(NioSocketChannel.class);
sBootstrapClient.handler(new PipelineInitializer(new MessageSavingHandler()));
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project alluxio by Alluxio.
the class RPCMessageIntegrationTest method before.
@Before
public final void before() {
sIncomingHandler.reset();
// Connect to the server.
ChannelFuture cf = sBootstrapClient.connect(sLocalAddress).syncUninterruptibly();
mOutgoingChannel = cf.channel();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project alluxio by Alluxio.
the class BlockDataServerHandler method handleUnderFileSystemBlockReadRequest.
/**
* Handles a {@link RPCUnderFileSystemBlockReadRequest} by reading the data through a
* {@link BlockReader} provided by the block worker. This method assumes the data is available
* in the UFS returns an error status if the data is not available.
*
* @param ctx The context of this request which handles the result of this operation
* @param req The initiating {@link RPCBlockReadRequest}
* @throws IOException if an I/O error occurs when reading the data requested
*/
public void handleUnderFileSystemBlockReadRequest(final ChannelHandlerContext ctx, final RPCUnderFileSystemBlockReadRequest req) throws IOException {
final long blockId = req.getBlockId();
final long offset = req.getOffset();
final long len = req.getLength();
final long sessionId = req.getSessionId();
final boolean noCache = req.getNoCache();
try {
DataBuffer buffer = null;
req.validate();
BlockReader reader = mWorker.readUfsBlock(sessionId, blockId, offset, noCache);
ByteBuffer data = reader.read(offset, len);
if (data != null && data.remaining() > 0) {
buffer = new DataByteBuffer(data, data.remaining());
Metrics.BYTES_READ_UFS.inc(buffer.getLength());
}
RPCBlockReadResponse resp = new RPCBlockReadResponse(blockId, offset, data.remaining(), buffer, RPCResponse.Status.SUCCESS);
ChannelFuture future = ctx.writeAndFlush(resp);
if (buffer != null) {
future.addListener(new ReleasableResourceChannelListener(buffer));
}
LOG.debug("Preparation for responding to remote block request for: {} done.", blockId);
} catch (Exception e) {
LOG.error("Exception reading block {}", blockId, e);
RPCBlockReadResponse resp;
if (e instanceof BlockDoesNotExistException) {
resp = RPCBlockReadResponse.createErrorResponse(req, RPCResponse.Status.FILE_DNE);
} else {
resp = RPCBlockReadResponse.createErrorResponse(req, RPCResponse.Status.UFS_READ_FAILED);
}
ChannelFuture future = ctx.writeAndFlush(resp);
future.addListener(ChannelFutureListener.CLOSE);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project alluxio by Alluxio.
the class DataServerWriteHandler method replySuccess.
/**
* Writes a response to signify the success of the block write. Also resets the channel.
*
* @param channel the channel
*/
private void replySuccess(Channel channel) {
channel.writeAndFlush(RPCProtoMessage.createOkResponse(null)).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
reset();
}
});
if (!channel.config().isAutoRead()) {
channel.config().setAutoRead(true);
channel.read();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project alluxio by Alluxio.
the class UnderFileSystemDataServerHandler method handleFileWriteRequest.
/**
* Handles a {@link RPCFileWriteRequest} by writing the data through an output stream provided
* by the file worker. This method only allows appending data to the file and does not support
* writing at arbitrary offsets.
*
* @param ctx The context of this request which handles the result of this operation
* @param req The initiating {@link RPCFileWriteRequest}
* @throws IOException if an I/O error occurs when interacting with the UFS
*/
public void handleFileWriteRequest(ChannelHandlerContext ctx, RPCFileWriteRequest req) throws IOException {
long ufsFileId = req.getTempUfsFileId();
// Currently unused as only sequential write is supported
long offset = req.getOffset();
long length = req.getLength();
final DataBuffer data = req.getPayloadDataBuffer();
try {
OutputStream out = mWorker.getUfsOutputStream(ufsFileId);
// This channel will not be closed because the underlying stream should not be closed, the
// channel will be cleaned up when the underlying stream is closed.
WritableByteChannel channel = Channels.newChannel(out);
channel.write(data.getReadOnlyByteBuffer());
RPCFileWriteResponse resp = new RPCFileWriteResponse(ufsFileId, offset, length, RPCResponse.Status.SUCCESS);
ctx.writeAndFlush(resp);
} catch (Exception e) {
// TODO(peis): Fix this. The exception here should never be caused netty related issue.
LOG.error("Failed to write ufs file.", e);
RPCFileWriteResponse resp = RPCFileWriteResponse.createErrorResponse(req, RPCResponse.Status.UFS_WRITE_FAILED);
ChannelFuture future = ctx.writeAndFlush(resp);
future.addListener(ChannelFutureListener.CLOSE);
}
}
Aggregations