001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.utils; 014 015import java.util.concurrent.atomic.*; 016 017/** 018 * Represents an entry in {@link StackTraceDatabase}. 019 */ 020public class StackTraceInfo { 021 AtomicInteger count; 022 long timeout; 023 String hash; 024 025 StackTraceInfo(long timeout, int hash) { 026 this.count = new AtomicInteger(1); 027 this.timeout = System.currentTimeMillis() + timeout; 028 this.hash = Integer.toHexString(hash); 029 } 030 031 private StackTraceInfo(int count, long timeout, String hash) { 032 this.count = new AtomicInteger(count); 033 this.timeout = timeout; 034 this.hash = hash; 035 } 036 037 @Override 038 public StackTraceInfo clone() { 039 return new StackTraceInfo(count.intValue(), timeout, hash); 040 } 041 042 /** 043 * Returns the number of times this stack trace was encountered. 044 * 045 * @return The number of times this stack trace was encountered. 046 */ 047 public int getCount() { 048 return count.intValue(); 049 } 050 051 /** 052 * Returns an 8-byte hash of the stack trace. 053 * 054 * @return An 8-byte hash of the stack trace. 055 */ 056 public String getHash() { 057 return hash; 058 } 059 060 StackTraceInfo incrementAndClone() { 061 return new StackTraceInfo(count.incrementAndGet(), timeout, hash); 062 } 063}