The road so far….

July 14, 2010

Implement your factory in Spring XML

Filed under: java — Tags: — Rahul Sharma @ 10:00 pm

In most of our applications we create few objects from factories. For each of these factories we often end up writing custom code rather some kind of common component that can be reused. But reuse is one aspect of programming that we should strive for, rather writing code every time.

Spring provides us quite a few options that can be employed for implementing factories. These factories can be implemented in spring  XML file. Then they can be asked for objects that are created by other spring beans. The objects returned can be tweaked using the “scope” modifier, so that every time a new or the same object can be returned.

In order to see what all mechanisms Spring provides I have created the following class hierarchy. (more…)

Advertisements

July 10, 2010

Easymock, Assert arguments of method call

Filed under: java — Tags: — Rahul Sharma @ 8:41 pm

EasyMock is used for mocking classes, interfaces and corresponding method calls. When you mock a method call you would like to assert the arguments of the call. Asserting an argument can be in terms of identical arguments – as provided during mock, similar arguments – similarity in terms of class/fields/order etc, or any other kind of assertion possible. The package provides whole bunch of options to assert the same. Here I have listed down a couple of them that can be used under varied situations. (more…)

July 5, 2010

Maps can avoid java.lang.OutOfMemoryError

Filed under: java — Tags: — Rahul Sharma @ 9:19 pm

Often we try to use java Maps for some kind of caching purpose.  Usually we keep adding data to Map either in form of new entries or keep updating old entries with new data. In any case Map starts to bloat up,  keeping data in it infinitely or until we remove it. In such a case objects keep piling up on the Java Heep space and we eventually get an java.lang.OutOfMemoryError: Java heap space exception.

But we can avoid such a situation and create an extensible Map that can be used to hold information without Out-Of-Memory exception,  let me show you how. (more…)

July 1, 2010

Gigaspace Concepts: Space, Miror Space and Persistance

Filed under: java — Tags: — Rahul Sharma @ 8:38 pm

I have been using GigaSpace for some amount of time now and I must admit the product seems to 99% there but for the rest you have to scratch your own itch. It offers quite a lot but also lacks some basic stuff like testing support.

Since there is no inherent testing support in the package so we tried to make a sort of solution by making the Space up in the test case, running it and then getting the data out in the test case.  While doing so we initially though we would require three things “the space”,  a “mirror space” which is proxy to the space and a “persistence” where the data can be pulled for assertion.

But actually we ended up using “space” and “persistence” only. (more…)