Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
WaitIOCommand |
|
| 1.5;1.5 |
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 | import java.util.concurrent.TimeUnit; | |
25 | ||
26 | /** | |
27 | * IOCommand to do nothing regarding moving data to/from disk. | |
28 | */ | |
29 | public class WaitIOCommand extends IOCommand { | |
30 | /** How long should the disk be idle? (in milliseconds) */ | |
31 | private final long waitDuration; | |
32 | ||
33 | /** | |
34 | * Constructor | |
35 | * | |
36 | * @param oocEngine out-of-core engine | |
37 | * @param waitDuration duration of wait | |
38 | */ | |
39 | public WaitIOCommand(OutOfCoreEngine oocEngine, long waitDuration) { | |
40 | 0 | super(oocEngine, -1); |
41 | 0 | this.waitDuration = waitDuration; |
42 | 0 | } |
43 | ||
44 | @Override | |
45 | public boolean execute() throws IOException { | |
46 | try { | |
47 | 0 | TimeUnit.MILLISECONDS.sleep(waitDuration); |
48 | 0 | } catch (InterruptedException e) { |
49 | 0 | throw new IllegalStateException("execute: caught InterruptedException " + |
50 | "while IO thread is waiting!"); | |
51 | 0 | } |
52 | 0 | return true; |
53 | } | |
54 | ||
55 | @Override | |
56 | public IOCommandType getType() { | |
57 | 0 | return IOCommandType.WAIT; |
58 | } | |
59 | ||
60 | @Override | |
61 | public String toString() { | |
62 | 0 | return "WaitIOCommand: (duration = " + waitDuration + "ms)"; |
63 | } | |
64 | } |