List of usage examples for org.apache.commons.pool.impl StackObjectPool StackObjectPool
public StackObjectPool(final PoolableObjectFactory factory)
From source file:com.lfv.yada.net.PacketPool.java
private PacketPool() { // Create a logger for this class log = LogFactory.getLog(getClass()); pool = new StackObjectPool(new BasePoolableObjectFactory() { public Object makeObject() throws Exception { return new Packet(PACKET_LENGTH); }// ww w.ja v a 2 s . c o m }); //debugList = new LinkedList<DebugEntry>(); }
From source file:com.stainlesscode.mediapipeline.EngineRuntime.java
/** * This method is to be called AFTER the coders have been setup and opened. *//*from www. j ava2 s .c o m*/ public void init() { // FIXME support audio-only files if (this.videoCoder == null) { throw new RuntimeException("No suitable video decoder could be loaded"); } // if (engine.getEngineConfiguration().getConfigurationValueAsBoolean( // EngineConfiguration.USE_OBJECT_POOLS)) { if (videoCoder != null) { this.rawPicturePool = new StackObjectPool(new IVideoPictureObjectPoolFactory( this.videoCoder.getPixelType(), this.videoCoder.getWidth(), this.videoCoder.getHeight())); } // FIXME buffer size important? probably. if (audioCoder != null) { this.audioSamplePool = new StackObjectPool( new IAudioSamplesObjectPoolFactory(1024, audioCoder.getChannels())); } this.resampledPicturePool = new StackObjectPool( new IVideoPictureObjectPoolFactory(this.resampler.getOutputPixelFormat(), this.resampler.getOutputWidth(), this.resampler.getOutputHeight())); this.packetPool = new SoftReferenceObjectPool(new IPacketObjectPoolFactory()); // } }
From source file:com.savoirtech.jaxb.engine.JaxbEngineProvider.java
private void initEngine() { try {// w ww . ja v a 2 s . c om // Introduce the additional JAXBIntros //JaxbIntros config = IntroductionsConfigParser.parseConfig(JaxbEngineProvider.class.getResourceAsStream(jaxbIntroFile)); //IntroductionsAnnotationReader reader = new IntroductionsAnnotationReader(config); //Map<String, Object> jaxbConfig = new HashMap<String, Object>(); //jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader); String[] packages = packageList.split(","); for (String pkg : packages) { Class clazz = Class.forName(pkg.trim() + ".ObjectFactory"); sizableContextClassesList.add(clazz); } //sizableContextClassesList.add(ExceptionReportMsg.class); jaxbContext = JAXBContext.newInstance(getContextClasses()); } catch (JAXBException e) { LOG.error("Cannot initialize the master JAXB Context : ", e); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } //Setup the pooling ObjectPool marshallPool = new StackObjectPool(new MarshallerPool(jaxbContext)); marshaller = new PooledMarshaller(PoolUtils.erodingPool(marshallPool)); ObjectPool unMarshallPool = new StackObjectPool(new UnmarshallerPool(jaxbContext)); unMarshaller = new PooledUnmarshaller(PoolUtils.erodingPool(unMarshallPool)); }
From source file:com.tkmtwo.sarapi.AbstractArsUserSource.java
/** * @see InitializingBean#afterPropertiesSet() *///w w w . j av a2 s . c o m @Override public void afterPropertiesSet() { //Assert.isTrue(!getArsContexts().isEmpty(), "Need some ArsContexts."); checkState(!getArsContexts().isEmpty(), "Need some ArsContexts."); if (getArsEnvironmentName() == null) { setArsEnvironmentName(Joiner.on(",").join(getArsContextHostNames())); } logger.debug("Creating ARServerUserFactory."); userPool = new StackObjectPool<ARServerUser>(new ARServerUserFactory(getArsEnvironmentName(), getArsContexts(), getUserName(), getUserPassword(), getLocale(), getTimeZone(), getCustomDateFormat(), getCustomTimeFormat(), getImpersonatedUser())); }
From source file:com.mijao.poc.jaxb.JaxbEngineProvider.java
private void initEngine() { try {//from w w w . ja v a 2 s . co m // Introduce the additional JAXBIntros //JaxbIntros config = IntroductionsConfigParser.parseConfig(JaxbEngineProvider.class.getResourceAsStream(jaxbIntroFile)); //IntroductionsAnnotationReader reader = new IntroductionsAnnotationReader(config); //Map<String, Object> jaxbConfig = new HashMap<String, Object>(); //jaxbConfig.put(JAXBRIContext.ANNOTATION_READER, reader); String[] packages = packageList.split(","); for (String pkg : packages) { Class clazz = Class.forName(pkg.trim() + ".ObjectFactory"); sizableContextClassesList.add(clazz); } //sizableContextClassesList.add(ExceptionReportMsg.class); jaxbContext = JAXBContext.newInstance(getContextClasses()); } catch (JAXBException e) { logger.error("Cannot initialize the master JAXB Context : ", e); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(cnfe); } //Setup the pooling ObjectPool marshallPool = new StackObjectPool(new MarshallerPool(jaxbContext)); marshaller = new PooledMarshaller(PoolUtils.erodingPool(marshallPool)); ObjectPool unMarshallPool = new StackObjectPool(new UnmarshallerPool(jaxbContext)); unMarshaller = new PooledUnmarshaller(PoolUtils.erodingPool(unMarshallPool)); }
From source file:gov.nih.nci.firebird.proxy.PoolingHandlerTest.java
@Test public void testPoolUse() throws Exception { PoolableObjectFactory<Object> factory = makeMockFactory(); ObjectPool<Object> pool = spy(new StackObjectPool<Object>(factory)); InvocationHandler handler = new PoolingHandler(pool); ITestClient proxy = (ITestClient) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { ITestClient.class }, handler); proxy.doSomethingUseful(null);// w w w . j a v a 2 s . c om verify(pool, times(1)).borrowObject(); verify(pool, times(1)).returnObject(any()); }
From source file:gov.nih.nci.firebird.proxy.PoolingHandlerTest.java
@Test public void testExpectedSuperExceptionHandeling() throws Exception { PoolableObjectFactory<Object> factory = makeMockFactory(); ObjectPool<Object> pool = spy(new StackObjectPool<Object>(factory)); PoolingHandler handler = new PoolingHandler(pool); handler.getValidExceptions().add(RuntimeException.class); assertTrue(new IllegalArgumentException() instanceof RuntimeException); ITestClient proxy = (ITestClient) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { ITestClient.class }, handler); try {/* www . j av a 2 s .co m*/ proxy.doSomethingBad(0); fail(); } catch (IllegalArgumentException ex) { } verify(pool, times(1)).borrowObject(); verify(pool, times(1)).returnObject(any()); verify(factory, times(0)).destroyObject(any()); }
From source file:gov.nih.nci.firebird.proxy.PoolingHandlerTest.java
@Test public void testExpectedSubExceptionHandling() throws Exception { PoolableObjectFactory<Object> factory = makeMockFactory(); ObjectPool<Object> pool = spy(new StackObjectPool<Object>(factory)); PoolingHandler handler = new PoolingHandler(pool); class SubException extends IllegalArgumentException { private static final long serialVersionUID = 1L; }/*from w w w. j a va 2 s . c om*/ handler.getValidExceptions().add(SubException.class); ITestClient proxy = (ITestClient) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { ITestClient.class }, handler); try { proxy.doSomethingBad(0); fail(); } catch (IllegalArgumentException ex) { } verify(pool, times(1)).borrowObject(); verify(pool, times(0)).returnObject(any()); verify(factory, times(1)).destroyObject(any()); }
From source file:org.alinous.plugin.derby.DerbyDataSource.java
public void init(AlinousCore core) throws DataSourceException { try {//from www .j av a 2s. co m driver = (Driver) Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); } catch (ClassNotFoundException e) { throw new DataSourceException(e); } catch (InstantiationException e) { throw new DataSourceException(e); } catch (IllegalAccessException e) { throw new DataSourceException(e); } this.factory = new DerbyConnectionFactory(this.driver, this.user, this.pass, this.uri); this.connectionPool = new StackObjectPool(this.factory); this.typeHelper = new TypeHelper(this); this.core = core; }
From source file:org.azkfw.persistence.database.DatabaseSource.java
/** * ???//ww w .ja va2 s. c o m * * @throws ClassNotFoundException ??????? */ private void pooling() throws ClassNotFoundException { Class.forName(entity.getDriver()); PoolableObjectFactory<Connection> factory = new SimpleConnectionFactory(entity.getUri(), entity.getUser(), entity.getPassword()); pool = new StackObjectPool<Connection>(factory); }