Skip to main content

Tech Conversant Weekly Mar 13 - Mar 25

Topic: General                                                                                                                Level: All

Welcome to the world of cutting-edge technology! Every 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!

Project Panama's objective is to access, manage and execute cross-platform native languages like C, and C++ via Java, which was typically done via Java Native Interface(JNI) earlier.
1. Foreign Function and Memory API - facilitates accessing foreign memory (off-heap JVM) and foreign functions (outside JVM) via MemorySession - handles MemorySegment Lifecycle (shared or confined memory regions for thread accessibilities) 
MemorySegment - handles contagious memory allocation on-heap or off-heap
MemoryAddress - handles memory within the segment, ie. Offset region of MemorySegment 
SegmentAllocator - abstraction defines useful operations to allocate and initialize memory segments 
2. Memory management
MemoryLayout - describes a segment's content to manipulate high-level data structures of native code such as structs, pointers, and pointers to structs.
SequenceLayout - for creating arrays of data 
3. Native Function Invocation (Foreign Function API)
Consumes native libraries without 3rd party wrappers, attained via MethodHandles 
Linker - a bridge between binaries 
FunctionDescriptor - defines the native functions signature and argument types
SymbolLookup - looks up the function in the class loader of the standard library 
The Linker interface enables both downcalls (calls from Java code to native code) and upcalls (calls from native code back to Java code). 
4. JExtract - the high-level abstraction wrapping around the fine-grained definitions for access, allocation and execution of Foreign memory and functions 

Develop a cloud-native microservice by using Spring cloud augmented with,
1. Spring cloud config server - for centralized application properties configuration management (can be hosted or location native toggled via active profiles)
And clients consuming the configuration having the spring-cloud-starter-config dependency and specifying the config server location in the client resources
2. Netflix Eureka Server - for service discovery and dashboard monitoring (also the client services register with the server with spring-cloud-starter-netflix-eureka-client dependency)
3. With application service log management via logs sent to the Zipkin instance using the Micrometer OTEL project (with dependencies micrometer-tracing-bridge-otel, opentelemetry-exporter-zipkin artifacts) and config server pointer 1 having configuration property for logs - zipkin.tracing.endpoint as zipkin running instant URL
4. OpenFeign - for interservice communication via interface REST endpoint definitions having FeignClient name (which automatically registered the clients to the service discovery of pointer 2) 
5. Spring cloud gateway - for API gateway pattern and OpenAPI documentation with Springdoc project (spring-cloud-gateway-starter to create an application handling gateway and annotate with EnableDiscoveryClient as the application is not Feign type)
6. OpenAPI Documentation with GroupedOpenApi and RouteDefinitionLocator for generating endpoints on each service, additionally specifying routes id, url, predicates, filters, and swagger in the config server of pointer 1
7. Finally build all the services into a docker image with the build-image step of the spring boot maven build the plugin and JIB for modules outside the multimodule build structure

REPL of Java - jshell can be extended further by providing tooling support like those from the java.util.spi.ToolProvider interface (javap, jpackage, jmod, jlink) via a wrapper in turn delegating to the actual tool invocation on the jshell itself rather than in a separate window/tab.

Intercepting the incoming REST requests for preprocessing, validating, rerouting, sanitizing and for obvious security reasons Jakarta REST request filter provides with jakarta.ws.rs.container.ContainerRequestFilter interface. Defining a class that implements the interface along with PreMatching annotation enables the requests to be intercepted before even the respective REST endpoint resource is mapped giving an option to convert the type of the REST request namely GET, POST, PUT, PATCH, DELETE etc., without the PreMatching annotation the filter will be invoked to intercept a request after it has been matched to its target method. 
jakarta.ws.rs.container.ContainerRequestContext is an implementation holding the request details header body and method type.
After the filter exits, the Jakarta REST runtime will match the request to the new method set in the filter.

Spring Data JPA method names will automatically try to resolve into SQL query associating with the parameters in the method, however, for creating complex SQL queries spanning in length and number of filter parameters it is always advisable to create an implementation of the query in the JpaRespository interface with Query annotation or with an entityManager managing the data state transactions. 

The perspective of using DTO varies in the context of managed entity objects in the persistence context, such that 
1. Any changes to the entity attributes are detected and executed lazily 
2. Idempotency when trying to fetch the same entity object 
3. Cached results 
Downsides,
1. All entity attributes are initialized when reading the entity 
2. Associated entities are eagerly fetched 
3. Persistence context checks for changes in managed entity object before any query execution and issues a write before if there is a change 
4. When instantiating a new object persistence context checks if there is already a managed object 
On the contrary, DTOs are unmanaged objects, that address the downsides of managed entity objects also eliminating the benefits offered. 
However, you can enforce a DTO layer abstraction in your code by using DTO objects directly while fetching entities via JPQL,
1. ResultTransformer 
2. TupleTransformer 
Or via the DTO constructor projections in the query with a fully qualified DTO constructor name, thereby directly instantiating a DTO object for each record in the result set.

With Java 20 release, it is time to take note of what was earlier and what is now, the state of evolution of features, and a quick refresher on the project API enhancements.
Project Amber - Facilitates Java Language productivity features 
1. Pattern matching for switch 
Simplified programming structure in place of multiple polymorphic type checks, casting, and variable declaration in switch clause that is exhaustive, and guards with addition conditional checks with when clause 
2. Record patterns 
Eliminates the need to create a pattern variable for each of the record fields as records enable accessors.  Nested records offer a huge advantage in field access. Enhanced for loop to have record pattern avoiding variable creation. 
Project Loom - Lightweight highly scalable concurrent APIs for threads
1. Virtual threads 
Decouples the usage of platform threads as the task is run in virtual threads that bind and unbinds from the platform thread on execution 
2. Scoped Values 
Replaces ThreadLocal which is mutable and subject to state changes in multiple threads, ScopedValues are immutable and bounded to a particular thread and require a definition for sharing the thread data 
3. Structured Concurrency 
Short-circuiting thread tasks execution assisting in graceful thread cancellation, error propagation, and state maintenance aggregated by a parent thread 
Project Panama - Interoperability with external JVM memory and libraries 
1. Foreign function and Memory API 
APIs for accessing external memory and libraries, namely Linker, SymbolLookup, MethodHandle, Arena, MemorySegment, MemoryLayout, and SegmentScope dealing with external memory management 
2. Vector API 
Provides a way to write complex vector algorithms in Java that perform extremely well, such as vectorized hashCode implementations or specialized array comparisons. Numerous domains can benefit from this, including machine learning, linear algebra, encryption, text processing, finance, and code within the JDK itself.
Summary of Java 20 Features
429: Scoped Values (Incubator)
432: Record Patterns (Second Preview)
433: Pattern Matching for switch (Fourth Preview)
434: Foreign Function & Memory API (Second Preview)
436: Virtual Threads (Second Preview)
437: Structured Concurrency (Second Incubator)
438: Vector API (Fifth Incubator)

TLDR,
1. Hibernate 6.x uses JPA 3.0 - namespace used is jakarta.persistence.* 
2. Hibernate-specific Criteria API is removed to use JPA Criteria API 
3. Entity ID naming sequence to postfix with _seq to the entity’s table name and uses that as the default sequence.
4. Incubating annotation for new experimental features 
5. TupleTransformer and ResultListTransformer in place of ResultTransformer interface enabling only the required implementation 
6. JSON document mapping via Embedded annotation with @JdbcTypeCode(SqlTypes.JSON)  and JSON fields specified in a class with Embeddable annotation 
7. Java Records as embeddable along with @EmbeddableInstantiator specifying how to instantiate provides all the attribute values in a ValueAccess object.
8. OffsetDateTime and ZonedDateTime improve the mapping by introducing the @TimeZoneStorage annotating and supporting 5 different mappings:
NATIVE, NORMALIZE, NORMALIZE_UTC, COLUMN, AUTO

When there exists a parent-child table association fetching paginated results via SQL JOIN FETCH doesn't return paginated results instead all the row entries are fetched from the database and actual pagination is applied in the application memory.
This can be observed in the logs for a WARN 'collection fetch applied in memory'
This could be a performance bottleneck, however, in Spring 6 employing Hibernate 6 we can rely on JPQL Window functions to apply pagination to the database or split the query into two parts, one for the paginated parent and another to get the associated child entities piping the results from the former query

Jakarta persistence of entity ID for database primary key was reliant on vendor specific implementation, now in JakartaEE10 the GenerationType strategy parameter of GeneratedValue annotation supports UUID such that the persistence provider generates and assigns RFC4122 UUID to the primary key field 

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