This project has retired. For details please refer to its Attic page.
GraphFunctions 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.graph;
20  
21  /**
22   * Each compute node running on the underlying cluster
23   * is marked with this enum to indicate the worker or
24   * master task(s) it must perform during job runs.
25   */
26  public enum GraphFunctions {
27    /** Undecided yet */
28    UNKNOWN {
29      @Override public boolean isMaster() { return false; }
30      @Override public boolean isWorker() { return false; }
31      @Override public boolean isZooKeeper() { return false; }
32    },
33    /** Only be the master */
34    MASTER_ONLY {
35      @Override public boolean isMaster() { return true; }
36      @Override public boolean isWorker() { return false; }
37      @Override public boolean isZooKeeper() { return false; }
38    },
39    /** Only be the master and ZooKeeper */
40    MASTER_ZOOKEEPER_ONLY {
41      @Override public boolean isMaster() { return true; }
42      @Override public boolean isWorker() { return false; }
43      @Override public boolean isZooKeeper() { return true; }
44    },
45    /** Only be the worker */
46    WORKER_ONLY {
47      @Override public boolean isMaster() { return false; }
48      @Override public boolean isWorker() { return true; }
49      @Override public boolean isZooKeeper() { return false; }
50    },
51    /** Do master, worker, and ZooKeeper */
52    ALL {
53      @Override public boolean isMaster() { return true; }
54      @Override public boolean isWorker() { return true; }
55      @Override public boolean isZooKeeper() { return true; }
56    },
57    /** Do master and worker */
58    ALL_EXCEPT_ZOOKEEPER {
59      @Override public boolean isMaster() { return true; }
60      @Override public boolean isWorker() { return true; }
61      @Override public boolean isZooKeeper() { return false; }
62    };
63  
64    /**
65     * Tell whether this function acts as a master.
66     *
67     * @return true iff this map function is a master
68     */
69    public abstract boolean isMaster();
70  
71    /**
72     * Tell whether this function acts as a worker.
73     *
74     * @return true iff this map function is a worker
75     */
76    public abstract boolean isWorker();
77  
78    /**
79     * Tell whether this function acts as a ZooKeeper server.
80     *
81     * @return true iff this map function is a zookeeper server
82     */
83    public abstract boolean isZooKeeper();
84  
85    public boolean isKnown() {
86      return this != UNKNOWN;
87    }
88  
89    public boolean isUnknown() {
90      return !isKnown();
91    }
92  
93    public boolean isNotAWorker() {
94      return isKnown() && !isWorker();
95    }
96  }