Monday, 28 July 2008

Not so warm for cuil

The top technology story on the bbc today was a new search "rival" to google. I was going to dismiss it, but I caught the line where it said it is developed by former employees from the big G.

The name of this new search engine Cuil , pronounced Cool means knowledge in Gaelic, but who cares, is it any better than good ol' google?

First thing I noticed when I entered the site, was the blackness, in contrast to googles white nothingness. Also it took a few moments to come up, I think it may have come up with a loading screen for a second.

I searched for this blog randomconsultant and it didn't have it listed. That was slightly disapointing, as their crawler technology is suppose to be better than google's. But hey it's their first day and this is an little known blog.

But Cuil does claim that it searches more pages on the web than anyone else - three times as many as google and ten times as many as microsoft.

I then searched for something more likely, like the firm I work for. That did come up and the thing that stands out is that the search results were in two columns and each had a little thumbnail. Some of the thumbnails didn't really match the result and there were too many results for pages from the same site.

On the right it had some categories.. but pratically speaking one wants their search engine to contain what they want in the first 3 hits, who cares about other categories. I remember to collect google,yahoo and other searches) had a similar thing but I never used it then.

The results didn't come up that quickly too, which maybe because the whole web wants to check out a possible google killer. In fact Cuil and are number one and two respectively in the hottest Google Trends list (i.e. the most searched for keywords right now) . I am sure google love that.

The search technology cuil uses is suppose to be a lot more sophicticated than google. Instead of just looking at which pages link to what like google does, it also looks at the context of the page and probably other stuff.

I will reserve complete judgement for now, until cuil has a bit of time to crawl the web, but I can't see anything now that will really trouble or make me and others want to switch their homepage.

Maybe in the future, when I am searching for some obscure things and google is firing blanks, and cuil comes up trumps maybe I will switch, but right now I don't think anybody will be in line to jump out of the windows at google hq.


Just tried going to and I got this message

"We’ll be back soon...

Due to overwhelming interest, our Cuil servers are running a bit hot right now. The search engine is momentarily unavailable as we add more capacity.

Thanks for your patience."

As the US starts waking up looks like they are on overload.... wonder how long people will use it... maybe for the novelty factor... or mayber it will be just "cuiler" (ok that's bad) than googling!


Just heard that IBM have swallowed up another product! Apparently this will provide ILOG customers with
"a full set of rule management tools for complete information and application lifecycle management across a comprehensive platform including IBM's leading WebSphere application development and management platform."

This basically means RSA will probably come bundled with JRules and projects will probably be encouraged (forced) to go with websphere if they choose to go with JRules.

I just find this quite funny, as for the last couple of years on my project, ILOG have complained websphere is no good, the IBM jdk is no good, and the rule studio plugin doesn't play well with RSA. IBM have complained that JRules has a ton of peformance issues and a whole load of other stuff.

I wonder what the guys at JBoss think. Before this they were the only ones who could provide a complete suite of application server and rules etc.

So this will probably bring ILOG into the mainstream, so nowhere is safe from the bpm and brms!

Futher reading:

First thoughts on the IBM/ILOG announcement by James Taylor - more of an in depth serious look at it than me.
IBM Puts the Rules Down - OnStrategies.
ILOG Press release
IBM throws arms around ILOG - The Register

Monday, 21 July 2008

Creating a J2ME app with EclipseME and Sony Ericsson SDK

I wanted to try out creating a little J2ME application which could be deployed onto my Sony Ericsson K850i phone. Sony do provide an SDK, and there seems to be a lot of documentation on their developer site , but there wasn't much in the way of a "Hello World" example.

So this is my example of creating a J2ME application using the EclipseME plugin.
This example should work on similar Sony Ericsson phones.


You need to have the following installed before doing anything else:
First you need to download and install the Sony Ericsson SDK for the Java(TM) ME Platform . Install it in the default location which should be "C:\SonyEricsson\JavaME_SDK_CLDC\". Keep a note of this location

Next you will need to install the EclipseME plugin to Eclipse
  1. Follow the install instructions from here.
  2. After you have restarted Eclipse ,you will need to configure EclipseME with Eclipse. Follow the instructions from here and in step 4 use the location you noted down above(i.e. C:\SonyEricsson\JavaME_SDK_CLDC\)
Now you can create a new J2ME Midlet Project. Follow the instructions from here to do this.

Now create a new Midlet class following the instructions from here and replace the template code with this:

package com.randomconsultant.test;

import java.util.Date;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class MyMidlet extends MIDlet {

Alert timeAlert;

public MyMidlet() {
timeAlert = new Alert("Alert!");
timeAlert.setString(new Date().toString());


protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub


protected void pauseApp() {
// TODO Auto-generated method stub


protected void startApp() throws MIDletStateChangeException {



Now you can run in debug mode in the phones emulator

You should see the date pop up for a moment in the emulator.

Now that we know we have a working app, we can try deploying it onto our phone. You have to create a package that will create a jad and jar file:

The jad and jar file will be dropped into the deployed folder within your project.

Now connect your phone via the usb cable or using bluetooth and copy the jad and jar file to somewhere on your phone.

Disconnect your phone from your pc, and open file manager on your phone ( Menu > Organizer > File Manager on my K850i) and select the jad file you copied over. Click on it and it will ask you where you would like to install the jad file (i.e. in applications or games).

Now your application can be selected from which ever menu you added it to (applications or games) and you will be able to run it!

For all my source code you can download it from here.

Leave a comment if you can't get this working or need a hand.

Saturday, 12 July 2008

Working with Drools from a JRules perspective

I had heard a few good things about drools , so I had a play with it over the last few days. I decided to create a small project in JRules 6.7 and keeping the same object model port it to drools 4.07 and see what happens. I specifically wanted to test out porting the following:

  • verbalisations
  • a ruleflow , with a subflow
  • business rules (brl rules)
  • decision tables
  • local variables
The projects I created can be downloaded from a link at the bottom of this post.

The rule project

I created a simple JRules project to process a train ticket. Given a journey start point (zone) and a journey destination, the rules would work out the cost of the journey and deduct it from the user's credit on their prepaid card(Oyster card). The price would also be influenced by the type of user (i.e. train staff, student, senior) . I have tried to keep a one-to-one mapping between rules I have created in JRules and rules I created in Drools.

Download the report of the jrules project from here.

The editors

JRules and Drools both provide an editor which is a plugin to eclipse. Actually, using eclipse is the only way to build the rules too. Even if you need to build from the command line , it runs in eclipse headless mode. However in Drools you are not tied to the editor, you can write all you rules in notepad or vi if you want then use the libraries to build them. That said, I would recommend using the eclipse plugin for Drools.

Verbalising the object model

Firstly if you are unclear about what an object model is in relation to rules, read Dan Serner's useful entry on his ILOG blog.

Ok, JRules , creates your object mapping for free, and creates default verbalisations for your object model. This is great so you can start writing rules right away. However some rules can end up with some convoluted verbalisations as you would have verbalised your object model without thinking about how each one will be used in the rules. You will probably have to go through a verbalisation refactoring stage to sort this out.

However in Drools, you need to create a dsl (domain specific language) file which maps expressions and actions to some given text. So you first think of your rule, then think of the verbalisation, then you add the mapping to your dsl file. This can lead to rules with greater readability, but you have to add each verbalisation yourself.

Here's a shot of my dsl file. (btw all the source code can be downloaded from a link at the bottom)

Writing business rules

Ok in Drools you can write rules directly in DRL (equivalent of IRL in JRules) or you can write rules in dslr which use verbalisations (equivalent of BRLs I guess).

Ok the first thing that threw me, was that you can't use an else in a rule. Weird huh? But there is probably a good reason for it. The other thing was, that I found myself getting into an infinite loop in a rule. You need to set the no-loop property on the rule otherwise it will keep evaluating if the when condition is true. Otherwise no other great surprises here.

Decision Tables

In JRules, you create decision tables within the eclipse editor. I have always found the Jrules decision table editor a bit flaky and pretty slow to open an existing decision table.

In Drools, you create decision tables in excel spreadsheets, csv or openoffice spreadsheets. You do not get autocomplete like the JRules editor, and auto static analysis and some other wizzy stuff, but it is very flexible. And given that while I have been working with JRules, I end up importing and exporting everything I do with decision tables to spreadsheets, I found this pretty useful.


The ruleflow functionality is pretty similar between JRules and Drools. The major exception though is probably that a rule or decision table in Drools points to the rule group(ruleflow task in jrules) it belongs to, rather than in Jrules where a ruleflow task only knows which rules it contains, and a rule can end up in many tasks.

Actually one of our complaints about JRules was that it was difficult to find out which ruleflows a rule is referenced in. But in Drools as it is the other way round, it is a bit of a hassle to search for all the rules that belong to a group, hopefully in a newer release the editor will automatically show all the rules that belong to a group.

Another thing about decision tables in Drools is that individual rows can belong to different rule groups. In JRules the whole table goes in the task.

Local variables

Ok this is where I found the most pain in drools. The equivalent of local variables in drools are global variables. I just couldn't get these damn things to work properly, so I created a local variable class, and a local variable object was passed into the ruleset as a parameter to provide the same functionality. It was also a pain , because I wanted to use a global with a primitive type and drools just didn't like it, and I ended up with some weird errors.

Building and executing

As I mentioned earlier drools is a bit more flexible as you do not need to use eclipse to build your rules in the same way JRules forces you to do. But in drools you need to add each rule or rule package to your ruleset or Rulebase , in your code. In JRules you just build your jar , and you have all your rules neatly packaged up. The code to execute the rules in drools is slightly easier than jrules i would say. Look at the code in com.transport.ticketFeeRules.jrules.RuleEngineRunner and com.transport.OysterCardRules.droolsrulerunner.DroolsRuleRunner , and you will see the difference.

The verdict

I like Drools, but if I was choosing a rules engine at the moment for my project I would stick with JRules. I know Drools is free, but I think it still needs to mature a bit. All the features are there, and it has a web based BRMS too. I have never used JRules Rule Team Server so I didn't compare it to Drools' equivalent.

In a couple of years though I expect Drools to be a real challenger in this space and as it is opensource I expect a lot more expertise to be out there. So if you have been working with JRules I encourage to try out Drools, but don't expect it to be a replacement just as yet. But if you are going throught the decision process now of picking a rules engine, do not discount Drools, it maybe exactly what you need.

Download my comparision projects from here.

Related blogs:

Drools Rules - useful examples on using Drools and benchmarking
ILOG Blogs - the official blog from the company behind JRules
Drools - the blog from the guys who produce Drools

Tuesday, 8 July 2008

Building from command line in JRules 6.7

In my post last week [2 years of JRules] I had a bit of a moan that JRules didn't have out of the box functionality to build a ruleset from outside of eclipse. Ironically a couple of days after I posted that up I was trying out JRules 6.7 and it appears ILOG have pulled their finger out and provided a way of building a ruleset from outside the eclipse rule studio.

It works by running eclipse in headless mode and providing a script location as one of the command line arguments. The given script is written in javascript and calls the JRules API.

For those of you who just want to dive straight into the code here are the downloads:

- this is an ant build file to run eclipse in headless mode and invoke the script

RulesBuild.js - this is the script that builds and extracts a ruleset by calling the JRules API.

I won't go through the ant script in detail, but if you are new to ant, have a look at the ant user manual.

The target "BuildSomething" is a dummy target for you to change. Here are the parameters that need to be updated:

projectName - This is the name of the project which contains the main rule flow.
extractorName - Name of extractor to use
archiveFile - path of where to save the ruleset jar
workspace.dir - path to the eclipse workspace which contains your rule projects

The other target "buildAndExtractRuleset" which BuildSomething calls, calls the macrodef task "headless.appication" which actually fires up eclipse in headless mode. The variables in here that need to be updated are:

script.location - path to RulesBuild.js
eclipse.home - the install path to eclipse

Once you update these variables you can just run the task BuildSomething (command line: ant -f rule-builder-script.xml BuildSomething) .

The script will take a bit of time to run depending on the number of rules in your projects, and once you see RulesBuild.js ENDED , your ruleset jar should be in the location of archiveFile.
Now let's look at the script. Firstly get to know the global variables that are accessible in the script:

Global Variable NameJava TypeDescription
workspaceorg.eclipse.core.resources.IWorkspaceProvides access to the projects access to the Rule Studio Model to Rule Studio rule model projects into the workspace the projects of the workspace the ruleset archives from the rule projects

The function main() is the entry point to the script. This reads in the arguments , turns off auto-building , calls the build functions, calls the generate archive action and then prints a report of all the projects built.

I'll skip to the function build in ArchiveBuilder (line 166):

First all the projects in the workspace are cleaned and refreshed:

Utilities.println("Begin Clean...");
buildHelper.clean ();
Utilities.println("End Clean...");

Utilities.println("Begin Refresh...");
for each( project in workspace.getRoot().getProjects() ) {
project.refreshLocal(2, null);
Utilities.println("End Refresh.");

You could add some code before this to open projects that are closed in the workspace.

Then a full build is called and for each project, a report is generated:

Utilities.println("Begin Full Build...");
Utilities.println("End Full Build");

for each( project in workspace.getRoot().getProjects() ) {
var report = new BuildReport (project,buildHelper.getBuildErrors(project, buildHelper.SEVERITY_ERROR));
this.reports.push (report);

That's the build complete, i.e. the ilr has been created for all your business rules, decision tables, ruleflows, etc.

Now all this ilr has to be packaged up into a jar.

The generate function(line 192) is called to to this.

var rp = ruleModel.getRuleProject(ruleprojectName) ;
var jarfile = archivePath;
Utilities.println("Extracting ruleset archive " + rp.getName() + " with extractor '" + extractor + "'");
Utilities.println("Successfully extracted in " + (new (jarfile)).getAbsolutePath());

The extractorHelper is called to extract the jar. If you don't have an extractor, the extract method is overloaded to also generate a ruleset just with a RuleProject and a path location.

That's about it. I really advise you to go through the RulesBuild.js and look at the JRules API documentation. If you have any questions post me a comment.

Wednesday, 2 July 2008

Using ClearQuest API from VB 6 or VBA

On my current project, I found myself exporting my team's list of activities from clearquest to excel over and over again. This made me look at what clearquest offers in terms of an API. Luckily enough, there was an API available, however whatever documentation that google threw at me, was pants.

I created an excel VBA macro to connect to clearquest and pull whatever data I wanted. Another useful use of the API is wto create some kind of integration tool thing between subversion and clearquest. I haven't had time to do this though.

You can download the excel workbook which contains my vba macro from here. You need access to a clearquest database and have the clearquest client installed for this to work.

Here's an explanation of the code which is contained in the "ThisWorkbook" object if you open the Visual Basic editor ( Tools > Macro > Visual Basic Editor) .

I would recommend that you have the Rational ClearQuest API Reference open while you're going through this.

The first thing to do is to import the module clearquest.bas from C:\Program Files\Rational\Clearquest or wherever cq is installed. This module contains a whole load of useful contstants that you may need later on.

Next open Tools>References and look in the Available references list and make sure "ClearQuestOLEServer" is selected.

Now for some code. You need to create a Session object to connect to clearquest. You need to supply a username, password and name of the clearquest database you are connecting to

'LOGIN - Create CQ Session
Dim cqsession As Session
Set cqsession = New Session

Call cqsession.UserLogon(strUsername, strPassword, strCQDB, AD_SHARED_SESSION, "")
'Create Query
Set querydef = cqsession.BuildQuery(strRecordType)

'Fields to display
For Each displayField In displayFields
querydef.BuildField (displayField)
Next displayField

displayFields is simly an array of strings where each string is a name of a field.

Next the filters for the query need to be added.
This creates an AND operator (the constant AD_BOOL_OP_AND is from the module that was imported)

Set Operator = querydef.BuildFilterOperator(AD_BOOL_OP_AND)
This filter added below specifies that the value of the given field (strFieldFilterName) must be one of the values in the array filterValues

Call Operator.BuildFilter(strFilterFieldName, AD_COMP_OP_IN, filterValues)
Now you can execute your query and get back some results

This creates and populats a ResultSet object from the query

Dim rsltset As Object
Set rsltset = cqsession.BuildResultSet(querydef)
Call rsltset.Execute

Now you can iterate through rsltset using rsltset.MoveNext and calling rsltset.GetColumnValue(Column) to get the values.

At the end call cqsession.SignOff so it closes the clearquest session cleanly.

That's it. Looking at the example in the workbook you should be able to create and execute your own queries. This will work in VB 6 too.

The source code for everything here can be downloaded from here.

If you just want the code without downloading the excel workbook , download from here.

Further reading:

Rational ClearQuest API Reference