Example usage for org.apache.commons.pool.impl SoftReferenceObjectPool SoftReferenceObjectPool

List of usage examples for org.apache.commons.pool.impl SoftReferenceObjectPool SoftReferenceObjectPool

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl SoftReferenceObjectPool SoftReferenceObjectPool.

Prototype

public SoftReferenceObjectPool(final PoolableObjectFactory factory) 

Source Link

Usage

From source file:com.github.chrishantha.microbenchmark.objectpool.CommonsPoolSoftReferenceObjectPoolBenchmark.java

@Override
public void setupObjectPool() {
    objectPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<TestObject>() {
        @Override//from   ww w  .j  a v a 2s  . c  om
        public TestObject makeObject() throws Exception {
            return new TestObject(true);
        }
    });
}

From source file:com.stainlesscode.mediapipeline.EngineRuntime.java

/**
 * This method is to be called AFTER the coders have been setup and opened.
 *//*from w w w. ja  v  a 2s  .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:org.fcrepo.server.security.PolicyParser.java

private PolicyParser(Schema schema) throws SAXException {
    m_validators = new SoftReferenceObjectPool<Validator>(new PoolableValidatorFactory(schema));
}

From source file:org.openrepose.common.auth.ResponseUnmarshaller.java

public ResponseUnmarshaller(JAXBContext jaxbContext) {
    this.jaxbContext = jaxbContext;
    objectPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Unmarshaller>() {

        @Override/*from   ww w  .  j ava  2 s.  c  om*/
        public Unmarshaller makeObject() {
            try {
                return ResponseUnmarshaller.this.jaxbContext.createUnmarshaller();
            } catch (JAXBException ex) {
                throw new ResourceConstructionException("Unable to build jaxb unmarshaller", ex);
            }
        }
    });
}

From source file:org.openrepose.commons.config.parser.jaxb.JaxbConfigurationParser.java

public JaxbConfigurationParser(Class<T> configurationClass, JAXBContext jaxbContext, URL xsdStreamSource) {
    super(configurationClass);
    objectPool = new SoftReferenceObjectPool<>(new UnmarshallerPoolableObjectFactory(jaxbContext,
            xsdStreamSource, configurationClass.getClassLoader()));
}

From source file:org.openrepose.commons.utils.digest.AbstractMessageDigester.java

public AbstractMessageDigester() {
    MESSAGE_DIGEST_POOL = new SoftReferenceObjectPool<>(
            new MessageDigestConstructionStrategy(digestSpecName()));
}

From source file:org.openrepose.commons.utils.transform.jaxb.AbstractJaxbTransform.java

public AbstractJaxbTransform(JAXBContext ctx) {
    jaxbContext = ctx;/*  w w w .  j ava2s  .co m*/

    marshallerPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Marshaller>() {
        @Override
        public Marshaller makeObject() {
            try {
                return jaxbContext.createMarshaller();
            } catch (JAXBException jaxbe) {
                throw new ResourceConstructionException(jaxbe.getMessage(), jaxbe);
            }
        }
    });

    unmarshallerPool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Unmarshaller>() {
        @Override
        public Unmarshaller makeObject() {
            try {
                return jaxbContext.createUnmarshaller();
            } catch (JAXBException jaxbe) {
                throw new ResourceConstructionException(jaxbe.getMessage(), jaxbe);
            }
        }
    });
}

From source file:org.openrepose.commons.utils.transform.xslt.AbstractXslTransform.java

public AbstractXslTransform(Templates transformTemplates) {
    this.transformationTemplates = transformTemplates;

    xsltResourcePool = new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Transformer>() {

        @Override/*from w  ww  .ja  v a  2 s  . c  o m*/
        public Transformer makeObject() {
            try {
                return transformationTemplates.newTransformer();
            } catch (TransformerConfigurationException configurationException) {
                throw new XsltTransformationException(
                        "Failed to generate XSLT transformer. Reason: " + configurationException.getMessage(),
                        configurationException);
            }
        }
    });
}

From source file:org.openrepose.commons.utils.transform.xslt.XsltTransformConstruction.java

public ObjectPool<Transformer> generateXsltResourcePool(final Templates transformationTemplates) {
    return new SoftReferenceObjectPool<>(new BasePoolableObjectFactory<Transformer>() {

        @Override//from   w  w w. j ava  2  s.  c  om
        public Transformer makeObject() {
            try {
                return transformationTemplates.newTransformer();
            } catch (TransformerConfigurationException configurationException) {
                throw new XsltTransformationException(
                        "Failed to generate XSLT transformer. Reason: " + configurationException.getMessage(),
                        configurationException);
            }
        }
    });
}

From source file:org.openrepose.filters.translation.TranslationFilter.java

private ObjectPool<XmlFilterChain> buildChainPool(final TranslationBase translation) {
    return new SoftReferenceObjectPool<>(
            new XmlFilterChainFactory(xsltChainBuilder, translation, configurationRoot, config));
}