request.setFuture(future);
// チャネルを通して送信
try {
// バッファを確保
OutputBuffer outputBuffer = new BasicOutputBuffer();
BSONEncoder encoder = new BSONEncoder();
encoder.set(outputBuffer);
// リクエスト内容を出力
writeRequest(request, encoder, outputBuffer);
// Safeリクエストの場合は、 getLastError クエリを付加
Request getLastError = null;
BSONObject query = request.getConsistency().getLastErrorQuery();
if (query != null) {
getLastError = new Query(
request.getDatabaseName(),
"$cmd",
0,
1,
query,
null
);
getLastError.setFuture(future);
writeRequest(getLastError, encoder, outputBuffer);
}
// ChannelBuffer を生成
ChannelBuffer channelBuffer = ChannelBuffers.buffer(outputBuffer.size());
outputBuffer.pipe(new ChannelBufferOutputStream(channelBuffer));
// ChannelFuture を取得し RequestFuture に設定
ChannelFuture channelFuture = e.getFuture();
future.setChannelFuture(channelFuture);