Welcome!

Java IoT Authors: Pat Romanski, Elizabeth White, Zakia Bouachraoui, William Schmarzo, Yeshim Deniz

Related Topics: Java IoT

Java IoT: Article

HTTP Session Garbage Collector

Removing cached data

A common approach to caching data in Web applications is to use an HTTP session. A business use case that spans multiple HTTP requests may create the need for caching in a Web tier. Once business use–case processing is completed, this cached data needs to be removed. Failure to do this may lead to memory leakage, which becomes noticeable when a user HTTP session continues for hours.

The Solution
The following terminology is used in subsequent sections:

  • A use case is a sequence of steps performed by a user toward realization of a business requirement.
  • A nested use case is the extension point from the base use case.
  • The use case context represents the logical starting point of a use case.
  • The handler is a server-side component responsible for processing HTTP requests.
  • The cache element is an object, cached during use case processing.
  • The navigation path is the sequence of handlers invoked when fulfilling a use case.
Let's begin by considering a few basic rules.

Rule 1: Only one use case is active at any instance: A user cannot process multiple use cases at a given instance.

Rule 2: A use case processing stage governs the cache element life cycle:

  1. Start stage: New use case processing starts on completion or termination of prior use case processing. Cache elements that correspond to a prior use case are removed.
  2. Intermediate stage: The user navigates to the next step or to a prior step of the use case. Forward navigation adds new cache elements; backward navigation may remove cache elements on an as-needed basis.
  3. End stage: On completion of the use case, all accumulated cache elements are removed.
To implement this rule we need to provide an additional parameter to identify the use case processing stage.

Rule 3: Handlers operate inside a use case context: User navigation dynamically builds a cache hierarchy tree with the handler and use case context as nodes and the cache element as a leaf. The handler node could hold a successor handler, cache elements, and a nested use case context. The use case context node holds a start handler. The root of the tree is the use case context.

Rule 4: Handlers operate on cache elements: Handlers create, read, and destroy cache elements.

Keeping these rules in mind, let's address the stated problem. We have conceptually built a cache hierarchy tree, which is the key concept to addressing the problem.

Step 1: Each request will go through the cache garbage collector
At the start of a new use case, the cache garbage collector removes all existing cache elements of the previous use case.

Figure 1 addresses the memory leakage problem. The introduction of the cache hierarchy tree removes tight coupling between handlers.

 

Step 2: Handlers navigate the cache hierarchy tree
A pointer is maintained to navigate the cache hierarchy tree. It points to the most recently processed node in the use case context. With the help of this pointer we can:

  • Jump to a previous step
  • Jump the nested use case context
During a jump operation all cache elements that are attached to downstream handlers may be removed. It's helpful in the following business scenarios: backward navigation and use case termination.

Efficient memory handling at a granular level is achieved. At the same time, the decoupled handlers make future enhancements easier.

Solution Implementation
Cache Hierarchy Tree Design
The cache hierarchy tree is built using the GoF Composite pattern (see Figure 2). The use case context and handlers are the nodes; the cache element names are leaves; the actual cache element instances reside in the HttpSession.

 

Cache Hierarchy Tree Management
The "UserAppStateContainer" object holds the cache hierarchy tree. This container instance is stored in the user is HTTP session. "UserAppStateManager" helps manage the cache hierarchy tree.

Conclusion
The cache hierarchy tree empowers HTTP session garbage collection; however, this tree is also kept in the user HTTP session. So in a clustered environment it also needs to be replicated.

More Stories By Abhinasha Karana

Abinasha is a technical specialist at Systems Integration group of Infosys Technologies. He has around 6 years of experience in information technology field as a developer and designer. His interest is in EAI and distributed computing.

Comments (1)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


IoT & Smart Cities Stories
Tapping into blockchain revolution early enough translates into a substantial business competitiveness advantage. Codete comprehensively develops custom, blockchain-based business solutions, founded on the most advanced cryptographic innovations, and striking a balance point between complexity of the technologies used in quickly-changing stack building, business impact, and cost-effectiveness. Codete researches and provides business consultancy in the field of single most thrilling innovative te...
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and Bi...
The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get tailored market studies; and more.
With the introduction of IoT and Smart Living in every aspect of our lives, one question has become relevant: What are the security implications? To answer this, first we have to look and explore the security models of the technologies that IoT is founded upon. In his session at @ThingsExpo, Nevi Kaja, a Research Engineer at Ford Motor Company, discussed some of the security challenges of the IoT infrastructure and related how these aspects impact Smart Living. The material was delivered interac...
CloudEXPO has been the M&A capital for Cloud companies for more than a decade with memorable acquisition news stories which came out of CloudEXPO expo floor. DevOpsSUMMIT New York faculty member Greg Bledsoe shared his views on IBM's Red Hat acquisition live from NASDAQ floor. Acquisition news was announced during CloudEXPO New York which took place November 12-13, 2019 in New York City.
Atmosera delivers modern cloud services that maximize the advantages of cloud-based infrastructures. Offering private, hybrid, and public cloud solutions, Atmosera works closely with customers to engineer, deploy, and operate cloud architectures with advanced services that deliver strategic business outcomes. Atmosera's expertise simplifies the process of cloud transformation and our 20+ years of experience managing complex IT environments provides our customers with the confidence and trust tha...
Intel is an American multinational corporation and technology company headquartered in Santa Clara, California, in the Silicon Valley. It is the world's second largest and second highest valued semiconductor chip maker based on revenue after being overtaken by Samsung, and is the inventor of the x86 series of microprocessors, the processors found in most personal computers (PCs). Intel supplies processors for computer system manufacturers such as Apple, Lenovo, HP, and Dell. Intel also manufactu...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...