- java.lang.Object
-
- org.snmp4j.security.CipherPool
-
public class CipherPool extends java.lang.Object
The CipherPool class provides service to share and reuse Cipher instances, across different threads. The maximum number of Ciphers in the pool might temporarily exceed themaxPoolSize
to minimize waiting time.- Since:
- 2.2.2
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<javax.crypto.Cipher>
availableCiphers
private int
currentPoolSize
private int
maxPoolSize
-
Constructor Summary
Constructors Constructor Description CipherPool()
Creates a new cipher pool with a pool size ofRuntime.availableProcessors()
.CipherPool(int maxPoolSize)
Creates a new cipher pool with a given pool size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
getMaxPoolSize
public int getMaxPoolSize()
-
reuseCipher
public javax.crypto.Cipher reuseCipher()
Gets a Cipher from the pool. It must be returned to the pool by callingofferCipher(Cipher)
when one of itsCipher.doFinal()
methods have been called and it is not needed anymore.- Returns:
- a Cipher from the pool, or
null
if the pool currently does not contain any cipher.
-
offerCipher
public void offerCipher(javax.crypto.Cipher cipher)
Offers a Cipher to the pool (thus returns it to the pool).- Parameters:
cipher
- a Cipher instance previously acquired byreuseCipher()
or created externally.
-
-