Skip to main content

Tech Conversant Weekly May 22 - Jun 03

Topic: General                                                                                                                Level: All

Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered.

Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences.

This time, we've got some exciting news to share with you!

With enhancements on switch expressions and patterns in switch, dealing with exhaustive switch cases both at the compile time and runtime constructs can get deceptive.
Having sealed types partially addresses the exhaustiveness of the switch by ensuring type conformity and as with Records patterns and their nesting their component associated also defines the exhaustiveness nature.
Patterns are exhaustive for a type:
1. A set of patterns containing a type pattern T t is exhaustive for T and any of its subtypes;
2. A set of patterns is exhaustive for a sealed type if it is exhaustive for its permitted direct subtypes;
3. A set of patterns containing a record pattern R(P) is exhaustive for R if P is exhaustive for the component type of R; and
4.A set of patterns containing the record patterns R(P0) .. R(Pn) is exhaustive for R if the set of patterns P0..Pn is exhaustive for R’s component type.

With Spring Boot 3.1 for running external services in the local development environment support for the Testcontainers and Docker Compose are enhanced.
The Testcontainers can be utilized for both running the tests and launching the application by specifying the TestConfiguration annotated class defining the testcontainers that are required to be bootstrapped.
By defining a docker-compose yml file with the container details in the project, Spring boot identifies the same if present, and while running the application with compose command all the relevant container image definitions in the docker-compose file are started during the application startup

The low-level constructs of System.currentTimeMillis() and System.nanoTime() in measuring the time lapsed between the sequence of events.
Inspecting closely the native implementation of currentTimeMillis() and nanoTime() uses gettimeofday() and clock_gettime() monotonic clock(if available) respectively, the Linux kernel functions.
The glibc–Linux kernel transition: normally when a process calls a Linux kernel function – also known as a syscall – it involves a switch from user mode to kernel mode and back.
Virtual Dynamic Shared Object vDSO - shortcut to avoid transitions maps them into a process’s address space and this implementation resides in the native platform code implementation where the performance deviates.

Entity relationship association with Many-to-Many mapping abstracts the intermediate table creation with annotation specification.
However, the need to add additional attributes to the intermediate table association raises questions about the primary key and 2 foreign keys definition for the associated entities.
Defining the intermediate association as an Entity with an Embeddable type encompassing the foreign key of both the associations and utilizing it as an EmbeddedId and performing Many-to-One mapping with MapsId of referenced entities solves the key mapping problem and enables to treat it as another entity where extra data attributes can be added.

With JDK21, JFR provides a view command for visualizing the data in the shell terminal without dumping it into a record file or using the JDK mission control for analysis.
1. Start flight recording of the jar application
2. With jcmd and the PID of the jar application run JFR.view
Multiple attributes can be passed after the view command for, (use $ jcmd 37417 JFR.view)
1. Environment views
2. JVM views
3. Application views
The tabulated output can further be formatted for the data representation,
Further, the JFR view can be executed against a jfr recording file
jfr view -help can offer detailed info about the usage 

Spring Data JPA repository provides default methods and their implementation details via the SimpleJpaRepository class. The application custom repository that implements JpaRepository inherits these method implementations. 
1. findById 
- from CrudRepository from Spring Data and parent of JpaRepository 
- SimpleJpaRepository provides implementation details 
- uses entitymanager find method (thus enabling L1 and L2 cache) to fetch based on primary key - further facilitates by defining Optimistic/Pessimistic Locks for concurrent modification of retrieved entity 
- EntityGraph to provide association initialization on fetching 
2. getOne/getById 
- deprecated 
- internally uses getReferenceById 
- gets domain reference 
- If the entity is not managed, Hibernate instantiates a proxy object and initializes the primary key attribute 
- similar to an uninitialized, lazily-fetched association that gives you a proxy object
3. findOne 
- QueryByExampleExecutor interface 
- find entity object that matches the example configuration with the predicates for attributes in the WHERE clause 
- Specification Object 
- defines the part of the WHERE clause 
- enable you to find entity objects by non-primary key attributes and define queries of any complexity.

 Java Records can be used in place of DTOs functioning as a query result object used in CriteriaBuilder API to create queries of the record type, and can also be used as a response entity holding the entity details without requiring to do a mapping from entity object to POJO.

Confining certain application endpoint access while allowing other management endpoints can be performed by implementing a SecurityFilterChain bean on EnableWebSecurity annotated configuration class that proxy intercepts the HTTP requests.
This filter setup takes in a bean of type RequestHeaderAuthenticationFilter that defines,
1. PrincipalRequestHeader - header token to be used for authentication (Principal Object)
2. AuthenticationRequestMatcher - to match the endpoints to apply the filter 
3. AuthenticationManager - Custom Authentication provider bean, that overrides the authenticate method and implements the logic for authentication returning the PreAuthenticatedAuthenticationToken object that can be treated as a user for role-based authorization

Initializer blocks in Java help to preprocess the context of the class that is being instantiated. The instance initializer block of a class will be invoked whenever there is an instance creation for the class and these blocks are executed in the order of their definition.
Emphasis on class variable access inside the instance blocks, namely forward field references can accomplish a write to the field but does not read (as it would violate declare before reading rule). 
On the contrary, writes are allowed on the fields to those declared outside the instance block, but the initial reads should use the 'this' keyword. 
And if there are any writes to the fields without the 'this' reference then the fields become local to the block and subsequent reads with the 'this' will refer to the local block initialized value.

An instance initializer block can be used to factor out common initialization code that will be executed regardless of which constructor is invoked. A typical usage of an instance initializer block is in anonymous classes, which cannot declare constructors but can instead use instance initializer blocks to initialize fields.

Generating artifacts for Spring Boot 3 applications with Gradle task definitions

On securing the REST API endpoints, here explore the details on API Key usage and prompting on other available options such as Basic authentication, JWT and OAuth2-based tokens. GenericFilterBean which is a spring-aware implementation and overrides doFilter as a proxy for interception of the REST API request to the application and registers the authentication details from the request to the security-context. AbstractAuthenticationToken class implementation provides the details for fetching the secret and principal from the request object. We can also configure a bean object SecurityFilterChain with security details and specify the filter definition

Extending the actuator support for non-Spring Boot-based applications, so that we can get the Observability benefits is possible by dependency spring-boot-actuator-autoconfigure instead of the starter actuator dependency, with this, we can auto-configure the application with properties. The auto-configuration classes of the Actuator use configuration properties. For example, WebEndpointAutoConfiguration uses WebEndpointProperties that are mapped to properties with the “management.endpoints.web” prefix. Also, the annotation EnableAutoConfiguration will be required

Hibernate ORM release 6.2.4

Design document - Nullability and Value Types

Disclaimer: 
This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in a professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual. All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
Downloadable Files and ImagesAny downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.
  • Comments are welcome. However, the blog owner reserves the right to edit or delete any comments submitted to this blog without notice due to :
  • Comments deemed to be spam or questionable spam.
  • Comments including profanity.
  • Comments containing language or concepts that could be deemed offensive.
  • Comments containing hate speech, credible threats, or direct attacks on an individual or group.
The blog owner is not responsible for the content in the comments. This blog disclaimer is subject to change at any time.

Comments

Popular posts from this blog

Tech Conversant Weekly Jul 03 - Jul 15

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Boosting Java startup with Class Data Sharing (CDS) https://www.youtube.com/watch?v=vvlQv1Dh-HU JDK21 LTS Maintenance and Support https://www.youtube.com/watch?v=3bfR22iv8Pc Health checking of multiple cloud applications with Spring Cloud Gateway https://spring.io/blog/2023/07/05/active-health-check-strategies-with-spring-cloud-gateway Functional Style Non-reactive HTTP clie

Tech Conversant Weekly Jun 19 - Jul 01

Topic: General                                                                                                                                              Level: All Welcome to the world of cutting-edge technology! Every bi-week, we bring you the latest and most incredible advancements in the tech industry that are sure to leave you feeling inspired and empowered. Stay ahead of the game and be the first to know about the newest innovations shaping our world. Discover new ways to improve your daily life, become more efficient, and enjoy new experiences. This time, we've got some exciting news to share with you! Modelling common behaviors between the List and the Set interface has been partially provided by LinkedHashSet. Now from JDK21 with the new interface SequencedCollection extending the Collection interface and is also extended by the List, SortedSet via SequencedSet (for reversal operation), Deque. The SequencedMap interface extends the Map interface by providing the below me

Microservices - Design Patterns

Topic: Software Design                                                                                                        Level: Intermediate Microservices - What? Microservice is a software design methodology, delegated to perform an isolated decoupled single functionality (following the Single-Responsibility Principle from object-oriented SOLID design principles).  Moreover, microservices by design, are decoupled making it easy to develop, test, maintain, deploy, configure, monitor and scale modules independently. Microservices - Why? Having one microservice would not be helpful without it being able to interact with other microservices, to aid in bringing an end-to-end business solution. So arises a question, how can I design a software system that is resilient, decentralized, fault-tolerant, scalable, maintainable, and extensible that complies with the microservice architecture? Design Patterns - What? Design patterns are solutions for commonly occurring problems within a given