Oct 08

In production you may have run into problems where a certain flow is slow, turning hibernate statistics on using the jmx-console would be a good idea, but debugging what actually corresponds to this slow flow could be like searching for a needle in this haystack. The obvious thing would be to organize the data in such a way that all queries for a flow along with their time are presented together. The blog discusses one approach for doing so assuming we are using spring and hibernate.

In our case we were interested in the hql, sql and time taken for them. We were also running into some issues with the session size, so had a piece to capture that too. The whole approach is based on these simple steps:

  1. Putting in a flow identifier
  2. Inject our own SessionStatsCollector
  3. Wire it via JMX
  4. Get callbacks for the original sql

Flow identifier
The utility of this approach depends on how easily can we pin point each flow. The url along with the thread id is a good starting point. However if the urls are kind of the same and the request parameters have a special token, we can use that as our flow discriminators. This token is injected into the NDC for the later part of the tool to pick it up and arrange diagnostic information.

Inject SessionStatsCollector
Hibernate does not allow any hook points to the session stats collector, so to get our custom stats collector in, we used a simple cglib proxy for it. The proxy intercepts only queryExecuted and closeSession methods. While queryExecuted is used to capture the hql, time and number of rows, closeSession callbacks helps us log all the collected information together.

Wire it via JMX
Since the original mbean does not support logging flows, the new jmx bean exposes one method profileFlows which takes the flow pattern and a boolean to indicate if the session size should be logged. Determining the session size is a heavy operation, so on most cases we may not want to do so. There is another method to reset the bean which would revert to the original statistics collector from our souped up version.

Sql callbacks
We were interacting with our dba group, for whom the hql was like greek, so the original sql was important to us, since the original stats implementer does not get any callbacks for this, we injected our own entity interceptor which gives a callback to the stats collector for the sql.

So in short with about 8 classes, we can create something which gives us some indicators of the flow performances. The performance and memory overhead introduced by this is nominal and can be turned off at any point.

The classes for this are easy to code, if laziness gets in your way, post a comment and will upload it.

Tagged with:
Aug 24

GWT RPC White List Magic
The reason I used the word magic is because that’s how it came across to me when I first came against this problem. This issue is more peculiar when one is using GXT and passing data back and forth between client and server using classes extending BaseModelData. Continue reading »

Tagged with:
Aug 24

As per Joshua Bloch Effective Java Second Edition, Item 9 Always override hashCode when you override equals.

“You must override hashCode in every class that overrides equals. Failure to do so
will result in a violation of the general contract for Object.hashCode, which will
prevent your class from functioning properly in conjunction with all hash-based
collections, including HashMap, HashSet, and Hashtable.”

Another Important Line from the Effective Java “In hashCode method you must exclude any fields that are not used in equals comparisons,
or you risk violating the second provision of the hashCode contract”(To refer to contract look into Object.java (javadoc))

I want to add to this and say :

Always compareTo method should reflect same logic as you have in equals. Continue reading »

Aug 19

This main focus is to point out some of the pitfalls which one may land into while writing the server side code for a GWT using especially when you are a beginner. Since Google’s GWT tutorial is really good and very extensive, this article is not explaining how to write code in GWT but some of the points which one needs to handle on the server side when GWT is the UI interface of the application. I am not an expert in GWT application, but just sharing my experience of integrating GWT in a web application for the first time. So you can definitely improve or suggest alternatives listed below.

Continue reading »

Tagged with:
Apr 28

Ohhk, quite a lot of things done but this one is something which I have used most often. Custom cells can sometimes greatly push ahead the usability of your application. In this post I am going to create a test project which will demonstrate how to create custom cells and use them appropriately to provide better usability. The application will finally look like this:

For basics and list of topics you can refer this post:

Continue reading »

Apr 22

In this post I am going to access all the preferences from the code. Also I have made a setup wizard which allows you to change the preferences from the application it self.

Following are some of the things covered:
  1. Reading Preferences
  2. Editing Preferences
  3. Custom UITableView
  4. Wizard

The Wizard will finally look like this:

You should read the following posts for basics

Continue reading »

Apr 22

In this post I will be using PSChildPaneSpecifier in the application preferences.

You should read part 1 of this post if you are not familiar with application preferences. You can find it here .
 

What does PSChildPaneSpecifier do? It adds another page of configurations into your settings. We do that when we have a large number of configurations, so we divide them into categories and make a child pane of each category.

Continue reading »

Apr 22

Here I am going to discuss Application Preferences. For those who are unaware of it, Application preferences refers to the configurations that shows up in the Settings. So if you want your application name to be listed inside Settings, you need to follow the procedure.

Lets first discuss what are the available options. Since we know in iPhone all applications work in a sandbox mode, we can not write a program to alter the behavior of another program. What it means here is, there are fixed UI Elements that can be used in Application preferences, their behavior is also fixed and cannot be changed. For example a you cannot provide a date picker in the settings, you cannot pop up a message saying the URL you entered is not correct. All you can do is provide a field where user can enter his preferences.
Following is a list of options we have for UI elements that we can provide:
  1. PSTitleValueSpecifier: Used to write titles, similar to UILabel
  2. PSTextFieldSpecifier: Similar to UITextField
  3. PSToggleSwitchSpecifier: A toggle switch which can be ON or OFF
  4. PSSliderSpecifier: A slider which can be used to provide a value bw MAX and MIN
  5. PSMultiValueSpecifier: Shows multiple values from which user can select one.
  6. PSGroupSpecifier: Very important for layout (discussed later).
  7. PSChildPaneSpecifier: When you need to have another page of configurations.

Continue reading »

Apr 15

An object by itself is intensely uninteresting.Objects contribute to the behavior of a system by collaborating with one another.One of relationship aspects between Objects can be represented by Association.

When we bring in Cardinality in Association we get One-to-One, One-to-Many and Many-to-Many.In later two One-to-Many and Many-to-Many we use Collection to represent many Side.For example: An Order have many OrderDetail’s.

We have these associations represented in Relational DBMS using foreign keys.So from any O-R framework we expect that to take care of these associations in smartest way possible.As these can easily become a performance bottle neck for the application.Some time you may end up loading lot of Data into memory, and sad part is you are never going to use them.  Continue reading »

Tagged with:
Apr 09

In this post I will be creating a calendar, which could reused in an any native application.

I used the calendar source from here and modified it a little bit to suit my requirements.
You can find the modified code from my project here: DOWNLOAD PROJECT
The final screen should look like this:
You can download the complete project from the link given, I will only discuss how we can reuse this calendar and modify it to fit our specific requirements.

Continue reading »

preload preload preload