fixes #69 make sleep time a function of compact time
[fluo-recipes.git] / modules / accumulo / src / main / java / io / fluo / recipes / accumulo / cmds / CompactTransient.java
1 /*
2 * Copyright 2015 Fluo authors (see AUTHORS)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14
15 package io.fluo.recipes.accumulo.cmds;
16
17 import javax.inject.Inject;
18
19 import io.fluo.api.config.FluoConfiguration;
20 import io.fluo.recipes.accumulo.ops.TableOperations;
21 import org.slf4j.LoggerFactory;
22
23 public class CompactTransient {
24
25 // when run with fluo exec command, the applications fluo config will be injected
26 @Inject
27 private static FluoConfiguration fluoConfig;
28
29 public static void main(String[] args) throws Exception {
30
31 if ((args.length == 1 && args[0].startsWith("-h")) || (args.length > 2)) {
32 System.out
33 .println("Usage : " + CompactTransient.class.getName() + " [<interval> [<count>]] ");
34
35 System.exit(-1);
36 }
37
38 int interval = 0;
39 int count = 1;
40
41 if (args.length >= 1) {
42 interval = Integer.parseInt(args[0]);
43 if (args.length == 2) {
44 count = Integer.parseInt(args[1]);
45 } else {
46 count = Integer.MAX_VALUE;
47 }
48 }
49
50 long t1 = System.currentTimeMillis();
51 TableOperations.compactTransient(fluoConfig);
52 long t2 = System.currentTimeMillis();
53 count--;
54
55 while (count > 0) {
56 long sleepTime = Math.max(3 * (t2 - t1), interval * 1000);
57 LoggerFactory.getLogger(CompactTransient.class).info("Sleeping {}ms", sleepTime);
58 Thread.sleep(sleepTime);
59 t1 = System.currentTimeMillis();
60 TableOperations.compactTransient(fluoConfig);
61 t2 = System.currentTimeMillis();
62 count--;
63 }
64 }
65 }