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 */18package org.apache.giraph.block_app.migration;
1920import java.io.DataInput;
21import java.io.DataOutput;
22import java.io.IOException;
23import java.util.List;
2425import org.apache.giraph.block_app.framework.api.BlockWorkerContextApi;
26import org.apache.giraph.block_app.framework.api.BlockWorkerContextSendApi;
27import org.apache.giraph.conf.DefaultImmutableClassesGiraphConfigurable;
28import org.apache.hadoop.io.Writable;
29import org.apache.hadoop.io.WritableComparable;
3031/**32 * Replacement for WorkerContext when migrating to Blocks Framework,33 * disallowing functions that are tied to execution order.34 */35 @SuppressWarnings({"rawtypes", "unchecked"})
36publicclassMigrationWorkerContext37extendsDefaultImmutableClassesGiraphConfigurable38implements Writable {
39privateBlockWorkerContextApi api;
40private List<Writable> receivedMessages;
4142publicvoid setApi(BlockWorkerContextApi api) {
43this.api = api;
44this.setConf(api.getConf());
45 }
4647publicvoid setReceivedMessages(List<Writable> receivedMessages) {
48this.receivedMessages = receivedMessages;
49 }
5051publicvoid preSuperstep() { }
5253publicvoid postSuperstep() { }
5455 @SuppressWarnings("deprecation")
56publiclong getTotalNumVertices() {
57return api.getTotalNumVertices();
58 }
5960 @SuppressWarnings("deprecation")
61publiclong getTotalNumEdges() {
62return api.getTotalNumEdges();
63 }
6465 @Override
66publicvoid readFields(DataInput in) throws IOException {
67 }
6869 @Override
70publicvoid write(DataOutput out) throws IOException {
71 }
7273publicfinalint getWorkerCount() {
74return api.getWorkerCount();
75 }
7677publicfinalint getMyWorkerIndex() {
78return api.getMyWorkerIndex();
79 }
8081publicfinal List<Writable> getAndClearMessagesFromOtherWorkers() {
82 List<Writable> ret = receivedMessages;
83 receivedMessages = null;
84return ret;
85 }
8687publicfinalvoid sendMessageToWorker(Writable message, int workerIndex) {
88 ((BlockWorkerContextSendApi<WritableComparable, Writable>) api)
89 .sendMessageToWorker(message, workerIndex);
90 }
9192/**93 * Drop-in replacement for WorkerContext when migrating to94 * Blocks Framework.95 */96publicstaticclassMigrationFullWorkerContext97extendsMigrationWorkerContext {
98publicvoid preApplication()
99throws InstantiationException, IllegalAccessException {
100 }
101102publicvoid postApplication() { }
103 }
104 }