Serializes this request.
(final byte server_version)
| 214 | |
| 215 | /** Serializes this request. */ |
| 216 | ChannelBuffer serialize(final byte server_version) { |
| 217 | if (server_version < RegionClient.SERVER_VERSION_095_OR_ABOVE) { |
| 218 | return serializeOld(server_version); |
| 219 | } |
| 220 | |
| 221 | // we create a new RegionAction for each region. |
| 222 | Collections.sort(batch, SORT_BY_REGION_AND_KEY); |
| 223 | final MultiRequest.Builder req = MultiRequest.newBuilder(); |
| 224 | RegionAction.Builder actions = null; |
| 225 | byte[] prev_region = HBaseClient.EMPTY_ARRAY; |
| 226 | int i = 0; |
| 227 | for (final BatchableRpc rpc : batch) { |
| 228 | final RegionInfo region = rpc.getRegion(); |
| 229 | final boolean new_region = !Bytes.equals(prev_region, region.name()); |
| 230 | if (new_region) { |
| 231 | if (actions != null) { // If not the first iteration ... |
| 232 | req.addRegionAction(actions.build()); // ... push actions thus far. |
| 233 | } |
| 234 | actions = RegionAction.newBuilder(); |
| 235 | actions.setRegion(rpc.getRegion().toProtobuf()); |
| 236 | prev_region = region.name(); |
| 237 | } |
| 238 | final Action.Builder action = Action.newBuilder().setIndex(i++); |
| 239 | if (rpc instanceof GetRequest) { |
| 240 | action.setGet(((GetRequest)rpc).getPB()); |
| 241 | } else { |
| 242 | action.setMutation(rpc.toMutationProto()); |
| 243 | } |
| 244 | actions.addAction(action); |
| 245 | } |
| 246 | req.addRegionAction(actions.build()); |
| 247 | return toChannelBuffer(MMULTI, req.build()); |
| 248 | } |
| 249 | |
| 250 | /** Serializes this request for HBase 0.94 and before. */ |
| 251 | private ChannelBuffer serializeOld(final byte server_version) { |