/**
 * Copyright 2010 CosmoCode GmbH
 *
 * Licensed 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 de.cosmocode.palava.jta;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author Tobias Sarnowski
 */
public class TransactionCounter implements TransactionCounterMBean, Serializable {

    private final AtomicLong pending = new AtomicLong();
    private final AtomicLong committed = new AtomicLong();
    private final AtomicLong rolledbackSuccess = new AtomicLong();
    private final AtomicLong rolledbackFailed = new AtomicLong();


    @Override
    public AtomicLong getRolledbackFailed() {
        return rolledbackFailed;
    }

    @Override
    public AtomicLong getRolledbackSuccess() {
        return rolledbackSuccess;
    }

    public long getRolledback() {
        return rolledbackSuccess.get() + rolledbackFailed.get();
    }

    @Override
    public AtomicLong getCommitted() {
        return committed;
    }

    @Override
    public AtomicLong getPending() {
        return pending;
    }
}
@@ -1131,24 +1131,113 @@
 kFailed() %7B%0A
+        if (rolledbackFailed.get() %3C 0) %7B%0A            rolledbackFailed.set(0);%0A        %7D%0A
         retu
@@ -1321,24 +1321,115 @@
 Success() %7B%0A
+        if (rolledbackSuccess.get() %3C 0) %7B%0A            rolledbackSuccess.set(0);%0A        %7D%0A
         retu
@@ -1498,33 +1498,36 @@
 %0A        return 
-r
+getR
 olledbackSuccess
@@ -1522,24 +1522,26 @@
 dbackSuccess
+()
 .get() + rol
@@ -1537,17 +1537,20 @@
 get() + 
-r
+getR
 olledbac
@@ -1552,24 +1552,26 @@
 edbackFailed
+()
 .get();%0A    
@@ -1622,24 +1622,99 @@
 mmitted() %7B%0A
+        if (committed.get() %3C 0) %7B%0A            committed.set(0);%0A        %7D%0A
         retu
@@ -1781,24 +1781,95 @@
 Pending() %7B%0A
+        if (pending.get() %3C 0) %7B%0A            pending.set(0);%0A        %7D%0A
         retu

reset counters to 0