/** * Shutdown the session factory. */ public void shutdown() { try { PooledSession curr; if (replyCapableSessionCache != null) { curr = replyCapableSessionCache.poll(); while (curr != null) { curr.close(); curr = replyCapableSessionCache.poll(); } } if (sendOnlySessionCache != null) { curr = sendOnlySessionCache.poll(); while (curr != null) { curr.close(); curr = sendOnlySessionCache.poll(); } } theConnection.close(); } catch (JMSException e) { LOG.log(Level.WARNING, "queue connection close failed: " + e); } // help GC // replyCapableSessionCache = null; sendOnlySessionCache = null; }
/** * Populate the cache */ public void populateCache() throws Exception { // create cache primaryCache = new LinkedList<E>(); secondaryCache = new LinkedList<SoftReference<E>>(); // preallocate objects into primary cache int primaryCachePreallocation = (preallocation > primaryCacheSize) ? primaryCacheSize : preallocation; for (int i = 0; i < primaryCachePreallocation; i++) { primaryCache.offer(create()); } // preallocate objects into secondary cache int secondaryCachePreallocation = preallocation - primaryCachePreallocation; for (int i = 0; i < secondaryCachePreallocation; i++) { secondaryCache.offer(new SoftReference<E>(create())); } }
/** * Return a Session to the pool * * @param pooled_session the session to recycle */ public void recycle(PooledSession pooledSession) { // sessions used long-term by the server receive side are not cached, // only non-null destinations are temp queues final boolean replyCapable = pooledSession.destination() != null; boolean discard = false; synchronized (this) { // re-cache session, closing if it cannot be it can be accomodated // discard = replyCapable ? (!replyCapableSessionCache.recycle(pooledSession)) : (!sendOnlySessionCache.recycle(pooledSession)); } if (discard) { try { pooledSession.close(); } catch (JMSException e) { LOG.log(Level.WARNING, "JMS Session discard failed: " + e); } } }
replyCapableSessionCache.populateCache(); } catch (Throwable t) { LOG.log(Level.FINE, "JMS Session cache populate failed: " + t); sendOnlySessionCache.populateCache(); } catch (Throwable t) { LOG.log(Level.FINE, "JMS Session cache populate failed: " + t); sendOnlySessionCache.populateCache(); } catch (Throwable t) { LOG.log(Level.FINE, "JMS Session cache populate failed: " + t);