Hi! Welcome...

I am Ashish. I am Member of Apache MINA PMC, ASF Committer and avid Code hacker. Contact me at paliwalashish at gmail dot com. I work for Terracotta [http://www.terracotta.org] as Solution Architect. I contribute to jsmpp [http://code.google.com/p/jsmpp/] as well.

14 October 2008 ~ 0 Comments

Mocking – the interpreted way


Mocking is a subject extensively covered and used heavily in Unit Testing. There are number of Mocking frameworks available today, ranging from Static Mocking to Dynamic Mocking, and the latest additions are AOP based Mocking Frameworks. Had been Coding for a few years now and at that time, JUnit has just made its entry. Wow! now I can automate my Unit Testing, but the pain was had to use static mock, objects. Each time I needed a new Object State, had to recompile and test again.

This is how a static mock code looks like

Static Mock

Static Mock

Even when using a mocking framework, we have to define the state of the object we want to return, which means compiling and redploying especially when testing deployed applications. Can frameworks be smart enough to take care of all data variation? unfortunately, the answer is no. Frameworks provide various ways of reducing the effort, but can't make it zero. Hope its always true, else Develoeprs like me shall loose their jobs.

Coming back to the topic. With a little overhead we can make this mock dynamic, so that we can change the state of the object without compiling and redeplying :-)

Let me introduce beanshell. Beanshell is a framework that supports lightweight scripting in Java and it now JSR274. It allows to write scripts in Java syntax, with type relaxation. Now lets see how can we make out Status mock, a dynamic mock by using beanshell script. many IDE's support beanshell scripting as well. Other options available are JRuby and Groovy.

Lets change the Mocked Object code to support beanshell

We create an instance of BSH Interpreter and call the file containing the implementation of the function. I prefer seperate file for seperate functions, to have exercise more control. The difference here is, we have moved the main logic from compiled code to interpreted code. This way, we can change the logic at runtime. We just change the bsh file and the interpreter executes the new version.

Lets look at bsh file

This post displays the cocnept in a very simplistic manner. There can be many variations like implementing the interfaces completely in scripting. Scripting can used as an add-on to existing mocking frameworks taking the Unit Testing to next level.

References

13 October 2008 ~ 6 Comments

Updating Google Calendar with MS Project Tasks


I am back, as promised. Please read my earlier post Processing Microsoft Project File in Java using MPXJ.

In this post we shall take an mpp and update the Google Calendar with the task details. The question is why would anyone do that? 

Lets cook the story. A small team is working and the poor Project Manager share the Schedule with the team. The team is so busy coding that they forget to look at the dates, and the tasks they must be starting on. The poor Project Manager himself loose track unless he keeps MS Project Open on his desktop :-( A pretty common situation :-)  

Have faced this situation and decided to organize myself and this post is outcome of that. The driving force was "Out of sight, is out of mind". So my assumption was if the team has a visual of the task dates, the chances of task slippage shall reduce a lot. 

In this post, have built upon the my previous post to create an MPP parsing function. Have tried to keep the code in simplest form, so that it can customized later to specific needs. Have created a sample Schedule for this activity and used it for the implementation. Here is how it looks.

 

Google Calendar updater Project Schedule

Google Calendar updater Project Schedule

The schdule is simple, some date, and tasks with dependencies. The concept shall work for any number of tasks.

Following are the steps that we need to perform:

  1. Parse the mpp file
  2. Create a Calendar Service (Lets assume that the Calendar is already there, though it is possible to programmatically create the same)
  3. Get All tasks from MPP, and create Calendar Entries in Google Calendar
The Code
Google Calendar Entry Creation Code

Google Calendar Entry Creation Code

The implementation is fairly simple. We have 3 functions:

  • translateTaskToCalendarEventEntry() - Converts an Task into CalendarEventEntry, which can be added to Google Calendar
  • updateCalendar() - Takes input of all the Tasks from MPP, translates into CalendarEventEntry (using function translateTaskToCalendarEventEntry) and update the Calendar
  • updateGoogleCalendarWithMPP() - Parses the MPP using the util function from my previous post, and calls the API above to update the Calendar.

Google Calendar API usage is described in details on Google's pages, hence won't discuss here.
To use it for yourself, replace User Name and Password at line#70, with your User Credentials. Repace the URL at Line# 71 to point to your calendar.
After running the program, this is how my Calendar looked like 

Google Calendar View
Google Calendar View

A simple way to keep track of Tasks.
 

13 October 2008 ~ 19 Comments

Processing Microsoft Project File in Java using MPXJ


Many a time, I wished I had a utility that would read my projects mpp File and automatically alerted me about my tasks. Had created such a utilitly and this post desribes the process of reading MS Project Files in Java using MPXJ and Apache POI library.

MPXJ - MPXJ is the java library used for parsing MS Project files. The lib depends upon Apache POI package for providing the functionality. MPXJ supports all the three formats for MS Project. The details can be found at the Home Page for MPXJ provided in references section

Let's start implementing. The code to read the File is fairly simple.

Reading MS Project File in Java (Using MPXJ)

Reading MS Project File in Java (Using MPXJ)

 To read an MS Project file, we use projectReaderUtility class to get the instance of a ProjectReader, based on the extension. ProjectReader is the interface implemented by the classes that can read an MS Project file in mpxj library. Once we get the instance of ProjectReader, we need to invoke read API, passing the file name to be read. The API returns an instance of ProjectFile, containing all the details in the MS Project File. 

More about ProjectFile - ProjectFile is the class in mpxj, which contains all the information about an MS Project file. It has API's to access all Task details, as well other API's to extract and manipulate other metadata.

Is that it? The basic objective of reading is done. Now we can use the provided API to iterate and create applications to suite our needs. For example, to list all the tasks, use getAllTasks(), it returns a List of Tasks. Custom logic can be applied to manipulate this list as desired, like filtering the tasks based on resources or date.

What's next?

I am working on the prototype to read the MS Project File and update the Google Calendar with Task details, based on Start Date.

References

Tags: , ,

12 October 2008 ~ 5 Comments

(N)IO Frameworks in Java


In this post, I have tried to briefly capture list of available Java IO application frameworks. IO Frameworks reduces the development time by providing additional features over the bare-bone IO API's provided with Java.

Here is the definition I have used for the Framework

"An (N)IO Framework is a library, that provides easy to use API by shielding low level complexity of IO and provides rich and reusable API's to create robust and scalable Networking Applications".

A key point here is, only complexity is reduced, the power of low level API's is still available.

Have been using Apache MINA for a while, and found some similar and powerful frameworks. The idea is to share the result of searches. I don't intent to compare them on their performances or features. The text for the frameworks have been picked from the respective websites.

  • Apache MINA   - MINA (Multipurpose Infrastructure for Network Applications) is a network application framework which helps users develop high performance and high scalability network applications easily.
  • xSockets - xSocket is a lightweight java nio-based server framework to build high performance, high scalable, multithreaded servers. It supports writing synchronous and asynchronous client-side applications as well as server-side applications in a very intuitive way  
  • Grizzly - The Grizzly framework has been designed to help developers to take advantage of the Java™ NIO API. Grizzly goals is to help developers to build scalable and robust servers using NIO.
  • Netty - Netty is a NIO client server framework which enables quick and easy development of network applications such as protocol servers and clients. It greatly simplifies and streamlines network programming such as TCP/IP socket server
There are a few others, have picked up the popular ones. 
References

11 October 2008 ~ 1 Comment

What is Apache MINA?


Apache MINA (Multipurpose Infrastructure for Network Application) is an open source java network application framework. MINA is can be used to create Scalable, high performance Network applications. MINA provides unified API's for various transports like TCP, UDP, Serial communication, In-VM pipe. It also makes it easy to make an implementation of custom transport type. MINA provides both high-level and low-level network API's.

Application Structure

 

MINA based Application Architecture

MINA based Application Architecture

From the figure above, User application interacts with MINA API's, shielding the User application from Low level IO details. MINA internally uses IO API's to perform the actual IO functions. This makes it easy for the Users to concentrate on Application logic and leave the IO handling to Apache MINA.

Advantages (From the Apache MINA Home page)

  • Unified API's for various transports (TCP/UDP etc)
  • Provides high/low level API's
  • Customizable Thread Model
  • Easy Unit Testing using MockObjects
  • Integration with DI frameworks like Spring, Google Guice, picocontainer
  • JMX Manageability

Reference

Apache MINA

- Home Page of Apache MINA

Tags: