Package com.sun.enterprise.resource

Examples of com.sun.enterprise.resource.ResourceHandle


     * @param resourceAllocator ResourceAllocator
     * @return ResourceHandle newly created resource
     * @throws PoolingException when unable create a resource
     */
    protected ResourceHandle createSingleResource(ResourceAllocator resourceAllocator) throws PoolingException {
        ResourceHandle resourceHandle;
        int count = 0;
        long startTime = 0;
        while (true) {
            try {
                count++;
                startTime = System.currentTimeMillis();
                resourceHandle = resourceAllocator.createResource();
                if(_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Time taken to create a single "
                            + "resource : "
                            + resourceHandle.getResourceSpec().getResourceId()
                            + " and adding to the pool (ms) : "
                            + (System.currentTimeMillis() - startTime));
                }
                if (validation || validateAtmostEveryIdleSecs)
                    resourceHandle.setLastValidated(System.currentTimeMillis());
                break;
            } catch (Exception ex) {
                if(_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, "Connection creation failed for " + count + " time. It will be retried, "
                        + "if connection creation retrial is enabled.", ex);
View Full Code Here


    }


    public ResourceHandle createResource(ResourceAllocator alloc) throws PoolingException {
        //NOTE : Pool should not call this method directly, it should be called only by pool-datastructure
        ResourceHandle result = createSingleResource(alloc);

        ResourceState state = new ResourceState();
        state.setBusy(false);
        state.setEnlisted(false);
        result.setResourceState(state);

        if (poolLifeCycleListener != null) {
            poolLifeCycleListener.connectionCreated();
        }
        return result;
View Full Code Here

    public void emptyFreeConnectionsInPool() {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, "Emptying free connections in pool : " + poolInfo);
        }

        ResourceHandle h;
        while ((h = ds.getResource()) != null) {
            ds.removeResource(h);
        }
    }
View Full Code Here

     * be called
     */
    private void killExtraResources(int numToKill) {
        cancelResizerTask();

        ResourceHandle h;
        for (int i = 0; i < numToKill && ((h = ds.getResource()) != null); i++) {
            ds.removeResource(h);
        }
        scheduleResizerTask();
    }
View Full Code Here

        int numResAdded = 0;
        writeLock.lock();
        //for now, coarser lock. finer lock needs "resources.size() < maxSize()" once more.
        try {
            for (int i = 0; i < count && resources.size() < maxSize; i++) {
                ResourceHandle handle = handler.createResource(allocator);
                resources.add(handle);
                numResAdded++;
            }
        } catch (Exception e) {
            PoolingException pe = new PoolingException(e.getMessage());
View Full Code Here

     * {@inheritDoc}
     */
    public ResourceHandle getResource() {
        readLock.lock();
        for(int i=0; i<resources.size(); i++){
            ResourceHandle h = resources.get(i);
            if (!h.isBusy()) {
                readLock.unlock();
                writeLock.lock();
                try {
                    if (!h.isBusy()) {
                        h.setBusy(true);
                        return h;
                    } else {
                        readLock.lock();
                        continue;
                    }
View Full Code Here

        int free = 0;
        readLock.lock();
        try{
            Iterator it = resources.iterator();
            while (it.hasNext()) {
                ResourceHandle rh = (ResourceHandle)it.next();
                if(!rh.isBusy()){
                    free++;
                }
            }
        }finally{
            readLock.unlock();
View Full Code Here

        if (set == null) return delistedResources;

        Iterator iter = set.iterator();
        while (iter.hasNext()) {
            ResourceHandle resource = (ResourceHandle) iter.next();
            ResourceState state = resource.getResourceState();
            state.setEnlisted(false);
            delistedResources.add(resource);
            iter.remove();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "Pool: transactionCompleted: " + resource);
View Full Code Here

        int numResAdded = 0;
        for (int i = 0; i < count && resources.size() < maxSize; i++) {
            boolean lockAcquired = dynSemaphore.tryAcquire();
            if(lockAcquired) {
                try {
                    ResourceHandle handle = handler.createResource(allocator);
                    synchronized (resources) {
                        synchronized (free) {
                            free.add(handle);
                            resources.add(handle);
                            numResAdded++;
View Full Code Here

     * get a resource from the datastructure
     *
     * @return ResourceHandle
     */
    public ResourceHandle getResource() {
        ResourceHandle resource = null;
        if (strategy != null) {
            resource = strategy.retrieveResource();
        } else {
            synchronized (free) {
                if (free.size() > 0){
View Full Code Here

TOP

Related Classes of com.sun.enterprise.resource.ResourceHandle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.