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.graph;
2021/**22 * Each compute node running on the underlying cluster23 * is marked with this enum to indicate the worker or24 * master task(s) it must perform during job runs.25 */26public enum GraphFunctions {
27/** Undecided yet */28 UNKNOWN {
29 @Override publicboolean isMaster() { return false; }
30 @Override publicboolean isWorker() { return false; }
31 @Override publicboolean isZooKeeper() { return false; }
32 },
33/** Only be the master */34 MASTER_ONLY {
35 @Override publicboolean isMaster() { returntrue; }
36 @Override publicboolean isWorker() { return false; }
37 @Override publicboolean isZooKeeper() { return false; }
38 },
39/** Only be the master and ZooKeeper */40 MASTER_ZOOKEEPER_ONLY {
41 @Override publicboolean isMaster() { returntrue; }
42 @Override publicboolean isWorker() { return false; }
43 @Override publicboolean isZooKeeper() { returntrue; }
44 },
45/** Only be the worker */46 WORKER_ONLY {
47 @Override publicboolean isMaster() { return false; }
48 @Override publicboolean isWorker() { returntrue; }
49 @Override publicboolean isZooKeeper() { return false; }
50 },
51/** Do master, worker, and ZooKeeper */52 ALL {
53 @Override publicboolean isMaster() { returntrue; }
54 @Override publicboolean isWorker() { returntrue; }
55 @Override publicboolean isZooKeeper() { returntrue; }
56 },
57/** Do master and worker */58 ALL_EXCEPT_ZOOKEEPER {
59 @Override publicboolean isMaster() { returntrue; }
60 @Override publicboolean isWorker() { returntrue; }
61 @Override publicboolean isZooKeeper() { return false; }
62 };
6364/**65 * Tell whether this function acts as a master.66 *67 * @return true iff this map function is a master68 */69publicabstractboolean isMaster();
7071/**72 * Tell whether this function acts as a worker.73 *74 * @return true iff this map function is a worker75 */76publicabstractboolean isWorker();
7778/**79 * Tell whether this function acts as a ZooKeeper server.80 *81 * @return true iff this map function is a zookeeper server82 */83publicabstractboolean isZooKeeper();
8485publicboolean isKnown() {
86returnthis != UNKNOWN;
87 }
8889publicboolean isUnknown() {
90return !isKnown();
91 }
9293publicboolean isNotAWorker() {
94return isKnown() && !isWorker();
95 }
96 }