- java.lang.Object
-
- org.snmp4j.security.CipherPool
-
public class CipherPool extends 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
- Author:
- Frank Fock
-
-
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(Cipher cipher)
Offers a Cipher to the pool (thus returns it to the pool).Cipher
reuseCipher()
Gets a Cipher from the pool.
-
-
-
Constructor Detail
-
CipherPool
public CipherPool()
Creates a new cipher pool with a pool size ofRuntime.availableProcessors()
.
-
CipherPool
public CipherPool(int maxPoolSize)
Creates a new cipher pool with a given pool size.- Parameters:
maxPoolSize
- the maximum number of ciphers in the pool.
-
-
Method Detail
-
getMaxPoolSize
public int getMaxPoolSize()
-
reuseCipher
public 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(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.
-
-