/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.synapse.aspects.flow.statistics.log;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * This class is to hold stat count information(stat count, callback count) inside event holder.
 */
public class StatisticsReportingCountHolder {
    /**
     * Which holds count of open events.
     */
    private AtomicInteger statCount = new AtomicInteger(0);

    /**
     * Which holds count of call backs registered.
     */
    private AtomicInteger callBackCount = new AtomicInteger(0);

    /**
     * Which holds count of branches created by clone or iterate mediators. This is used to track the sub branches created by clone or iterate mediators, and to make sure all the branches are closed before closing the main branch.
     * Initial value is 1 since main branch is also considered as a branch, and it is closed when all the sub branches are closed.
     */
    private AtomicInteger branchCount = new AtomicInteger(1);

    public void incrementStatCount() {
        this.statCount.incrementAndGet();
    }

    public int decrementAndGetStatCount() {
        return this.statCount.decrementAndGet();
    }

    public int getStatCount() {
        return this.statCount.get();
    }

    public void incrementCallBackCount() {
        this.callBackCount.incrementAndGet();
    }

    public int decrementAndGetCallbackCount() {
        return this.callBackCount.decrementAndGet();
    }

    public int getCallBackCount() {
        return this.callBackCount.get();
    }

    public void incrementBranchCount() {
        this.branchCount.incrementAndGet();
    }

    public int decrementAndGetBranchCount() {
        return this.branchCount.decrementAndGet();
    }

    public int getBranchCount() {
        return this.branchCount.get();
    }

}
