This project has retired. For details please refer to its Attic page.
TorqueDataLoader 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.hadoop.chukwa.inputtools.mdl;
19  
20  
21  import java.sql.SQLException;
22  import org.apache.commons.logging.Log;
23  import org.apache.commons.logging.LogFactory;
24  import org.apache.hadoop.chukwa.util.PidFile;
25  import org.apache.hadoop.chukwa.util.ExceptionUtil;
26  
27  public class TorqueDataLoader {
28    private static Log log = LogFactory.getLog("TorqueDataLoader");
29  
30    private TorqueInfoProcessor tp = null;
31    private PidFile loader = null;
32  
33    public TorqueDataLoader(DataConfig mdlConfig, int interval) {
34      log.info("in torqueDataLoader");
35      tp = new TorqueInfoProcessor(mdlConfig, interval);
36      loader = new PidFile("TorqueDataLoader");
37    }
38  
39    public void run() {
40      boolean first = true;
41      while (true) {
42        try {
43          tp.setup(first);
44          first = false;
45        } catch (Exception ex) {
46          tp.shutdown();
47  
48          if (first) {
49            log.error("setup error");
50            ex.printStackTrace();
51            loader.clean(); // only call before system.exit()
52            System.exit(1);
53          }
54          log.error("setup fail, retry after 10 minutes");
55          try {
56            Thread.sleep(600 * 1000);
57          } catch (InterruptedException e) {
58            // TODO Auto-generated catch block
59            log.error(e.getMessage());
60            // e.printStackTrace();
61          }
62          continue;
63  
64        }
65  
66        try {
67          tp.run_forever();
68        } catch (SQLException ex) {
69          tp.shutdown();
70          log.error("processor died, reconnect again after 10 minutes");
71          ex.printStackTrace();
72          try {
73            Thread.sleep(600 * 1000);
74          } catch (InterruptedException e) {
75            // TODO Auto-generated catch block
76            log.error(e.getMessage());
77            // e.printStackTrace();
78          }
79        } catch (Exception ex) {
80          try {
81            Thread.sleep(16 * 1000);
82          } catch (InterruptedException e) {
83            log.debug(ExceptionUtil.getStackTrace(e));
84          }
85          tp.shutdown();
86          log.error("process died...." + ex.getMessage());
87          loader.clean();
88          System.exit(1);
89        }
90  
91      }// while
92  
93    }
94  
95    public static void main(String[] args) {
96      /*
97       * if (args.length < 2 || args[0].startsWith("-h") ||
98       * args[0].startsWith("--h")) {
99       * System.out.println("Usage: UtilDataLoader interval(sec)");
100      * System.exit(1);puvw-./chij } String interval = args[0]; int
101      * intervalValue=Integer.parseInt(interval);
102      */
103     int intervalValue = 60;
104 
105     DataConfig mdlConfig = new DataConfig();
106 
107     TorqueDataLoader tdl = new TorqueDataLoader(mdlConfig, intervalValue);
108     tdl.run();
109 
110   }
111 
112 }