Wednesday, June 26, 2013

Friday, June 14, 2013

Sending books to your Kindle

Found this article that introduced me to the SendToKindle desktop app from Amazon. This is the effective way of having your non Amazon books synced to your Kindle cloud account, so that all of your devices can have them, rather than side loading them. There are versions for PC and Mac.

Additionally, you can use Calibre to convert PDF docs to .mobi before sending them to your Kindle account. 

Thursday, May 16, 2013

Outputting JMX Monitoring Points

If you need to programmatically access all JMX monitoring points for your Servlet app, do the following:

1. Add the following VM arguments to the Tomcat Run Configuration (This can be done in Eclipse/STS run configurations):
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.port=8234
-Dcom.sun.management.jmxremote.ssl=false

2. Then run the following Java Program:
package com.rim.platform.mdm.core.service.email;

import java.io.IOException;
import java.util.Set;

import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectInstance;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

public class MonitoringPoints
{

    public MonitoringPoints()
    {
    }

    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception
    {
        String host = "localhost"; 
        int port = 8234;
        String url = "service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/jmxrmi";
        printAll(url);
    }

    public static void printAll(String url) throws IOException, MalformedObjectNameException, 
            InstanceNotFoundException, IntrospectionException, ReflectionException
    {
        JMXServiceURL serviceUrl = new JMXServiceURL(url);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceUrl, null);
        try
        {
            MBeanServerConnection mbeanConn = jmxConnector.getMBeanServerConnection();
            // now query to get the beans or whatever
            Set beanSet = mbeanConn.queryMBeans(null, null);
            for (ObjectInstance instance : beanSet)
            {
                MBeanInfo info = mbeanConn.getMBeanInfo(instance.getObjectName());
                MBeanAttributeInfo[] mai = info.getAttributes();
                System.out.println("\n******* Monitoring points for: " + instance.getObjectName());
                for (MBeanAttributeInfo object : mai)
                {
                    System.out.println(object.getName());
                }
            }
        }
        finally
        {
            jmxConnector.close();
        }
    }
}

Friday, November 16, 2012

Content assist for static imports in Eclipse

Take a look at the following link on how you can enable auto complete in Eclipse for static imports:
http://stackoverflow.com/questions/288861/eclipse-optimize-imports-to-include-static-imports

This is very helpful when you are writing JUnit and Mockito code. Below is the relevant part of the StackOverflow answer: 

Wednesday, October 31, 2012

Partial implementation of Interface

Java Stuff: If you are implementing an interface and planning on not supporting all the methods, it a good practice to do the following for not implemented methods:
        throw new org.apache.commons.lang.NotImplementedException.NotImplementedException(
                  "method not implemented by This class");

More details here:
http://stackoverflow.com/questions/1062937/java-equivalent-to-nets-notsupportedexception

Tuesday, October 9, 2012

Git Tricks

I started maintaining a new page at Zoho docs to document my git learning:

Sunday, August 5, 2012

Code highlighting in Blogger

There are helpful instructions on the link below for high-lighting code in your blogger posts:
http://lukabloga.blogspot.com/2008/10/to-test-new-highlighting.html

UPDATE: I found GitHub Gist to be a faster and elegant alternative

There are other alternatives here:
http://stackoverflow.com/q/679189/747479

Stack Overflow rocks!