This project has retired. For details please refer to its Attic page.
Util 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  
19  package org.apache.hadoop.chukwa.extraction.demux.processor;
20  
21  
22  import java.text.SimpleDateFormat;
23  import java.util.Calendar;
24  
25  public class Util {
26    static SimpleDateFormat day = new java.text.SimpleDateFormat("yyyyMMdd");
27  
28    static Calendar calendar = Calendar.getInstance();
29    static int currentDay = 0;
30    static int currentHour = 0;
31  
32    static {
33      synchronized (calendar) {
34        calendar.setTimeInMillis(System.currentTimeMillis());
35        currentDay = Integer.parseInt(day.format(calendar.getTime()));
36        currentHour = calendar.get(Calendar.HOUR_OF_DAY);
37      }
38    }
39  
40    public static String generateTimeOutput(long timestamp) {
41      int workingDay = 0;
42      int workingHour = 0;
43  
44      String output = null;
45  
46      int minutes = 0;
47      synchronized (calendar) {
48        calendar.setTimeInMillis(timestamp);
49        workingDay = Integer.parseInt(day.format(calendar.getTime()));
50        workingHour = calendar.get(Calendar.HOUR_OF_DAY);
51        minutes = calendar.get(Calendar.MINUTE);
52      }
53  
54      if (workingDay != currentDay) {
55        output = "_" + workingDay + ".D.evt";
56      } else {
57        if (workingHour != currentHour) {
58          output = "_" + workingDay + "_" + workingHour + ".H.evt";
59        } else {
60          output = "_" + workingDay + "_" + workingHour + "_";
61          int dec = minutes / 10;
62          output += dec;
63  
64          int m = minutes - (dec * 10);
65          if (m < 5) {
66            output += "0.R.evt";
67          } else {
68            output += "5.R.evt";
69          }
70        }
71      }
72  
73      return output;
74    }
75  }