Package org.mom4j.xcp.util

Examples of org.mom4j.xcp.util.InstancePool


       
        Object[] objects = new Object[this.config.getWorkersCount()];
        for(int i = 0; i < objects.length; i++) {
            objects[i] = new XcpDocumentHandler(cfg);
        }
        this.docHandlers = new InstancePool(objects);
    }
View Full Code Here


        Integer[] ia = new Integer[num];
        for(int i = 0; i < num; i++) {
            ia[i] = new Integer(i);
        }
       
        InstancePool pool = new InstancePool(ia);
       
        Assert.assertEquals("available size of pool", num, pool.getAvailable());
       
        Integer[] integers = new Integer[num];
        for(int i = 0; i < num; i++) {
            Assert.assertEquals("loop: available size of pool #" + i,
                              num - i,
                              pool.getAvailable());
            integers[i] = (Integer)pool.getObject();
            Assert.assertEquals("loop: integer ", ia[i], integers[i]);
        }
        Assert.assertEquals("available size of pool after loop",
                           0,
                           pool.getAvailable());
       
        long t1 = System.currentTimeMillis();
        new Releaser(pool, integers[0], 3000);
        integers[0] = (Integer)pool.getObject();
        long t2 = System.currentTimeMillis();
       
        Assert.assertTrue("wait()-period", (t2 - t1) > 2500 && (t2 - t1) < 3500);
        Assert.assertEquals("object after release", integers[0], ia[0]);
        Assert.assertEquals("capacity after release", 0, pool.getAvailable());
       
    }
View Full Code Here

                //cllient side, so no logging ...
                ex.printStackTrace();
                throw new IllegalStateException(ex.getMessage());
            }
        }
        InstancePool pool = new InstancePool(objects);
       
        this.handlerMap.put(protocol, pool);
    }
View Full Code Here

    }
   
   
    public XcpHandler getXcpHandler(String protocol) {
        XcpHandler   ret  = null;
        InstancePool pool = (InstancePool)this.handlerMap.get(protocol);
        if(pool != null) {
            ret = (XcpHandler)pool.getObject();
        }
        return ret;
    }
View Full Code Here

        return ret;
    }
   
   
    public void releaseXcpHandler(String protocol, XcpHandler handler) {
        InstancePool pool = (InstancePool)this.handlerMap.get(protocol);
        if(pool != null) {
            pool.releaseObject(handler);
        }
    }
View Full Code Here

TOP

Related Classes of org.mom4j.xcp.util.InstancePool

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.