Custom Search

Thursday, July 23, 2009

iBator eclipse plugin

If you are like me and you are into using iBatis eclipse plugin - check out http://ibatis.apache.org/ibator.html. It comes with an eclipse plugin that is quite useful if you are working with the ibatis configuration files.

Friday, July 17, 2009

Handling signals in Java

Signals by definition are specific to the underlying implementation ( read, operating system) .

Java, being a platform independent language , it is often discouraged to write platform specific stuff except for the rarest cases and when there is a clear business justification for the same.

Java does have an undocumented API that talks about signals where we can override the default signal handler for a given signal.  Scenarios where this might be useful and necessary are when we try to release resources ( connections etc.).

Note: When we override default signal handlers, it is important to delegate the behavior to the default handler implementation (Hint: Save the old handler when overriding the same) after we finish the current implementation.


package experiment;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import sun.misc.Signal;
import sun.misc.SignalHandler;

public class CustomSignalHandler implements SignalHandler
{

private static final Logger LOGGER = Logger.getLogger(CustomSignalHandler.class.getName());

private static Map<Signal, SignalHandler> handlers = new HashMap<Signal, SignalHandler>();


@Override
public void handle(Signal signal)
{
LOGGER.info("received " + signal);

// Delegate to the existing handler after handling necessary clean-up.
handlers.get(signal).handle(signal);
}


/**
* Important: This API is not portable but heavily platform dependent as the signal name depends
* on the underying operating system.

*
* @param signalName
* @param signalHandler
*/
public static void delegateHandler(final String signalName,
final SignalHandler signalHandler)
{
try {
Signal signal = new Signal(signalName);
SignalHandler oldhandler = Signal.handle(signal, signalHandler);
} finally {
handlers.put(signal, oldhandler);
}
}


public static void main(String[] args)
{
final int LONG_TIME = 50000;

SignalHandler example = new CustomSignalHandler();
delegateHandler("TERM", example);
delegateHandler("INT", example);
delegateHandler("ABRT", example);

try
{
Thread.sleep(LONG_TIME);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
}


Advanced Linux Programming

There is a new free e-book on advanced linux programming available here at - http://www.advancedlinuxprogramming.com/alp-folder  .

The chapter list is as follows.

  • Chapter 01 - Advanced Unix Programming with Linux
  • Chapter 02 - Writing Good GNU/Linux Software
  • Chapter 03 - Processes
  • Chapter 04 - Threads
  • Chapter 05 - Interprocess Communication
  • Chapter 06 - Mastering Linux
  • Chapter 07 - The /proc File System
  • Chapter 08 - Linux System Calls
  • Chapter 09 - Inline Assembly Code
  • Chapter 10 - Security
  • Chapter 11 - A Sample GNU/Linux Application
Among the list of chapters - chapter 7 and chapter 8 to some extent are especially useful and well-written where there are some good hidden treasures even for a seasoned linux professional.




Wednesday, July 1, 2009

Segmentation Fault - but no core dump ?

When I was working on a given binary - it gave me a "Segmentation Fault" but no core dump.

Started with the usual suspects .
* Checked the permission of the directory to see if the user has write permission to write the core file. It was ok.
* Checked the /tmp directory just in case.

Then I realized that I was working on bash, that sets core file size to be 0 automatically.

$ ulimit -a
core file size          (blocks, -c)   0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 20

..


Reset the same as below

$ ulimit -c unlimited


Now I ran my executable again and yes , this time the core dump is available for processing.




Wednesday, February 4, 2009

Linux AIO Examples

Tim Jones gives an excellent introduction and motivation behind aio here.  All 2.6 kernels have aio as a standard feature now.

Thursday, January 29, 2009

Elastic Block Store

Amazon comes up with another *potential* low-margin - high volume business by announcing Elastic Block Store today.
The most interesting feature is of course the facility to provide block level storage. The S3 service is already extremely popular - thanks to getting away from the relational model (which sometimes could end up being an overkill ) and reducing the headache of IT management for a potential entrepreneur .

EC2 service, no doubt - is much better to create your own instance of an image from scratch and use it. In spite of having free REST requests to the S3 service , the absence of persistence as such on the image instance was a drawback.

EBS provides us with block-level storage volumes that could be attached to an EC2 instance. As opposed to the other tools that has a much stepper adoption curve ( s3 needs some sort of wrapper around REST - the popular being JetS3t ) - this is probably as simple as it could get and hence it might increase the adoption rate compared to the rest.

I have not got the time to compare the pricing of EBS against the rest, but my guess is that people probably would not mind paying up for this given the level of comfort it gives to making the EC2 instances more usable.

Graphite - Visualization Tool

Orbitz, the popular travel planning website, had recently brought some of their (previously proprietary) projects into the public domain by making them open source.

Graphite is a scalable, real-time graph visualization tool, released under the Apache License.

Some of the interesting aspects of the same (courtesy, the FAQ of the software):


  • Written in Python, based on the Django project.
  • The rendering engine is based on the Cairo framework, the same rendering engine used for the rendering of content in the Firefox 3 browser.
  • The input data has to be a numeric time series. (This seems intuitive since graph visualization schemes, differences ought to be based on some quantitative measure eventually). And then, of course - any categorical metric could be mapped to preset numerical values to achieve a similar effect.



Graphite, seems to achieve the scalability by storing the entries in a distributed in-memory database, similar to what LiveJournal implements using the memcached service. And more recently, microsoft has started offering Velocity , a competing product in the same space (with subtle differences though- which I will cover later ).