Writes a header to the region server with the authenticated username. It will also mark the region client as ready to process so that any pending RPCs will be flushed to the server. @param chan The channel to write to
(final Channel chan)
| 177 | * @param chan The channel to write to |
| 178 | */ |
| 179 | private void sendRPCHeader(final Channel chan) { |
| 180 | final RPCPB.UserInformation user = RPCPB.UserInformation.newBuilder() |
| 181 | .setEffectiveUser(client_auth_provider.getClientUsername()) |
| 182 | .build(); |
| 183 | final RPCPB.ConnectionHeader pb = RPCPB.ConnectionHeader.newBuilder() |
| 184 | .setUserInfo(user) |
| 185 | .setServiceName("ClientService") |
| 186 | .setCellBlockCodecClass("org.apache.hadoop.hbase.codec.KeyValueCodec") |
| 187 | .build(); |
| 188 | final int pblen = pb.getSerializedSize(); |
| 189 | final byte[] buf = new byte[4 + pblen]; |
| 190 | final ChannelBuffer header = ChannelBuffers.wrappedBuffer(buf); |
| 191 | header.clear(); |
| 192 | header.writeInt(pblen); // 4 bytes |
| 193 | try { |
| 194 | final CodedOutputStream output = |
| 195 | CodedOutputStream.newInstance(buf, 4, pblen); |
| 196 | pb.writeTo(output); |
| 197 | output.checkNoSpaceLeft(); |
| 198 | } catch (IOException e) { |
| 199 | throw new RuntimeException("Should never happen", e); |
| 200 | } |
| 201 | // We wrote to the underlying buffer but Netty didn't see the writes, |
| 202 | // so move the write index forward. |
| 203 | header.writerIndex(buf.length); |
| 204 | Channels.write(chan, wrap(header)); |
| 205 | region_client.becomeReady(chan, RegionClient.SERVER_VERSION_095_OR_ABOVE); |
| 206 | } |
| 207 | } |
no test coverage detected