Thursday, June 15, 2006

Lifetime Management with BPEL (Part II)

It's time now to explain to the reader what I mean using the term "Lifetime Management".

The basic idea is handling the timeouts as they were previously defined before (see Lifetime Management with BPEL (Part I) with BPEL Peek example).

Standard BPEL allows us to handle duration or deadline timeouts by defining how much time should elapse before the timeout event will occur or by specifying the deadline date and time for the deadline (onAlarm's for and until attributes accordingly).

The new way I'd like to declare the process timeout expression is so that onAlarm can handle an automatic duration prolongation in the case when some of the duration expression conditions were changed. It's important to notice that you can not just change onAlarm's expression via, say, Assign activity (at least I couldn't found the way how to do that, so please inform me if you know the way).

Lets take an example of how to use this functionality.

Imagine a web shop that keeps a personal shopping cart for each of its customers.

A user may surf through the web shop, put some products in the cart and make an order.

One of usecases for this web shop may be the following:

  • Customer wants to buy everything he placed in the cart (the good one :). In this case the system calculates an order and starts the process of billing and delivery of the products to the user;
Another possible usecase is:
  • Customer leaves the webshop page (doesn't matter how - by navigating to another URL or just closes the browser window).
What should become with a customer's shopping cart and all the goods that he placed into it in the last scenario? Should we release all the items from the cart immediately? But what if the user will return to the page and act as in the first use case? Then he would have to navigate the site once again and take all the stuff he already did few time ago - bad usability.

On the other hand if we left the items in the cart forever then no one other would be able to buy the stuff that is in the other user's cart since it's already reserved.

So we need to specify the cart lifetime somehow so that all the items were released and the cart were cleared after the specified time.

The typical solution for a web shop here nowadays is using HTTP session but as we are talking about Web Services the HTTP session is not suitable for that. So we may use BPEL that can give us the functionality we need at the higher level of abstraction.

Why not just use BPEL onAlarm duration (the for attribute)? Since, as I already said above, it is not possible to change the duration expression at runtime while this is required to set the new cart lifetime after each cart update (say after adding new item to cart).

In the next part we'll see how to implement this example using BPEL and discuss some key aspects that you should pay attention for while using BPEL here...

Lifetime Management with BPEL (Part I)

Here we go...

I'd like to show you an example of BPEL (read BEEPLE :) that allows to implement some kind of a lifetime management using web-services.

This implementation is based on BPEL's Pick activity, and right before we start I'd like to introduce readers in what this activity is need for. Those who familiar with that may freely skip this part.

So, as I already said, BPEL have the Pick activity that is like widely known Switch/Case language construction in programming languages (Java, C++ or Pascal Case/Of). Those constructions have a possibility of redirecting control flow based on some expression, for instance (Java):

switch (directionExpression) {
case LEFT:
moveLeft();
break;
case RIGHT:
moveRight();
break;
case UP:
moveUp();
break;
case DOWN:
moveDown();
break;
default: // Hold
}
In BPEL the Pick activity is the analog of the Switch statement. Pick's OnMessage statements are like Switch's case statements.

To be true to the reader I'd like to say that BPEL have the Switch activity too. The main thing that distinguish Pick from Switch constructions is that Pick is a blocking activity, that means that the expression that manages the process control flow is a message that BPEL process instance is waiting for to receive, and the flow would be frozen until this message arrives, while in Switch we already have this expression defined as a process variable and the alternative flow may be picked up without any delay.

Now I'd like you to mention the default statement. Pick has the analog of this statement that corresponds the situation when no message were arrived to the Pick activity during some time period (or by deadline) - the timeout; and the activity that is responsible to handle such timeouts is Pick's OnAlarm.


So the BPEL code using Pick may looks like:
<pick>
<onMessage operation="approve">
<!-- TODO Implement OnApprove -->
</onMessage>
<onMessage operation="reject">
<!-- TODO Implement OnReject -->
</onMessage>
<!-- Timeout will occur in one minute -->
<onAlarm for="&quot;PT1M&quot;">
<!-- TODO Implement OnTimeout -->
</onAlarm>
</pick>


to be continued...

References

Tuesday, June 13, 2006

Dynamic HTML Forms Code Snippet

I'm sure that there are a lot of examples in the Internet of how to implement it so I'm just paste my own snippet "as is" without any explanation of how its works.

Copy-Paste it to see how it works.


<html>
<head>
<script type="text/javascript">
var id = 0;

function addElement(container) {
id++;

var htmlId = "id" + id;

container.innerHTML += "\n<div id=\"" + htmlId + "\">"
+ "\n I'm number " + id
+ "\n <button onclick=\"removeElement('" + htmlId + "')\">Remove</button>"
+ "\n</div>";
}

function initContainer() {
addElement(document.getElementById("container"));
}

function removeElement(id) {
document.getElementById("container").removeChild(document.getElementById(id));
}
</script>
</head>
<body>
<form id="container">
<script type="text/javascript"> initContainer(); </script>
</form>
<button onclick="addElement(document.getElementById('container'))">Add</button>
</body>
</html>


More Information
Dynamic Content with DOM-2

Hello World

My first blog, my first blog entry... :)

I just don't know where else I can write my thoughts and my researches which is why I created it.

As you may notice by the title of this entry I'm a software developer and the majority of posts would be about programming and IT, and everything related to that.

I think I will publish my resume somwere near here later so that readers (if anybody would read this blog :) can see the area of my interests.