1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.comm.requests;
2021import org.apache.giraph.comm.ServerData;
22import org.apache.giraph.partition.Partition;
23import org.apache.hadoop.io.Writable;
24import org.apache.hadoop.io.WritableComparable;
25import org.apache.log4j.Logger;
2627import java.io.DataInput;
28import java.io.DataOutput;
29import java.io.IOException;
3031/**32 * Send a collection of vertices for a partition. Note that this doesn't33 * use a cache - might want to optimize in the future.34 *35 * @param <I> Vertex id36 * @param <V> Vertex data37 * @param <E> Edge data38 */39 @SuppressWarnings("rawtypes")
40publicclass SendVertexRequest<I extends WritableComparable,
41 V extends Writable, E extends Writable> extends42 WritableRequest<I, V, E> implements WorkerRequest<I, V, E> {
43/** Class logger */44privatestaticfinal Logger LOG =
45 Logger.getLogger(SendVertexRequest.class);
46/**Partition */47private Partition<I, V, E> partition;
4849/**50 * Constructor used for reflection only51 */52publicSendVertexRequest() { }
5354/**55 * Constructor for sending a request.56 *57 * @param partition Partition to send the request to58 */59publicSendVertexRequest(Partition<I, V, E> partition) {
60this.partition = partition;
61 }
6263 @Override
64publicvoid readFieldsRequest(DataInput input) throws IOException {
65 partition = getConf().createPartition(-1, null);
66 partition.readFields(input);
67 }
6869 @Override
70publicvoid writeRequest(DataOutput output) throws IOException {
71 partition.write(output);
72 }
7374 @Override
75publicRequestType getType() {
76return RequestType.SEND_VERTEX_REQUEST;
77 }
7879 @Override
80publicvoid doRequest(ServerData<I, V, E> serverData) {
81 serverData.getPartitionStore().addPartition(partition);
82 }
8384 @Override
85publicint getSerializedSize() {
86return WritableRequest.UNKNOWN_SIZE;
87 }
88 }
89