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.commons.pool2.impl; 018 019import org.apache.commons.pool2.PooledObject; 020import org.apache.commons.pool2.UsageTracking; 021 022import java.io.PrintWriter; 023 024/** 025 * Strategy for obtaining and printing the current call stack. This is primarily useful for 026 * {@linkplain UsageTracking usage tracking} so that different JVMs and configurations can use more efficient strategies 027 * for obtaining the current call stack depending on metadata needs. 028 * 029 * @see CallStackUtils 030 * @since 2.4.3 031 */ 032public interface CallStack { 033 034 /** 035 * Prints the current stack trace if available to a PrintWriter. The format is undefined and is primarily useful 036 * for debugging issues with {@link PooledObject} usage in user code. 037 * 038 * @param writer a PrintWriter to write the current stack trace to if available 039 * @return true if a stack trace was available to print or false if nothing was printed 040 */ 041 boolean printStackTrace(final PrintWriter writer); 042 043 /** 044 * Takes a snapshot of the current call stack. Subsequent calls to {@link #printStackTrace(PrintWriter)} will print 045 * out that stack trace until it is {@linkplain #clear() cleared}. 046 */ 047 void fillInStackTrace(); 048 049 /** 050 * Clears the current stack trace snapshot. Subsequent calls to {@link #printStackTrace(PrintWriter)} will be 051 * no-ops until another call to {@link #fillInStackTrace()}. 052 */ 053 void clear(); 054}