2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
20 package org.onap.dmaap.dbcapi.service;
\r
22 import static com.att.eelf.configuration.Configuration.MDC_BEGIN_TIMESTAMP;
\r
23 import static com.att.eelf.configuration.Configuration.MDC_ELAPSED_TIME;
\r
24 import static com.att.eelf.configuration.Configuration.MDC_END_TIMESTAMP;
\r
26 import java.text.SimpleDateFormat;
\r
27 import java.util.Date;
\r
28 import java.util.TimeZone;
\r
29 import org.slf4j.MDC;
\r
32 public class StopWatch {
\r
34 private static final String ISO_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
\r
35 private final static SimpleDateFormat isoFormatter = new SimpleDateFormat(ISO_FORMAT);
\r
36 private final static TimeZone utc = TimeZone.getTimeZone("UTC");
\r
38 private long startTimestamp;
\r
39 private long elapsedTime;
\r
42 isoFormatter.setTimeZone(utc);
\r
45 public void start() {
\r
46 startTimestamp = System.currentTimeMillis();
\r
47 MDC.put(MDC_BEGIN_TIMESTAMP, isoFormatter.format(new Date(startTimestamp)));
\r
50 public void stop() {
\r
51 long endTimestamp = System.currentTimeMillis();
\r
52 elapsedTime = endTimestamp - startTimestamp;
\r
53 MDC.put(MDC_END_TIMESTAMP, isoFormatter.format(new Date(endTimestamp)));
\r
54 MDC.put(MDC_ELAPSED_TIME, String.valueOf(elapsedTime));
\r
57 public void resetElapsedTime() {
\r
61 public long getElapsedTime() {
\r