List of usage examples for org.springframework.integration.util SimplePool SimplePool
public SimplePool(int poolSize, PoolItemCallback<T> callback)
From source file:org.springframework.integration.file.remote.session.CachingSessionFactory.java
/** * Create a CachingSessionFactory with the specified session limit. By default, if * no sessions are available in the cache, and the size limit has been reached, * calling threads will block until a session is available. * @see #setSessionWaitTimeout(long)/*w ww . j av a 2 s . co m*/ * @see #setPoolSize(int) * @param sessionFactory the underlying session factory. * @param sessionCacheSize the maximum cache size. */ public CachingSessionFactory(SessionFactory<F> sessionFactory, int sessionCacheSize) { this.sessionFactory = sessionFactory; this.pool = new SimplePool<Session<F>>(sessionCacheSize, new SimplePool.PoolItemCallback<Session<F>>() { public Session<F> createForPool() { return CachingSessionFactory.this.sessionFactory.getSession(); } public boolean isStale(Session<F> session) { return !session.isOpen(); } public void removedFromPool(Session<F> session) { session.close(); } }); }
From source file:org.springframework.integration.ip.tcp.connection.CachingClientConnectionFactory.java
public CachingClientConnectionFactory(AbstractClientConnectionFactory target, int poolSize) { super("", 0); // override single-use to true to force "close" after use target.setSingleUse(true);// w w w . ja v a 2 s .co m this.targetConnectionFactory = target; pool = new SimplePool<TcpConnectionSupport>(poolSize, new SimplePool.PoolItemCallback<TcpConnectionSupport>() { public TcpConnectionSupport createForPool() { try { return targetConnectionFactory.getConnection(); } catch (Exception e) { throw new MessagingException("Failed to obtain connection", e); } } public boolean isStale(TcpConnectionSupport connection) { return !connection.isOpen(); } public void removedFromPool(TcpConnectionSupport connection) { connection.close(); } }); }