Class ConnectionPool

    • Field Detail

      • localStrings

        protected static final StringManager localStrings
      • _logger

        protected static final Logger _logger
      • maxPoolSize

        protected int maxPoolSize
      • steadyPoolSize

        protected int steadyPoolSize
      • resizeQuantity

        protected int resizeQuantity
      • maxWaitTime

        protected int maxWaitTime
      • idletime

        protected long idletime
      • failAllConnections

        protected boolean failAllConnections
      • matchConnections

        protected boolean matchConnections
      • validation

        protected boolean validation
      • preferValidateOverRecreate

        protected boolean preferValidateOverRecreate
      • resizerTask

        protected Resizer resizerTask
      • poolInitialized

        protected volatile boolean poolInitialized
      • timer

        protected Timer timer
      • connectionCreationRetry_

        protected boolean connectionCreationRetry_
      • connectionCreationRetryAttempts_

        protected int connectionCreationRetryAttempts_
      • conCreationRetryInterval_

        protected long conCreationRetryInterval_
      • validateAtmostPeriodInMilliSeconds_

        protected long validateAtmostPeriodInMilliSeconds_
      • maxConnectionUsage_

        protected int maxConnectionUsage_
      • resourceSelectionStrategyClass

        protected String resourceSelectionStrategyClass
      • resourceGatewayClass

        protected String resourceGatewayClass
      • dataStructureType

        protected String dataStructureType
      • dataStructureParameters

        protected String dataStructureParameters
      • poolWaitQueueClass

        protected String poolWaitQueueClass
      • poolInfo

        protected final PoolInfo poolInfo
    • Method Detail

      • initializeResourceSelectionStrategy

        protected void initializeResourceSelectionStrategy()
      • initializeResizer

        protected Resizer initializeResizer()
      • setResourceStateToFree

        protected void setResourceStateToFree​(ResourceHandle resourceHandle)
        marks resource as free. This method should be used instead of directly calling resoureHandle.getResourceState().setBusy(false) OR getResourceState(resourceHandle).setBusy(false) as this method handles stopping of connection leak tracing If connection leak tracing is enabled, takes care of stopping connection leak tracing
        Parameters:
        resourceHandle - Resource
      • setResourceStateToBusy

        protected void setResourceStateToBusy​(ResourceHandle resourceHandle)
        marks resource as busy. This method should be used instead of directly calling resoureHandle.getResourceState().setBusy(true) OR getResourceState(resourceHandle).setBusy(true) as this method handles starting of connection leak tracing If connection leak tracing is enabled, takes care of starting connection leak tracing
        Parameters:
        resourceHandle - Resource
      • getResource

        public ResourceHandle getResource​(ResourceSpec spec,
                                          ResourceAllocator alloc,
                                          jakarta.transaction.Transaction txn)
                                   throws PoolingException,
                                          jakarta.resource.spi.RetryableUnavailableException
        returns resource from the pool.
        Specified by:
        getResource in interface ResourcePool
        Returns:
        a free pooled resource object matching the ResourceSpec
        Throws:
        PoolingException - - if any error occurrs - or the pool has reached its max size and the max-connection-wait-time-in-millis has expired.
        jakarta.resource.spi.RetryableUnavailableException
      • prefetch

        protected ResourceHandle prefetch​(ResourceSpec spec,
                                          ResourceAllocator alloc,
                                          jakarta.transaction.Transaction tran)
        Overridden in AssocWithThreadResourcePool to fetch the resource cached in the ThreadLocal In ConnectionPool this simply returns null.
        Parameters:
        spec - ResourceSpec
        alloc - ResourceAllocator to create a resource
        tran - Transaction
        Returns:
        ResourceHandle resource from ThreadLocal
      • getUnenlistedResource

        protected ResourceHandle getUnenlistedResource​(ResourceSpec spec,
                                                       ResourceAllocator alloc,
                                                       jakarta.transaction.Transaction tran)
                                                throws PoolingException
        To provide an unenlisted, valid, matched resource from pool.
        Parameters:
        spec - ResourceSpec
        alloc - ResourceAllocator
        tran - Transaction
        Returns:
        ResourceHandle resource from pool
        Throws:
        PoolingException - Exception while getting resource from pool
      • isConnectionValid

        protected boolean isConnectionValid​(ResourceHandle h,
                                            ResourceAllocator alloc)
        Check whether the connection is valid
        Parameters:
        h - Resource to be validated
        alloc - Allocator to validate the resource
        Returns:
        boolean representing validation result
      • matchConnection

        protected boolean matchConnection​(ResourceHandle resource,
                                          ResourceAllocator alloc)
        check whether the connection retrieved from the pool matches with the request.
        Parameters:
        resource - Resource to be matched
        alloc - ResourceAllocator used to match the connection
        Returns:
        boolean representing the match status of the connection
      • getResourceFromPool

        protected ResourceHandle getResourceFromPool​(ResourceAllocator alloc,
                                                     ResourceSpec spec)
                                              throws PoolingException
        return resource in free list. If none is found, try to scale up the pool/purge pool and
        return a new resource. returns null if the pool new resources cannot be created.
        Parameters:
        alloc - ResourceAllocator
        Returns:
        ResourceHandle resource from pool
        Throws:
        PoolingException - if unable to create a new resource
      • createSingleResourceAndAdjustPool

        protected ResourceHandle createSingleResourceAndAdjustPool​(ResourceAllocator alloc,
                                                                   ResourceSpec spec)
                                                            throws PoolingException
        This method will be called from the getUnenlistedResource method if we detect a failAllConnection flag. Here we simply create a new resource and replace a free resource in the pool by this resource and then give it out. This replacement is required since the steadypoolsize might equal maxpoolsize and in that case if we were not to remove a resource from the pool, our resource would be above maxPoolSize
        Parameters:
        alloc - ResourceAllocator to create resource
        spec - ResourceSpec
        Returns:
        newly created resource
        Throws:
        PoolingException - when unable to create a resource
      • createSingleResource

        protected ResourceHandle createSingleResource​(ResourceAllocator resourceAllocator)
                                               throws PoolingException
        Method to be used to create resource, instead of calling ResourceAllocator.createConfigBean(). This method handles the connection creation retrial in case of failure
        Parameters:
        resourceAllocator - ResourceAllocator
        Returns:
        ResourceHandle newly created resource
        Throws:
        PoolingException - when unable create a resource
      • performMaxConnectionUsageOperation

        protected void performMaxConnectionUsageOperation​(ResourceHandle handle)
        If the resource is used for maxConnectionUsage times, destroy and create one
        Parameters:
        handle - Resource to be checked
      • freeUnenlistedResource

        protected void freeUnenlistedResource​(ResourceHandle h)
      • freeResource

        protected void freeResource​(ResourceHandle resourceHandle)
      • cleanupResource

        protected boolean cleanupResource​(ResourceHandle handle)
      • isResourceUnused

        protected boolean isResourceUnused​(ResourceHandle h)
      • getInvalidConnections

        public Set getInvalidConnections​(Set connections)
                                  throws jakarta.resource.ResourceException
        Description copied from interface: ResourceHandler
        gets the invalid connections from the given connections set
        Specified by:
        getInvalidConnections in interface ResourceHandler
        Parameters:
        connections - that need to be validated
        Returns:
        invalid connections set
        Throws:
        jakarta.resource.ResourceException - when unable to validate
      • resizePool

        public void resizePool​(boolean forced)
        Specified by:
        resizePool in interface ResourcePool
      • notifyWaitingThreads

        protected void notifyWaitingThreads()
      • blockRequests

        public void blockRequests​(long waitTimeout)
        Description copied from interface: ResourcePool
        block any new requests to the pool Used for transparent dynamic reconfiguration of the pool
        Specified by:
        blockRequests in interface ResourcePool
        Parameters:
        waitTimeout - time for which the new requests will wait
      • flushConnectionPool

        public boolean flushConnectionPool()
                                    throws PoolingException
        Reinitialize connections established in the connection pool and bring the pool to steady pool size.
        Specified by:
        flushConnectionPool in interface ResourcePool
        Returns:
        boolean indicating whether flush operation was successful or not
        Throws:
        PoolingException
      • reconfigurePool

        public void reconfigurePool​(ConnectorConnectionPool poolResource)
                             throws PoolingException
        Reconfigure the Pool's properties. The reconfigConnectorConnectionPool method in the ConnectorRuntime will use this method (through PoolManager) if it needs to just change pool properties and not recreate the pool
        Specified by:
        reconfigurePool in interface ResourcePool
        Parameters:
        poolResource - - the ConnectorConnectionPool JavaBean that holds the new pool properties
        Throws:
        PoolingException - if the pool resizing fails
      • reconfigureSteadyPoolSize

        protected void reconfigureSteadyPoolSize​(int oldSteadyPoolSize,
                                                 int newSteadyPoolSize)
                                          throws PoolingException
        Throws:
        PoolingException
      • switchOnMatching

        public void switchOnMatching()
        Switch on matching of connections in the pool.
        Specified by:
        switchOnMatching in interface ResourcePool
      • getPoolInfo

        public PoolInfo getPoolInfo()
        query the name of this pool. Required by monitoring
        Specified by:
        getPoolInfo in interface ResourcePool
        Returns:
        the name of this pool
      • dumpPoolStatus

        public void dumpPoolStatus()
        This method can be used for debugging purposes
      • getResizeQuantity

        public int getResizeQuantity()
        Description copied from interface: PoolProperties
        gets the resize quantity of the pool
        Specified by:
        getResizeQuantity in interface PoolProperties
        Returns:
        resize quantity
      • getIdleTimeout

        public long getIdleTimeout()
        Description copied from interface: PoolProperties
        gets the idle connection timeout value
        Specified by:
        getIdleTimeout in interface PoolProperties
        Returns:
        idle timeout value
      • getWaitQueueLength

        public int getWaitQueueLength()
        Description copied from interface: PoolProperties
        gets the current wait queue length
        Specified by:
        getWaitQueueLength in interface PoolProperties
        Returns:
        wait queue length
      • setMaxPoolSize

        public void setMaxPoolSize​(int size)
        Description copied from interface: ResourcePool
        Sets the max-pool-size value for this pool. This attribute is expected to be set by the self-management framework for an optimum max-pool-size. The corresponding accessor gets this value.
        Specified by:
        setMaxPoolSize in interface ResourcePool
        Parameters:
        size - - The new max-pool-size value
        See Also:
        ResourcePool.getMaxPoolSize()
      • setSteadyPoolSize

        public void setSteadyPoolSize​(int size)
        Description copied from interface: ResourcePool
        Sets the steady-pool-size value for this pool. This attribute is expected to be set by the self-management framework for an optimum steady-pool-size. The corresponding accessor gets this value.
        Specified by:
        setSteadyPoolSize in interface ResourcePool
        Parameters:
        size - - The new steady-pool-size value
        See Also:
        ResourcePool.getSteadyPoolSize()
      • setSelfManaged

        public void setSelfManaged​(boolean selfManaged)
        Description copied from interface: ResourcePool
        Sets/Resets the flag indicating if this pool is self managed. This method would be typically called by the self management framework to indicate to the world (and this pool) that this pool is self managed. Its very important that the self mgmt framework properly sets this flag to control the dynamic reconfig behavior of this pool. If this flag is set to true, all dynamic reconfigs affecting the max/steady pool size of this pool will be ignored.
        Specified by:
        setSelfManaged in interface ResourcePool
        Parameters:
        selfManaged - - true to switch on self management, false otherwise
      • isSelfManaged

        protected boolean isSelfManaged()
      • getPoolStatus

        public PoolStatus getPoolStatus()
        Get Connection Pool status by computing the free/used values of the connections in the pool. Computations are based on whether the pool is initialized or not when this method is invoked.
        Specified by:
        getPoolStatus in interface ResourcePool
        Returns:
        PoolStatus object