Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 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.
  */
 
 package com.sun.enterprise.resource.pool.monitor;
 
 import  org.glassfish.gmbal.AMXMetadata;
 import  org.glassfish.gmbal.Description;
 import  org.glassfish.gmbal.ManagedAttribute;
 import  org.glassfish.gmbal.ManagedObject;
 
StatsProvider object for Jdbc pool monitoring. Implements various events related to jdbc pool monitoring and provides objects to the calling modules that retrieve monitoring information.

Author(s):
Shalini M
 
 @AMXMetadata(type="connector-connection-pool-mon", group="monitoring")
 @ManagedObject
 @Description("Connector Connection Pool Statistics")
     
     private Logger logger;
     private PoolInfo poolInfo;
 
     
     //Registry that stores all listeners to this object
 
     
     //Objects that are exposed by this telemetry
             "NumConnFailedValidation".,
             "The total number of connections in the connection pool that failed " +
             "validation from the start time until the last sample time.");
             "NumConnTimedOut"."The total number of " +
             "connections in the pool that timed out between the start time and the last sample time.");
             0, 0, 0,
             "NumConnFree"."The total number of free " +
             "connections in the pool as of the last sampling.",
             System.currentTimeMillis(), System.currentTimeMillis());
             0, 0, 0, 
            "NumConnUsed"."Provides connection usage " +
            "statistics. The total number of connections that are currently being " +
            "used, as well as information about the maximum number of connections " +
            "that were used (the high water mark).",
            System.currentTimeMillis(), System.currentTimeMillis());
            0, 0, 0, 
            "ConnRequestWaitTime".
            "The longest and shortest wait times of connection requests. The " +
            "current value indicates the wait time of the last request that was " +
            "serviced by the pool."
            System.currentTimeMillis(), System.currentTimeMillis());
            "NumConnDestroyed".
            "Number of physical connections that were destroyed since the last reset.");
            "NumConnAcquired"."Number of logical " +
            "connections acquired from the pool.");
            "NumConnReleased"."Number of logical " +
            "connections released to the pool.");
            "NumConnCreated".
            "The number of physical connections that were created since the last reset.");
            "NumPotentialConnLeak".
            "Number of potential connection leaks");
            "NumConnSuccessfullyMatched".,
            "Number of connections succesfully matched");
            "NumConnNotSuccessfullyMatched".,
            "Number of connections rejected during matching");    
            "TotalConnRequestWaitTime".,
            "Total wait time per successful connection request");
            "AverageConnWaitTime".,
            "Average wait-time-duration per successful connection request");    
            "WaitQueueLength".
            "Number of connection requests in the queue waiting to be serviced.");    
    private static final String JCA_PROBE_LISTENER = "glassfish:jca:connection-pool:";
    public ConnectorConnPoolStatsProvider(PoolInfo poolInfoLogger logger) {
        this. = poolInfo;
        this. = logger;
    }
    
    
Whenever connection leak happens, increment numPotentialConnLeak

Parameters:
pool JdbcConnectionPool that got a connLeakEvent
    @ProbeListener( + "potentialConnLeakEvent")
    public void potentialConnLeakEvent(@ProbeParam("poolName"String poolName,
                                       @ProbeParam("appName"String appName,
                                       @ProbeParam("moduleName"String moduleName
                                       ) {
	// handle the conn leak probe event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection Leak event received - poolName = " + 
                             poolName);
            }
            //TODO V3: Checking if this is a valid event
            //Increment counter
            .increment();
        }
    }

    
Whenever connection timed-out event occurs, increment numConnTimedOut

Parameters:
pool JdbcConnectionPool that got a connTimedOutEvent
    @ProbeListener( + "connectionTimedOutEvent")
    public void connectionTimedOutEvent(@ProbeParam("poolName"String poolName,
                                        @ProbeParam("appName"String appName,
                                        @ProbeParam("moduleName"String moduleName
                                        ) {
	// handle the conn timed out probe event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection Timed-out event received - poolName = " + 
                             poolName);
            }
            //Increment counter
            .increment();
        }        
    }
    
    
Decrement numconnfree event

Parameters:
poolName
    @ProbeListener( + "decrementNumConnFreeEvent")
    public void decrementNumConnFreeEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
	// handle the num conn free decrement event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Decrement Num Connections Free event received - poolName = " + 
                        poolName);
            } 
            //Decrement counter
            synchronized() {
                .setCurrent(.getCurrent() - 1);
            }
        }
    }
    
    
Increment numconnfree event

Parameters:
poolName
beingDestroyed if the connection is destroyed due to error
steadyPoolSize
    @ProbeListener( + "incrementNumConnFreeEvent")
    public void incrementNumConnFreeEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName,
            @ProbeParam("beingDestroyed"boolean beingDestroyed,
            @ProbeParam("steadyPoolSize"int steadyPoolSize) {            
	// handle the num conn free increment event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Increment Num Connections Free event received - poolName = " + 
                             poolName);
            }
            if(beingDestroyed) {
                //if pruned by resizer thread
                synchronized() {
                    synchronized() {
                        if(.getCurrent() + .getCurrent() < steadyPoolSize) {
                            .setCurrent(.getCurrent() + 1);
                        }
                    }
                }            
            } else {
                synchronized() {
                    .setCurrent(.getCurrent() + 1);
                }
            }
        }
    }
    
    
Decrement numConnUsed event

Parameters:
poolName
    @ProbeListener( + "decrementConnectionUsedEvent")
    public void decrementConnectionUsedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
	// handle the num conn used decrement event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Decrement Num Connections Used event received - poolName = " + 
                             poolName);
            }
            //Decrement numConnUsed counter
            synchronized() {
                .setCurrent(.getCurrent() - 1);
            }
        }
    }
    
    
Connections freed event

Parameters:
poolName
count number of connections freed to the pool
    @ProbeListener( + "connectionsFreedEvent")
    public void connectionsFreedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName,
            @ProbeParam("count"int count) {
	// handle the connections freed event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connections Freed event received - poolName = " +
                        poolName);
                .finest("numConnUsed =" + .getCurrent() + 
                    " numConnFree=" + .getCurrent() + 
                    " Number of connections freed =" + count);
            }
            //set numConnFree to the count value
            synchronized() {
                .setCurrent(count);
            }
        }
    }

    
Connection used event

Parameters:
poolName
    @ProbeListener( + "connectionUsedEvent")
    public void connectionUsedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
	// handle the connection used event
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection Used event received - poolName = " + 
                             poolName);
            }
            //increment numConnUsed
            synchronized() {
                .setCurrent(.getCurrent() + 1);
            }
        }
    }

    
Whenever connection leak happens, increment numConnFailedValidation

Parameters:
pool JdbcConnectionPool that got a failed validation event
    @ProbeListener( + "connectionValidationFailedEvent")
    public void connectionValidationFailedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName,
            @ProbeParam("increment"int increment) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection Validation Failed event received - " +
                    "poolName = " + poolName);
            }
            //TODO V3 : add support in CounterImpl for addAndGet(increment)
            .increment(increment);
        }
        
    }
    
    
Event that a connection request is served in timeTakenInMillis.

Parameters:
poolName
timeTakenInMillis
    @ProbeListener( + "connectionRequestServedEvent")
    public void connectionRequestServedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName,
            @ProbeParam("timeTakenInMillis"long timeTakenInMillis) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection request served event received - " +
                    "poolName = " + poolName);
            }
            .setCurrent(timeTakenInMillis);
            .increment(timeTakenInMillis);
        }        
    }  
    
    
When connection destroyed event is got increment numConnDestroyed.
    @ProbeListener( + "connectionDestroyedEvent")
    public void connectionDestroyedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection destroyed event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                
    }
    
    
When a connection is acquired increment counter
    @ProbeListener( + "connectionAcquiredEvent")
    public void connectionAcquiredEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection acquired event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                        
    }

    
When a connection is released increment counter
    @ProbeListener( + "connectionReleasedEvent")
    public void connectionReleasedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection released event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                                
    }

    
When a connection is created increment counter
    @ProbeListener( + "connectionCreatedEvent")
    public void connectionCreatedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection created event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                                        
    }

    
Reset pool statistics When annotated with

Reset:
this method is invoked whenever monitoring is turned to HIGH from OFF, thereby setting the statistics to appropriate values.
    @Reset
    public void reset() {
        if(.isLoggable(.)) {        
            .finest("Reset event received - poolName = " + );
        }
        PoolStatus status = ConnectorRuntime.getRuntime().getPoolManager().getPoolStatus();
        .setCurrent(status.getNumConnUsed());
        .setCurrent(status.getNumConnFree());    
        .reset();
        .reset();
        .reset();
        .reset();
        .reset();
        .reset();
        .reset();
        .reset();
        .reset();        
    }
    
    
When connection under test matches the current request , increment numConnSuccessfullyMatched.
    @ProbeListener( + "connectionMatchedEvent")
    public void connectionMatchedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection matched event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                
    }

    
When a connection under test does not match the current request, increment numConnNotSuccessfullyMatched.
    @ProbeListener( + "connectionNotMatchedEvent")
    public void connectionNotMatchedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Connection not matched event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                
    }
    
    
When an object is added to wait queue, increment the waitQueueLength.
    @ProbeListener( + "connectionRequestQueuedEvent")
    public void connectionRequestQueuedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Wait Queue length modified event received - " +
                    "poolName = " + poolName);
            }
            .increment();
        }                        
    }
    
    
When an object is removed from the wait queue, decrement the waitQueueLength.
    @ProbeListener( + "connectionRequestDequeuedEvent")
    public void connectionRequestDequeuedEvent(
            @ProbeParam("poolName"String poolName,
            @ProbeParam("appName"String appName,
            @ProbeParam("moduleName"String moduleName
            ) {
        PoolInfo poolInfo = new PoolInfo(poolNameappNamemoduleName);
        if(this..equals(poolInfo)) {
            if(.isLoggable(.)) {
                .finest("Wait Queue length modified event received - " +
                    "poolName = " + poolName);
            }
            .decrement();
        }                        
    }
    protected PoolInfo getPoolInfo() {
        return ;
    }
    protected void setPoolRegistry(PoolLifeCycleListenerRegistry registry) {
        this. = registry;
    }
        return ;
    }
    
    
When a connection leak is observed, the monitoring statistics are displayed to the server.log. This method helps in segregating the statistics based on LOW/HIGH monitoring levels and displaying them.

Parameters:
poolName
stackTrace
    //TODO V3 : need this?
    /*@ProbeListener("glassfish:connector:connector-connection-pool:toString")
    public void toString(@ProbeParam("poolName") String poolName,
            @ProbeParam("stackTrace") StringBuffer stackTrace) {
        logger.finest("toString(poolName) event received. " +
                "poolName = " + poolName);
        if((poolName != null) && (poolName.equals(this.ccPoolName))) {
            //If level is not OFF then print the stack trace.
            if(jdbcPoolStatsProviderBootstrap.getEnabledValue(monitoringLevel)) {
                if("LOW".equals(monitoringLevel)) {
                    lowLevelLog(stackTrace);
                } else if("HIGH".equals(monitoringLevel)) {
                    highLevelLog(stackTrace);                    
                }
            }
        }    
    }*/
    
/*
    private void lowLevelLog(StringBuffer stackTrace) {
        stackTrace.append("\n curNumConnUsed = " + numConnUsed.getCurrent());
        stackTrace.append("\n curNumConnFree = " + numConnFree.getCurrent());
        stackTrace.append("\n numConnCreated = " + numConnCreated.getCount());
        stackTrace.append("\n numConnDestroyed = " + numConnDestroyed.getCount());        
    }
    
*/
    /*private void highLevelLog(StringBuffer stackTrace) {
        lowLevelLog(stackTrace);
        stackTrace.append("\n numConnFailedValidation = " + numConnFailedValidation.getCount());
        stackTrace.append("\n numConnTimedOut = " + numConnTimedOut.getCount());
        stackTrace.append("\n numConnAcquired = " + numConnAcquired.getCount());
        stackTrace.append("\n numConnReleased = " + numConnReleased.getCount());
        //TODO V3 : enabling other counters.
        /*stackTrace.append("\n currConnectionRequestWait = " + currConnectionRequestWait);
        stackTrace.append("\n minConnectionRequestWait = " + minConnectionRequestWait);
        stackTrace.append("\n maxConnectionRequestWait = " + maxConnectionRequestWait);
        stackTrace.append("\n totalConnectionRequestWait = " + totalConnectionRequestWait);
        stackTrace.append("\n numConnSuccessfullyMatched = " + this.numConnSuccessfullyMatched);
        stackTrace.append("\n numConnNotSuccessfullyMatched = " + numConnNotSuccessfullyMatched);
        stackTrace.append("\n numPotentialConnLeak = " + numPotentialConnLeak.getCount());
    }*/
    @ManagedAttribute(id="numpotentialconnleak")
        return .getStatistic();
    }
    @ManagedAttribute(id="numconnfailedvalidation")
        return .getStatistic();
    }
    @ManagedAttribute(id="numconntimedout")
        return .getStatistic();
    }
    @ManagedAttribute(id="numconnused")
    public RangeStatistic getNumConnUsed() {
        return .getStatistic();
    }
    @ManagedAttribute(id="numconnfree")
    public RangeStatistic getNumConnFree() {
        return .getStatistic();
    }
    @ManagedAttribute(id="connrequestwaittime")
        return .getStatistic();
    }
    @ManagedAttribute(id="numconndestroyed")
        return .getStatistic();
    }
    @ManagedAttribute(id="numconnacquired")
        return .getStatistic();
    }
    @ManagedAttribute(id="numconncreated")
    public CountStatistic getNumConnCreated() {
        return .getStatistic();
    }
    @ManagedAttribute(id="numconnreleased")
        return .getStatistic();
    }
    
    @ManagedAttribute(id="numconnsuccessfullymatched")
        return ;
    }
    
    @ManagedAttribute(id="numconnnotsuccessfullymatched")
        return ;
    }
    @ManagedAttribute(id="averageconnwaittime")
       //Time taken by all connection requests divided by total number of 
       //connections acquired in the sampling period.
       long averageWaitTime = 0;        
       if (.getCount() != 0) {
           averageWaitTime = .getCount()/ 
                   .getCount();
       } else {
           averageWaitTime = 0;
       }
       .setCount(averageWaitTime);
       return ;
    }
    @ManagedAttribute(id="waitqueuelength"
        return ;
    }    
New to GrepCode? Check out our FAQ X