In this post under Apache Pool, I will explain with example how to retrieve number of active and idle objects in object pool. For our example I will create the below factory class which extends Apache Pool’s “BasePooledObjectFactory” class. package package5;import org.apache.commons.pool2.BasePooledObjectFactory;import org.apache.commons.pool2.PooledObject;import org.apache.commons.pool2.impl.DefaultPooledObject;public class ThreadPooledObjectFactory extends BasePooledObjectFactory<Thread> { private int count = 0; @Override…… Continue reading Getting number of active and idle objects in object pool
Setting startup timeout
In this post under TestContainers, I will show with example how to setup startup timeout. Whenever we start a container whether through programmatically or through Docker Desktop or any other container management software, it takes time to start. TestContainers to figure out whether a container has started or not, it waits for 60 sec so…… Continue reading Setting startup timeout
Retrieve environment values present in file
In previous posts under DotEnv, whenever we called static “load” method on “DotEnv” class it used to load system environment values in addition to environmentvalues present in .env or .env file with custom name. What if we want only the environment values present in the file and not the system environment values. There is way…… Continue reading Retrieve environment values present in file
Accessing an non existing environment key
In this post under DotEnv, I will show with example how to handle retrieving values of environment keys that doesn’t exist. Below is the main class for your reference. Main class 1 package defaultPackage;2 3 import io.github.cdimascio.dotenv.Dotenv;4 5 public class Example6 {6 public static void main(String[] args) {7 Dotenv dotenv = Dotenv.load();8 String value =…… Continue reading Accessing an non existing environment key
Using @Value example
In all my previous posts under Lombok, I used Pojo classes as an example. All these Pojo classes are mutable since they have setter and getter method. In this post, I will show with example how to create an immutable class. To create an immutable class, we annotate a Pojo class with “@Value” annotation and…… Continue reading Using @Value example
Using @Getter(lazy=true) example
In this post under Lombok, I will explain with example the purpose of “@Getter(lazy=true)” annotation. In many cases, the values of Pojo class instance variables are fixed. In some cases, these values have to be computed at runtime. We can add a getter method which when called first time, will compute the value once and…… Continue reading Using @Getter(lazy=true) example
Changing scopes to @Component annotated class
In this post under Spring Core, I will show with example how to change the scope of class annotated with “@Component” annotation. By default whenever we annotate a class with “@Component” annotation the scope of the bean is set to “singleton”. We can change this by the help of “@Scope” annotation which is also applied…… Continue reading Changing scopes to @Component annotated class
Generating an TOTP
In this post I will show with example how to generate TOTP. TOTP is based on HOTP but instead of using counter, TOTP uses the current time as the counter in addition to secret key So TOTP = HOTP(secret key, current time). Similar to HOTP in client server scenario both client and server has to…… Continue reading Generating an TOTP
Changing the hotp length
Under OTP, I showed with example how to generate an hotp. By default the length of the hotp generated will be 6. We can change that to any number between 6 and 8. In this post under OTP, I will show with example how to change hotp length to 8. Below is the complete main…… Continue reading Changing the hotp length
Verifying the HOTP
In this post, I will show with example how to verify HOTP. In my previous posts, under OTP I showed with example how to generate HOTP. To verify an HOTP we can use non-static overloaded “verify” methods in “HOTP” class. Below is the complete code for your reference. Main Class 1 package defaultPackage;2 3 import…… Continue reading Verifying the HOTP