Tuesday, January 10, 2017

Tutorial : Converting a java project to Maven project


Why Maven : You would find lot of articles on usage and power of Maven but in my experience biggest advantage is that you do not have to include/maintain those huge jar files in your code repository server. Very often real code or core of project runs into few mb's but if you include all the dependencies the size can become extremely bloated. With Maven in place developers (and consumers) can happily do quick rebase/clone commands, leaving the time consuming job of including dependencies to Maven. Best still if you have downloaded jars for other project, you do not have to download them again, and maven plugins in IDE (like Eclipse) handles the class paths transparently enough for you.

         


Imagine a scenario where you started off developing a java project and now would want to share it with developers/customers/testers etc. by leveraging Maven.There were a lot of hardships in converting your existing java projects into Maven earlier, but IDE plugins have have made developers life easier these days.

                                   


If you are using new releases of Eclipse, you already have a plugin installed m2e, if not you can download it from here : M2E Plugin

Steps to Convert

1. Right click on your existing project in eclipse and choose Configure -> Convert to Maven Project


                



2. Now you can open newly generated pom file in your project and add dependencies, and you can remove references from build path if you had added them manually.

3. If you want to get details on dependencies on jar files, try searching them on maven central. Once you click on the listed jar, you can get information like groupid, artifactid and version you want to use.


4. Once you have added all dependencies, right click on project and choose run as Maven clean, this should trigger download of all dependencies in your maven home directory. This also automatically adds dependencies to referenced libraries of your project, so you do not have to do it manually.

Tuesday, January 3, 2017

Story of an extra leap second and the mayhem it caused.

If you are not a programmer (or even if you are) chances are you missed the news of an extra second being added to clock. This was done to take care of earth slowing down fractionally for its rotation around sun, but that is not what I would be discussing in this blog.


 What I am going to discuss is the mayhem an extra second can cause to software's, specially the ones where performance measurements are done like Load Balancers (F5 etc.) or other DNS servers.

Now the gist of the problem is that developers assume time is Monotonic. In theory there seems nothing wrong with it, but think carefully and you would realize it is not always true. Consider a scenario where I need to calculate performance of a specific module, a quick way is to getTime at start of a function and do a getTime at end of a function and then subtract these 2 values. This seems perfectly correct, after all this is exactly what we do when referring to our stop watches on wrist right.



Important difference here though is no one suddenly makes your stop watch go faster or slower, which is not always true for a computer clock. When the time changes (Daylight or other occurrences like above), good NTP implementations take care of slowing (of fastening) clocks in a smoother manner, bad NTP implementations can change time with jerks on either side.

So your performance function can in all probability tell you that a piece of functionality finished off in less than 0 seconds. Which off-course you know is wrong and can lead to weird functional flows in your application, specially in an application like Load Balancer. 

So never assume time to be monotonic unless it has been guaranteed by underlying library you are using.

Lot of DNS server faced this when clocks stated adjusting to make up for the extra second, case in point being CloudFlare :How and Why leap second affected Cloudflare DNS

Always rely on better mechanisms like currentTimeMillis / nanoTime or if you are using libraries check if they support CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW.

Merging and Splitting PDF files

We all use and rely on PDF's. There are occasions though when you want to edit certain portions of a pdf and merge the edited version ba...