Observability Done Right: Best Practices and Anti-Patterns for Effective System Monitoring

Image
  WHAT Observability is a concept that refers to the ability to gain insights into the behavior and performance of complex systems. In the context of software engineering, observability involves the collection, analysis, and visualization of data from software applications, infrastructure, and other components of a system. In the animal kingdom, observability plays a critical role in survival, allowing animals to monitor their surroundings, detect threats, and find food. Dolphins use echolocation to observe their surroundings. They emit high-frequency sounds that bounce off objects, allowing them to create a 3D map of their environment. Thanks for reading Knowledge Cafe! Subscribe for free to receive new posts and support my work. Subscribed WHY In today's era, architectures are becoming increasingly large, complex, and fast-paced due to the faster development and deployment of software by distributed teams with the help of DevOps, continuous delivery, and agile development methodo...

Singleton Collection Classes



Singletons are useful to provide a unique source of data or functionality to other Java Objects. Collection framework provides singleton classes for each collection class like SingletonList and SingletonMap.  
In this article we will discuss about SingletonList which is equally applicable to other singleton collection classes.

Collections Class provide method to convert normal list into singletonList like below syntax,
List<String> mySingletonList = Collections.singletonList("AAA");

Java documentation says "Returns an immutable list containing only the specified object. The returned list is serializable."

Why we need this type single object Immutable list?


Below is the code to remove all null values from list - in conventional style:

package singleton;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SingletonListTest {

	public static void main(String[] args) {
		List <String> myList = new ArrayList<String>(){
		{add("a"); add(null); add("c"); add(null);}};

		System.out.println("Original List" + myList);
		//Creating nullObject List to provide to removeAll method
                List<String> nullList = new ArrayList<String>();
		nullList.add(null);

		System.out.println(myList.removeAll(nullList));
		System.out.println("Modified List" + myList);
	}
}

Output:
Original List[a, null, c, null]
true
Modified List[a, c]

In above code

  • we created an empty list object

  • add an null element to it, and

  • passed it to removeAll method argument.


We can solve the problem with below one line change..

package singleton;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class SingletonListTest {

	public static void main(String[] args) {
		List <String> myList = new ArrayList<String>(){
		{add("a"); add(null); add("c"); add(null);}};

		System.out.println("Original List" + myList);
		System.out.println(myList.removeAll(Collections.singleton(null)));
		System.out.println("Modified List" + myList);	
	}
}

Output: Same as above.

Hope this is helpful article. Happy coding.

Popular posts from this blog

Chain of responsibility using Spring @Autowired List

Iterate Through a HashMap

Under the Hood: Understanding the Gossip Protocol in Apache Cassandra