This project has retired. For details please refer to its Attic page.
SendWorkerToWorkerMessageRequest xref
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.comm.ServerData;
22  import org.apache.hadoop.io.Text;
23  import org.apache.hadoop.io.Writable;
24  import org.apache.hadoop.io.WritableComparable;
25  
26  import java.io.DataInput;
27  import java.io.DataOutput;
28  import java.io.IOException;
29  
30  /** Request which sends any Writable message from one worker to another */
31  public class SendWorkerToWorkerMessageRequest extends WritableRequest
32      implements WorkerRequest<WritableComparable, Writable, Writable> {
33    /** Message sent */
34    private Writable message;
35  
36    /**
37     * Default constructor, for reflection
38     */
39    public SendWorkerToWorkerMessageRequest() {
40    }
41  
42    /**
43     * Constructor with message
44     *
45     * @param message Message sent
46     */
47    public SendWorkerToWorkerMessageRequest(Writable message) {
48      this.message = message;
49    }
50  
51    @Override
52    public RequestType getType() {
53      return RequestType.SEND_WORKER_TO_WORKER_MESSAGE_REQUEST;
54    }
55  
56    @Override
57    void writeRequest(DataOutput output) throws IOException {
58      Text.writeString(output, message.getClass().getName());
59      message.write(output);
60    }
61  
62    @Override
63    void readFieldsRequest(DataInput input) throws IOException {
64      String className = Text.readString(input);
65      try {
66        message = (Writable) Class.forName(className).newInstance();
67        message.readFields(input);
68      } catch (InstantiationException | IllegalAccessException |
69          ClassNotFoundException e) {
70        throw new IllegalStateException(
71            "readFieldsRequest: Exception occurred", e);
72      }
73    }
74  
75    @Override
76    public void doRequest(
77        ServerData<WritableComparable, Writable, Writable> serverData) {
78      serverData.addIncomingWorkerToWorkerMessage(message);
79    }
80  }