All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sun.grizzly.tcp.RequestGroupInfo Maven / Gradle / Ivy

There is a newer version: 1.9.65
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2007-2010 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
 * or packager/legal/LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at packager/legal/LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 *
 *
 * This file incorporates work covered by the following copyright and
 * permission notice:
 *
 * Copyright 2004 The Apache Software Foundation
 *
 * 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 com.sun.grizzly.tcp;

import java.util.ArrayList;

/** This can be moved to top level ( eventually with a better name ).
 *  It is currently used only as a JMX artifact, to agregate the data
 *  collected from each RequestProcessor thread.
 */
public class RequestGroupInfo {
    ArrayList processors=new ArrayList();
    private long deadMaxTime = 0;
    private long deadProcessingTime = 0;
    private int deadRequestCount = 0;
    private int deadErrorCount = 0;
    private long deadBytesReceived = 0;
    private long deadBytesSent = 0;

    // START S1AS
    private long deadCount2xx;
    private long deadCount3xx;
    private long deadCount4xx;
    private long deadCount5xx;
    private long deadCountOther;
    private long deadCount200;
    private long deadCount302;
    private long deadCount304;
    private long deadCount400;
    private long deadCount401;
    private long deadCount403;
    private long deadCount404;
    private long deadCount503;
    private long countOpenConnections;
    private long maxOpenConnections;
    // END S1AS


    public synchronized void addRequestProcessor( RequestInfo rp ) {
        processors.add( rp );
    }

    public synchronized void removeRequestProcessor( RequestInfo rp ) {
        if( rp != null ) {
            if( deadMaxTime < rp.getMaxTime() )
                deadMaxTime = rp.getMaxTime();
            deadProcessingTime += rp.getProcessingTime();
            deadRequestCount += rp.getRequestCount();
            deadErrorCount += rp.getErrorCount();
            deadBytesReceived += rp.getBytesReceived();
            deadBytesSent += rp.getBytesSent();

            // START S1AS
            deadCount2xx += rp.getCount2xx();
            deadCount3xx += rp.getCount3xx();
            deadCount4xx += rp.getCount4xx();
            deadCount5xx += rp.getCount5xx();
            deadCountOther += rp.getCountOther();
            deadCount200 += rp.getCount200();
            deadCount302 += rp.getCount302();
            deadCount304 += rp.getCount304();
            deadCount400 += rp.getCount400();
            deadCount401 += rp.getCount401();
            deadCount403 += rp.getCount403();
            deadCount404 += rp.getCount404();
            deadCount503 += rp.getCount503();
            // END S1AS

            processors.remove( rp );
        }
    }

    public synchronized long getMaxTime() {
        long maxTime=deadMaxTime;
        for( int i=0; i maxOpenConnections) {
            maxOpenConnections = countOpenConnections;
        }
    }

    public synchronized void increaseCountOpenConnections() {
        countOpenConnections++;
        if (countOpenConnections > maxOpenConnections) {
            maxOpenConnections = countOpenConnections;
        }
    }

    public synchronized void decreaseCountOpenConnections() {
        if (countOpenConnections > 0){
            countOpenConnections--;
        }
    }

    public synchronized long getMaxOpenConnections() {
        return maxOpenConnections;
    }

    public synchronized void setMaxOpenConnections(long count) {
        maxOpenConnections = count;
    }
    // END S1AS


    // START SJSAS 6338793
    /**
     * Gets the URI of the last request serviced.
     *
     * @return The URI of the last request serviced
     */
    public String getLastRequestURI() {

        long lastRequestCompletionTime = 0;
        String lastRequestURI = null;

        for (int i=0; i lastRequestCompletionTime) {
                lastRequestCompletionTime = rp.getLastRequestCompletionTime();
                lastRequestURI = rp.getLastRequestURI();
            }
        }

        return lastRequestURI;
    }

    /**
     * Gets the HTTP method of the last request serviced.
     *
     * @return The HTTP method of the last request serviced
     */
    public String getLastRequestMethod() {

        long lastRequestCompletionTime = 0;
        String lastRequestMethod = null;

        for (int i=0; i lastRequestCompletionTime) {
                lastRequestCompletionTime = rp.getLastRequestCompletionTime();
                lastRequestMethod = rp.getLastRequestMethod();
            }
        }

        return lastRequestMethod;
    }

    /**
     * Gets the time when the last request was completed.
     *
     * @return The time when the last request was completed.
     */
    public long getLastRequestCompletionTime() {

        long lastRequestCompletionTime = 0;

        for (int i=0; i lastRequestCompletionTime) {
                lastRequestCompletionTime = rp.getLastRequestCompletionTime();
            }
        }

        return lastRequestCompletionTime;
    }
    // END SJSAS 6338793


    public void resetCounters() {
        this.setBytesReceived(0);
        this.setBytesSent(0);
        this.setRequestCount(0);
        this.setProcessingTime(0);
        this.setMaxTime(0);
        this.setErrorCount(0);
        // START S1AS
        this.setCount2xx(0);
        this.setCount3xx(0);
        this.setCount4xx(0);
        this.setCount5xx(0);
        this.setCountOther(0);
        this.setCount200(0);
        this.setCount302(0);
        this.setCount304(0);
        this.setCount400(0);
        this.setCount401(0);
        this.setCount403(0);
        this.setCount404(0);
        this.setCount503(0);
        this.setCountOpenConnections(0);
        this.setMaxOpenConnections(0);
        // END S1AS
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy