    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 java.io.PrintWriter;
    020
    021import org.apache.commons.pool2.PooledObject;
    022import org.apache.commons.pool2.UsageTracking;
    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     * Clears the current stack trace snapshot. Subsequent calls to {@link #printStackTrace(PrintWriter)} will be
    036     * no-ops until another call to {@link #fillInStackTrace()}.
    037     */
    038    void clear();
    039
    040    /**
    041     * Takes a snapshot of the current call stack. Subsequent calls to {@link #printStackTrace(PrintWriter)} will print
    042     * out that stack trace until it is {@linkplain #clear() cleared}.
    043     */
    044    void fillInStackTrace();
    045
    046    /**
    047     * Prints the current stack trace if available to a PrintWriter. The format is undefined and is primarily useful
    048     * for debugging issues with {@link PooledObject} usage in user code.
    049     *
    050     * @param writer a PrintWriter to write the current stack trace to if available
    051     * @return true if a stack trace was available to print or false if nothing was printed
    052     */
    053    boolean printStackTrace(final PrintWriter writer);
    054}