/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time * @deprecated to be removed in pool 2.0 */ @Deprecated @Override public synchronized void setFactory(PoolableObjectFactory<T> factory) throws IllegalStateException { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { clear(); _factory = factory; } }
boolean success = !isClosed(); if (_factory != null) { if(!_factory.validateObject(obj)) {
/** * Returns an approximation not less than the of the number of idle instances in the pool. * * @return estimated number of idle instances in the pool */ @Override public synchronized int getNumIdle() { pruneClearedReferences(); return _pool.size(); }
assertOpen(); if (_factory == null) { throw new IllegalStateException("Cannot add objects without a factory.");
public static Document parseNamespaceAware(InputStream src) throws Exception { Document result = null; DocumentBuilder builder = (DocumentBuilder) DOCUMENT_BUILDERS.borrowObject(); try { result = builder.parse(src); } finally { DOCUMENT_BUILDERS.returnObject(builder); } return result; }
/** * <p>Close this pool, and free any resources associated with it. Invokes * {@link #clear()} to destroy and remove instances in the pool.</p> * * <p>Calling {@link #addObject} or {@link #borrowObject} after invoking * this method on a pool will cause them to throw an * {@link IllegalStateException}.</p> * * @throws Exception never - exceptions clearing the pool are swallowed */ @Override public void close() throws Exception { super.close(); clear(); }
public static void returnTransformerFactory(TransformerFactory factory) { try { TRANSFORM_FACTORIES.returnObject(factory); } catch (Exception e) { e.printStackTrace(); } }
public static DocumentBuilder borrowDocumentBuilder() throws Exception { return (DocumentBuilder) DOCUMENT_BUILDERS.borrowObject(); }
assertOpen(); T obj = null; boolean newlyCreated = false;
public static Document parseNamespaceAware(InputStream src) throws Exception { Document result = null; DocumentBuilder builder = (DocumentBuilder) DOCUMENT_BUILDERS.borrowObject(); try { result = builder.parse(src); } finally { DOCUMENT_BUILDERS.returnObject(builder); } return result; }
public void close() throws Exception { super.close(); clear(); }
public static void returnDocumentBuilder(DocumentBuilder object) { try { DOCUMENT_BUILDERS.returnObject(object); } catch (Exception e) { e.printStackTrace(); } }
/** * Convenience method to get a new instance of a TransformerFactory. * If the {@link TransformerFactory} is an instance of * net.sf.saxon.TransformerFactoryImpl, the attribute * {@link net.sf.saxon.FeatureKeys#VERSION_WARNING} will be set to false in order to * suppress the warning about using an XSLT1 stylesheet with an XSLT2 * processor. * * @return a new instance of TransformerFactory * @throws Exception */ public static TransformerFactory borrowTransformerFactory() throws Exception { return (TransformerFactory) TRANSFORM_FACTORIES.borrowObject(); }
/** * Sets the {@link PoolableObjectFactory factory} this pool uses * to create new instances. Trying to change * the <code>factory</code> while there are borrowed objects will * throw an {@link IllegalStateException}. * * @param factory the {@link PoolableObjectFactory} used to create new instances. * @throws IllegalStateException when the factory cannot be set at this time */ public synchronized void setFactory(PoolableObjectFactory factory) throws IllegalStateException { assertOpen(); if(0 < getNumActive()) { throw new IllegalStateException("Objects are already active"); } else { clear(); _factory = factory; } }
/** * Clears any objects sitting idle in the pool. */ @Override public synchronized void clear() { if(null != _factory) { Iterator<SoftReference<T>> iter = _pool.iterator(); while(iter.hasNext()) { try { T obj = iter.next().get(); if(null != obj) { _factory.destroyObject(obj); } } catch(Exception e) { // ignore error, keep destroying the rest } } } _pool.clear(); pruneClearedReferences(); }
/** * Create an object, and place it into the pool. * addObject() is useful for "pre-loading" a pool with idle objects. */ public synchronized void addObject() throws Exception { assertOpen(); if (_factory == null) { throw new IllegalStateException("Cannot add objects without a factory."); } Object obj = _factory.makeObject(); boolean success = true; if(!_factory.validateObject(obj)) { success = false; } else { _factory.passivateObject(obj); } boolean shouldDestroy = !success; if(success) { _pool.add(new SoftReference(obj, refQueue)); notifyAll(); // _numActive has changed } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
public static Transformer getTransformer(Source src) throws Exception { TransformerFactory factory = null; Transformer result = null; try { factory = TRANSFORM_FACTORIES.borrowObject(); result = (src == null) ? factory.newTransformer() : factory.newTransformer(src); } finally { if (factory != null) { try { TRANSFORM_FACTORIES.returnObject(factory); } catch (Exception e) { e.printStackTrace(); } } } return result; }
public void close() throws Exception { super.close(); clear(); }
public synchronized void returnObject(Object obj) throws Exception { boolean success = !isClosed(); if (_factory != null) { if(!_factory.validateObject(obj)) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } } boolean shouldDestroy = !success; _numActive--; if(success) { _pool.add(new SoftReference(obj, refQueue)); } notifyAll(); // _numActive has changed if (shouldDestroy && _factory != null) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
public static void returnDocumentBuilder(DocumentBuilder object) { try { DOCUMENT_BUILDERS.returnObject(object); } catch (Exception e) { e.printStackTrace(); } }