View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.comm.requests;
20  
21  import org.apache.giraph.master.MasterGlobalCommHandler;
22  import org.apache.giraph.io.InputType;
23  
24  import java.io.DataInput;
25  import java.io.DataOutput;
26  import java.io.IOException;
27  
28  /**
29   * A request which workers will send to master to ask it to give them splits
30   */
31  public class AskForInputSplitRequest extends WritableRequest
32      implements MasterRequest {
33    /** Type of split we are requesting */
34    private InputType splitType;
35    /** Task id of worker which requested the split */
36    private int workerTaskId;
37  
38    /**
39     * Constructor
40     *
41     * @param splitType Type of split we are requesting
42     * @param workerTaskId Task id of worker which requested the split
43     */
44    public AskForInputSplitRequest(InputType splitType, int workerTaskId) {
45      this.splitType = splitType;
46      this.workerTaskId = workerTaskId;
47    }
48  
49    /**
50     * Constructor used for reflection only
51     */
52    public AskForInputSplitRequest() {
53    }
54  
55    @Override
56    public void doRequest(MasterGlobalCommHandler commHandler) {
57      commHandler.getInputSplitsHandler().sendSplitTo(splitType, workerTaskId);
58    }
59  
60    @Override
61    void readFieldsRequest(DataInput in) throws IOException {
62      splitType = InputType.values()[in.readInt()];
63      workerTaskId = in.readInt();
64    }
65  
66    @Override
67    void writeRequest(DataOutput out) throws IOException {
68      out.writeInt(splitType.ordinal());
69      out.writeInt(workerTaskId);
70    }
71  
72    @Override
73    public RequestType getType() {
74      return RequestType.ASK_FOR_INPUT_SPLIT_REQUEST;
75    }
76  }