Saturday, May 25, 2013

HumanTask Event Listeners - WSO2 BPS


HumanTask engine comes with a humantask event generator. These task events are generated when a task goes trough a state transition. An event contains details about tasks and its state transition. So by writing a custom event listener to these events, a developer can easily enhance the HumanTask engine's functionalities.

What developer can do with a task event listener.
  • Can do custom java code/ web service invocations.
  • Can retrieve task information. 
  • Developer free to implement their own logic depending on their requirement.

Sample Event Listener.

EventListener class should implement HumanTaskEventListener class and onEvent method. See following sample code.


How to deploy a custom listener to WSO2 BPS

  1. Build a jar file of including your listener.
  2. Copy it into /repository/components/lib. Where is the root directory of BPS server.
  3. Uncomment TaskEventListeners in HumanTask configuration file (/repository/conf/humantask.xml) and give your Event Listener class name for ClassName.
  4. eg:
    Note: you can have multiple listener classes.
  5. Start BPS.
  6. Execute a task.

Escalating a human task with WSO2 BPS.

This Post describes, how to you can define a deadline within a human task. For this I am going to extend WSO2 BPS Claim Approval Task sample.

Prerequisite

  • If you haven't tried the sample yet, try it first. So you get better idea about how human task works.
  • Download WSO2 BPS 3.0.0 +
  • an Text Editor.

Note: You can find more information about humantask deadlines and timeouts under section 4.9 in humatask specification. 

What I am going to do in this sample ...

In this sample, I have set deadline time duration for 5 minuets after task creation. The escalation is defined such a way that, if the claimed amount is less than 10000 and task not started within 5 minutes, then notify task's potential owners that current claim approval task is overdue.

Steps to Modify WSO2 BPS Claim Approval Task sample


1)  Setup BPS as mentioned in sample page.

Deploy BPEL package. Creates Roles and Users. But do not deploy humantask package ClaimsApprovalTask.zip since we are going to modify it in next steps.

2) Modify ClaimsApprovalTask.ht

Unzip ClaimsApprovalTask.zip and Add following deadline definition (i.e <htd:deadlines>) inside ApproveClaim task definition (i.e. <htd:task "ApproveClaim"> ) in ClaimsApprovalTask.ht


3) Replace ClaimsApprovalTaskService.wsdl

I did slight changes to wsdl file for this sample. So replace ClaimsApprovalTaskService.wsdl with this file.

4) Deploy Sample

Create new zip file including all files.(modified and unmodified) and deploy it in BPS.
( you can find modified sample from here )

5) Send a Sample Request.

After deployment, send a sample request (like given in sample page). You can see task is created under clerk login. Do not start the human task.

6) Wait 5 mins.

After 5 mins, deadline will be executed. As a result this, a notification is generated and sent to the clerk. Clerk can view notification under Home -> Human Tasks -> Notifications.   




Recovering your deleted files using - Foremost

I recently looking for data recovery tool to recover some files in my home folder. I was looking some recover tool for linux, and I found an interesting command line tool call Foremost.

Why is it so interesting ?

  • light weight and easy to install. 
  • Easy to use.
  • Built in file filters for fast recovery. ( e.g: jpg, zip, rar etc.)

How to install foremost.

Go to terminal and  type.

$ sudo apt-get install foremost


Recovering deleted jpgs files in partition

  1. First make an empty writable directory to save recover files in a partition other than that you are going to recover. ( let's say /recovery/data/ )
  2. Then run foremost.  I am going to recover my home partition ( let's say /dev/sda5).

  3. $ sudo foremost -t jpg -i /dev/sda5 -o /recovery/data

  4. Finally set user permission to /recovery/data/ to view image. type

  5. $ sudo chown YOUR_USER_NAME /recovery/data -R

Some important foremost command line arguments.
  • -i  :- partition/image to recover
  • -o :- location to store recovered files.
  • -t  :- built in file filter options.  you can give multiple filters by separating using commas. (e.g: for jpg and pdf: -t jpg,pdf ) 
  • -q :- quick mode.
 you can find more details about foremost in following locations.

  1. https://help.ubuntu.com/community/DataRecovery#Foremost
  2. http://linux.die.net/man/1/foremost

Sunday, May 5, 2013

Writing an Assembler for CMinus using Antlr 3 and String Templates

Recently I wrote an assembler for DLX architecture using Antlr 3 as an assignment of the Advance architecture course module.
 

Target 

Main target of this assemble is to generate an optimized assembly code by filling delayed branch slots. It can take High level language code segment as a input. First it should generate unoptimized assembly code and then optimized it to fill delayed branch slots.


Why Antlr ?

Antlr supports String template which is a java template engine that can be used to generate any type of formated texts ( source codes, emails, etc). So using string template we can perform language transformation very easily. For example Java to C#, C++ etc. For more details look at Here .

you can find antlr 3 samples at github.  I modified the cminus sample available at github for this project. 


About project

I used Cminus as High level language and DLX (RISC architecture) as target platform. It used Antlr version 3.

This project is available at Google-code svn repository.


Limitations of the Code

  • Fills only delayed branched that occurs after unconditional jump. ( j )
  • Supports multiple for, while and doWhile loops in high level language.
  • supports only addition.
  • supports only == and < 
  • do not support variable = variable + variable type assignments
and more.



Main Development Steps

  1. Building Lexer and Parser using lexer rules.
    • used Antlr IDE ( downloaded via antlr site) to generate lexer and parser.
  2. Unoptimized code generation using string template.
  3. Wrote optimizer  and Optimized code generation. 
  4. Mavenized the project. 

Building Project and Run

you can build project using maven3. ($mvn clean install) .
Maven build will execute assembler after the build and generate optimized code for sample.txt. asem_optimized.txt and asem_unoptimized.txt will be created after the build.


Improvements to the Code base

I warmly welcome your suggestions and ideas to improve this assembler.