001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.stats; 018 019import java.time.*; 020import java.util.*; 021 022import org.apache.juneau.annotation.*; 023import org.apache.juneau.rest.*; 024import org.apache.juneau.swaps.*; 025 026/** 027 * A snapshot of execution statistics for REST resource classes. 028 * 029 * <h5 class='section'>See Also:</h5><ul> 030 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/ExecutionStatistics">REST method execution statistics</a> 031 * </ul> 032 */ 033@Bean(properties = "startTime,upTime,methodStats") 034public class RestContextStats { 035 private final Instant startTime; 036 private final List<MethodExecStats> methodStats; 037 038 /** 039 * Constructor. 040 * 041 * @param startTime The start time of the {@link RestContext} object. 042 * @param methodStats The execution statistics beans for the context. 043 */ 044 public RestContextStats(Instant startTime, List<MethodExecStats> methodStats) { 045 this.startTime = startTime; 046 this.methodStats = methodStats; 047 } 048 049 /** 050 * Returns statistics on all method executions. 051 * 052 * @return Statistics on all method executions. 053 */ 054 public Collection<MethodExecStats> getMethodStats() { return methodStats; } 055 056 /** 057 * Returns the time this REST resource class was started. 058 * 059 * @return The time this REST resource class was started. 060 */ 061 @Swap(TemporalSwap.IsoInstant.class) 062 public Instant getStartTime() { return startTime; } 063 064 /** 065 * Returns the time in milliseconds that this REST resource class has been running. 066 * 067 * @return The time in milliseconds that this REST resource class has been running. 068 */ 069 public String getUpTime() { 070 long s = Duration.between(startTime, Instant.now()).getSeconds(); 071 return String.format("%dh:%02dm:%02ds", s / 3600, (s % 3600) / 60, (s % 60)); 072 } 073}