domenica 15 aprile 2012

Some anticipation of the first application (PT1) - Facebook Desktop Notifier


From two previous post, we understood that a primary goal of our works is INTEGRATE application. Now we would make things more interesting, (as possible). Let's start with a simple example: this first example is far to the reality, but is interesting (also for me) to see the behaviour of the library in a simple real situation

Ok, let's start!

Now we suppose that we want to manage Facebook notifications, through rss format (see http://www.kristi-barrow.com/facebook-rss-feeds-what-is-available/ ; facebook make it able an xml page with some notification,   reachable through a simple secure link). On the other hand, suppose that we have a little client that can manage some kind of notification, but not in RSS format.

This application expects to receives the 'number' of notifications that are not yet been read, , contacting directly facebook. However, facebook doesn't provide this service: it allows only to receive the rss file.

How we can manage this situation? From my point of view, we could integrate these application through a connector :) In an informal way, we can follow these steps: we fetch the rss notifications from facebook, adapt the informations (with the connector) and provide its to the client. Ok, let's start to see how do it!

The first step can be resolved by defining a simple https connection to the specific link (http://www.new.facebook.com/feeds/notifications.php?id=your_facebook_id&viewer=your_facebook_id&key=your_internal_key&format=rss20). This step are solved by the client application

Ok, now we can continue with the second step. In this step we practically define our connector.

This connector must transform the xml file into a big 'Rss' Object. To do this, we can define a translator primitive (we discussed it in the previous post) that consume from the xml file e, through  the transforming logic (that consist of an Rss parser) converts the file into a RSS Object (we can use the rss lib utils).

Finally, this translator write the result of the transformation - a simple number - on a txt file; this file will be read by the client application, that on own will notify the user of this new information

This is the result 
(Simple System Tray Icon)

Nexts posts will explain step by step how obtain things like these :).. Stay tuned

domenica 8 aprile 2012

How use a term of the algebra

To build a connector, we must define at least one term, called primitive: these primitives are explained in the previous post. Ok lets' start to see how define a connector composed by a single trm.

Suppose that an application would to provide a txt file of a non standard format, while the reader expect to manage a csv file. To make this last application able to read the file without modify the logic of the application, we can build a connector that 'transform' the file provided file with a csv structure.

Initially, we must define the term:

 Trans t = new Trans(source_uri, type_in, receiver_uri, type_out);

 where :
 1) source_uri indicates how the message -in this case the non standard format file- can be received (it can be a request such http - you can find all the supported uris here http://camel.apache.org/components.html )

 2) type_in is the type of the incoming message, in this case we can assume File.class (it must be an existing implemented class)

 3) the receiver_uri is such the source_uri; the important things is that we must know how the client application fetch its files. For example, if the client read the cvs file from a specific folder, we must write the result of the transformation in this folde: in this case we can use the supporte file uri (http://camel.apache.org/file2.html) and specifiy "file:target_folder?fileName=output.csv" as parameter.

4)The output_type is such the type, but in this case could be exists a specifi class, like CSVFile.class 

Ok! Once specified these base informations, we must define the transform logic. To do this, we must define (in the same class or in another accesible class) a method that make the transformation: in our case

public CSVFile transformMethod(File file){
        //read the file
        //construct the new file
   
        //return the constructed CSVfile


A the end of this process, we must bind this definition with the translator object:

t.setTransLogic(class_that_contain_the_method.class, "transformMethod");

 At the end of this step, we can start the connector:

 t.start();
 Thread.sleep(2000);

 and keep the application alive for 2 seconds. A the at the end of the execution the client is ready to starts the processing! There are lot of consideration around this little example. I'm pleased to answer, if possible, to your questions :)