@@ -0,0 +1,2252 @@
+/*%0A * Copyright (C) 2015 Brett Wooldridge%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.codacy.play.tomcatcp.metrics;%0A%0Aimport com.codacy.play.tomcatcp.utils.ClockSource;%0A%0Aimport java.util.concurrent.atomic.AtomicLong;%0A%0A/**%0A * @author Brett Wooldridge%0A */%0Apublic abstract class PoolStats %7B%0A    private final ClockSource clock;%0A    private final AtomicLong reloadAt;%0A    private final long timeoutMs;%0A%0A    protected volatile int totalConnections;%0A    protected volatile int idleConnections;%0A    protected volatile int activeConnections;%0A    protected volatile int pendingThreads;%0A%0A    public PoolStats(final long timeoutMs) %7B%0A        this.timeoutMs = timeoutMs;%0A        this.reloadAt = new AtomicLong();%0A        this.clock = ClockSource.INSTANCE;%0A    %7D%0A%0A    public int getTotalConnections() %7B%0A        if (shouldLoad()) %7B%0A            update();%0A        %7D%0A%0A        return totalConnections;%0A    %7D%0A%0A    public int getIdleConnections() %7B%0A        if (shouldLoad()) %7B%0A            update();%0A        %7D%0A%0A        return idleConnections;%0A    %7D%0A%0A    public int getActiveConnections() %7B%0A        if (shouldLoad()) %7B%0A            update();%0A        %7D%0A%0A        return activeConnections;%0A    %7D%0A%0A    public int getPendingThreads() %7B%0A        if (shouldLoad()) %7B%0A            update();%0A        %7D%0A%0A        return pendingThreads;%0A    %7D%0A%0A    protected abstract void update();%0A%0A    private boolean shouldLoad() %7B%0A        for (; ; ) %7B%0A            final long now = clock.currentTime();%0A            final long reloadTime = reloadAt.get();%0A            if (reloadTime %3E now) %7B%0A                return false;%0A            %7D else if (reloadAt.compareAndSet(reloadTime, clock.plusMillis(now, timeoutMs))) %7B%0A                return true;%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add a class that provides updated stats of a pool