public class CipherPool
extends java.lang.Object
maxPoolSize
to minimize waiting time.Modifier and Type | Field and Description |
---|---|
private java.util.LinkedList<javax.crypto.Cipher> |
availableCiphers |
private int |
currentPoolSize |
private int |
maxPoolSize |
Constructor and Description |
---|
CipherPool()
Creates a new cipher pool with a pool size of
Runtime.availableProcessors() . |
CipherPool(int maxPoolSize)
Creates a new cipher pool with a given pool size.
|
Modifier and Type | Method and Description |
---|---|
int |
getMaxPoolSize() |
void |
offerCipher(javax.crypto.Cipher cipher)
Offers a Cipher to the pool (thus returns it to the pool).
|
javax.crypto.Cipher |
reuseCipher()
Gets a Cipher from the pool.
|
private java.util.LinkedList<javax.crypto.Cipher> availableCiphers
private int maxPoolSize
private int currentPoolSize
public CipherPool()
Runtime.availableProcessors()
.public CipherPool(int maxPoolSize)
maxPoolSize
- the maximum number of ciphers in the pool.public int getMaxPoolSize()
public javax.crypto.Cipher reuseCipher() throws javax.crypto.NoSuchPaddingException, java.security.NoSuchAlgorithmException
offerCipher(Cipher)
when one of its Cipher.doFinal()
methods have been called and it is not needed anymore.null
if the pool currently does not contain any
cipher.javax.crypto.NoSuchPaddingException
java.security.NoSuchAlgorithmException
public void offerCipher(javax.crypto.Cipher cipher)
cipher
- a Cipher instance previously acquired by reuseCipher()
or created externally.