This project has retired. For details please refer to its Attic page.
Block 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  package org.apache.giraph.block_app.framework.block;
19  
20  import java.util.Iterator;
21  
22  import org.apache.giraph.block_app.framework.piece.AbstractPiece;
23  import org.apache.giraph.function.Consumer;
24  
25  /**
26   * Composable unit of execution. Used to combine other Blocks into
27   * bigger units. Each Piece represents a Block itself.
28   *
29   * Execution is represented as an iterator across Pieces.
30   *
31   * The whole application run is represented by a single block at the end.
32   */
33  @SuppressWarnings("rawtypes")
34  public interface Block extends Iterable<AbstractPiece> {
35    /**
36     * Create iterator representing all pieces needed to be executed
37     * in this block.
38     *
39     * After Iterator.next call returns, master compute of returned Piece is
40     * guaranteed to be called before calling hasNext/next on the iterator.
41     * (allows for iterators logic to depend on the execution dynamically,
42     * and not be only static)
43     */
44    @Override
45    Iterator<AbstractPiece> iterator();
46  
47    /**
48     * Calls consumer for each Piece:
49     * - in no particular order
50     * - potentially calling multiple times on same Piece
51     * - even if Piece might never be returned in the iterator
52     * - it will be called at least once for every piece that is
53     *   going to be returned by iterator
54     *
55     * Can be used for static analysis/introspection of the block,
56     * without actually executing them.
57     */
58    void forAllPossiblePieces(Consumer<AbstractPiece> consumer);
59  
60    /**
61     * How many pieces are in this block.
62     * Sometimes we don't know (eg RepeatBlock).
63     *
64     * @return How many pieces are in this block.
65     */
66    PieceCount getPieceCount();
67  }