Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
IOCommand |
|
| 1.0;1 | ||||
IOCommand$IOCommandType |
|
| 1.0;1 |
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.ooc.command; | |
20 | ||
21 | import org.apache.giraph.ooc.OutOfCoreEngine; | |
22 | ||
23 | import java.io.IOException; | |
24 | ||
25 | /** | |
26 | * Representation of an IO command (moving data to disk/memory) used in | |
27 | * out-of-core mechanism. | |
28 | */ | |
29 | public abstract class IOCommand { | |
30 | /** Type of IO command */ | |
31 | 0 | public enum IOCommandType { |
32 | /** Loading a partition */ | |
33 | 0 | LOAD_PARTITION, |
34 | /** Storing a partition */ | |
35 | 0 | STORE_PARTITION, |
36 | /** Storing incoming messages of a partition */ | |
37 | 0 | STORE_MESSAGE, |
38 | /** | |
39 | * Storing message/buffer raw data buffer of a currently out-of-core | |
40 | * partition | |
41 | */ | |
42 | 0 | STORE_BUFFER, |
43 | /** Doing nothing regarding IO */ | |
44 | 0 | WAIT |
45 | } | |
46 | ||
47 | /** Id of the partition involved for the IO */ | |
48 | protected final int partitionId; | |
49 | /** Out-of-core engine */ | |
50 | protected final OutOfCoreEngine oocEngine; | |
51 | /** | |
52 | * Number of bytes transferred to/from memory (loaded/stored) during the | |
53 | * execution of the command | |
54 | */ | |
55 | protected long numBytesTransferred; | |
56 | ||
57 | /** | |
58 | * Constructor | |
59 | * | |
60 | * @param oocEngine Out-of-core engine | |
61 | * @param partitionId Id of the partition involved in the IO | |
62 | */ | |
63 | 0 | public IOCommand(OutOfCoreEngine oocEngine, int partitionId) { |
64 | 0 | this.oocEngine = oocEngine; |
65 | 0 | this.partitionId = partitionId; |
66 | 0 | this.numBytesTransferred = 0; |
67 | 0 | } |
68 | ||
69 | /** | |
70 | * Get the id of the partition involved in the IO | |
71 | * | |
72 | * @return id of the partition | |
73 | */ | |
74 | public int getPartitionId() { | |
75 | 0 | return partitionId; |
76 | } | |
77 | ||
78 | /** | |
79 | * Execute (load/store of data) the IO command, and change the data stores | |
80 | * appropriately based on the data loaded/stored. Return true iff the command | |
81 | * is actually executed (resulted in loading or storing data). | |
82 | * | |
83 | * @return whether the command is actually executed | |
84 | * @throws IOException | |
85 | */ | |
86 | public abstract boolean execute() throws IOException; | |
87 | ||
88 | /** | |
89 | * Get the type of the command. | |
90 | * | |
91 | * @return type of the command | |
92 | */ | |
93 | public abstract IOCommandType getType(); | |
94 | ||
95 | /** | |
96 | * Get the number of bytes transferred (loaded/stored from/to disk). | |
97 | * | |
98 | * @return number of bytes transferred during the execution of the command | |
99 | */ | |
100 | public long bytesTransferred() { | |
101 | 0 | return numBytesTransferred; |
102 | } | |
103 | } | |
104 |