Clipboard Page Analyzer

Have you seen a colored clipboard like this before, probably not right, please read to find out how and more importantly why it looks as it is.

Color Clipboard

We love creating Pages, especially finding good names for them. Within Pega Rules Process Commander (PRPC) pages play a very critical role as a highly flexible data structure that offer application developers the ability to abstract the underlying business data model.

But with all this glamor, “named” pages hold one dark secret, once created they have to be manually deleted through the code. Which means you have to track most of the pages that system create for you (Obj-Browse, Obj-Open) and all of the pages that you create (Page-New), so that you can remove those pages at the correct moment within the business process after they are no longer needed. If not this can lead to significant performance issues as every page in the clipboard occupies memory.

This being a design feature in PRPC, Pega has given couple of ways to delete named pages. Widely used Page-Remove activity method is the easiest and by far the best way to delete named pages, but if you are writing Java then removeFromClipboard Pega Java API method can be used to achieve the same outcome.

Everything is working perfectly up to this point, there are ways to create pages and ways to delete pages. But there is a problem, since we are doing these tasks as humans, even though it is a good development practice to remove pages whenever not needed, sometimes we tend to find the best practice is not being followed, resulting a cluttered clipboard.

So what if there is a way to find out pages that were created but not deleted within two different points in an execution flow that you have selected. Which brings us to the beginning of this post the colored clipboard. Yes you guessed it correctly, those colored pages indicate exactly that. Those are pages that were created but not deleted within a user specified two points in an execution flow. I like to call this the Clipboard Page Analyzer.

So you know the problem and you have seen an answer, let’s see how to implement this.

Let’s start with an example, Imagine you have a process with 3 flow actions (FA) and you are creating two pages called A and B within the boundary of these 3 flow actions. According to the technical design correct life span of these two page should be as follows.

Page A – Initialized within FA1 and removed within FA2

Page B – Initialized within FA1 and removed within FA1 

Following diagram shows the correct representation of that.

Correct Implementation

Now for a moment let’s analyze the following diagram which is an incorrect implementation of the technical design

Incorrect Implementation

So as you can see if you examine the clipboard after the FA1 you will find Page A and B both on the clipboard, but according to the design only Page A should be present, which means the developer has not removed Page B at the correct moment within the process. Something similar can be seen if you examine the clipboard after FA2, where you will see both the pages present but according to the design none should be there.

So how do we track these clipboard page creation and deletion moments. It turns out to be that we do not have to track, there is a neat trick that can be used to get the delta of pages within two different points in time.

If you examine the PRPC Java API you will find a method called getPageNames in PageDirectory interface.

 getPageNames API method

Once you have this method it is matter of invoking this method at two points in time and find the delta. So with this in mind and after some client side coding following is what you get. (Please see the video in YouTube directly with HD full screen for better quality).

Clipboard Page Analyzer

Comments

Popular posts from this blog

Creating custom rules in PRPC

Creating custom rules in PRPC – Introduction

CSSA PDN Links Compilation