Manually generating heapdumps in Websphere

This post explains the steps on generating heapdumps in Websphere on windows 

  1. Navigate to C:\IBM\SDP\runtimes\base_v7\bin
  2. Execute wsadmin.bat
  3. Execute the following in wsadmin prompt
set jvm [$AdminControl completeObjectName type=JVM,process=server1,*]
$AdminControl invoke $jvm generateHeapDump
$AdminControl invoke $jvm dumpThreads
Manually generating heapdumps in Websphere

Retrieveing Websphere Commerce Merchant Key

Here is a snippet of code to retrieve Merchant key in websphere commerce 7

final com.ibm.commerce.security.keys.WCKey keyName = com.ibm.commerce.security.keys.WCKeyRegistry.getInstance().getKey("MerchantKey");
final String merchantKey = keyName.getValueAsString();
System.out.println("merchantKey= "+merchantKey);
Retrieveing Websphere Commerce Merchant Key

Adding and Removing Spring initialized beans from Container

Yesterday one of my friend shoot a question on Spring bean management on runtime. His requirement is to remove bean for container and register it back after doing some operation.
The idea is straight, We might run into these situations depending on our business use cases complexities.

Here is a test case code snippet to remove bean and register it again to the spring container

Spring Context XML



        
	
		
			Shinu
		
	


JUnit Test class


package com.shinu.demo;

import javax.servlet.ServletContext;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.ConfigurableWebApplicationContext;
import org.springframework.web.context.support.XmlWebApplicationContext;

public class SpringWebDynamicCreationTest extends TestCase {

	final static Log logger = LogFactory
			.getLog(SpringWebDynamicCreationTest.class);

	protected static ConfigurableWebApplicationContext context;

	ServletContext mockServletContext;

	@Override
	protected void setUp() throws Exception {
		mockServletContext = new MockServletContext("/WebContent",
				new FileSystemResourceLoader());
		context = new XmlWebApplicationContext();
		context.setConfigLocations(new String[] { "/WEB-INF/config/springContext.xml" });
		context.setServletContext(mockServletContext);
		context.refresh();
		context.registerShutdownHook();
	}

	public void testAddAndRemoveObjects() throws ClassNotFoundException {
		Demo demo = getBean(context);
		assertEquals("Shinu", demo.getName());

		ConfigurableListableBeanFactory configurableListableBeanFactory = context
				.getBeanFactory();

		BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) configurableListableBeanFactory;
		// Removing the bean from container
		beanDefinitionRegistry.removeBeanDefinition("demo");
		
		// Trying to obtains bean again from container. This will throw a null		
		demo = getBean(context);
		//demo object will be null here
		assertNull(demo);
		
		// Creating and registering bean to the container		
		BeanDefinition beanDefinition = new RootBeanDefinition(Demo.class);
		beanDefinition.setAttribute("name", "Shinu");

		beanDefinitionRegistry.registerBeanDefinition("demo", beanDefinition);
		context.refresh();
	
		//Obtaining from container again
		demo = getBean(context);
		assertEquals("Shinu", demo.getName());

	}

	private static Demo getBean(ApplicationContext applicationContext) {		
		try{
			return (Demo) applicationContext.getBean("demo");
		}catch(NoSuchBeanDefinitionException e){
			return null;
		}
	}

}


Adding and Removing Spring initialized beans from Container

OpenGrok

I came to see one of my colleague using a source code browser today which is called as OpenGrok.
A very good source code browser and its straight away catch my eye because of the name, i see an ‘Open’. I did some research behind this app and found some thing interesting, the application is built using java, yes it is, worth take a look back at the source code. Another important thing to note is that this tool can very well exist with most of the source control systems. It use apache Lucen indexing and so on. Lot many exciting features.
I’m thinking of installing this in my group as well

OpenGrok

jvisualvm

jvisualvm – the application which provides the in and out of java apps running in a VM is out with jdk now. It is available with the jdk1.6 update. Really cool graphical interfaces which will show you the running threads, monitor the heap etc, and you can even profile the application using this tool. Nice set of plugins contributed by the community make this app a perfect choice for all folks who drink and eat java.

jvisualvm

Collections class inside java.util

The utility class contains static methods that operate or return collections.
Some of the useful static methods for developers daily use

  • sort – Collections.sort
  • binarySerach – List should be sorted first before invoking the search
  • reverse – Reverse the order of elements
  • swap – Swaps elements at the specified positions in the list
  • copy – Copies all the elements from one list to another
  • min – Returns the minimum element in the collection. Elements should implement Comparable (Overloaded method available which accepts a Comparator as the second argument)
  • max – Returns the maximum element in the collection. Elements should implement Comparable (Overloaded method available which accepts Comparator as the second argument)
  • replaceAll – Replaces all the occurrences of one specified value in a list with another
  • unmodifiableCollection – Returns an unmodifiable view of the collection. UnSupportedOperation exception will be thrown in any attempt to modify the returned collection. (UnModifiable List, Set and Map are also available)
  • synchronizedCollection – Returns a synchronized (thread-safe collection). (Synchronized Set, List and Map are also available) Its is very important to note that the end user who is doing the iteration over the collection has to manually do the synchronize.
  • checkedCollection – This is one of the useful method if programmers are not using java1.5. This will returns a dynamically typesafe view of the specified collection. An attempt to insert an element of the wrong type will result in a immediate ClassCastException (Checked List, Set and Map are also available)
  • singleton – Returns an immutable set containing only the specified object (Singleton List and Map are also available).
  • disjoint – Returns true if two specified collections have no elements in common
  • addAll – Adds all the specified elements to the specified collection
Collections class inside java.util

Vnstat GUI in JavaFX

After long analysis and exploration about the technology to use in developing the new gui project, i decided i’ll go with the lates JavaFX. Evaluated java-gnome also. But the lot goes to JavaFX. One of the main thing which strikes me with JavaFX is the richness in creating gui applications and the easiness in porting the this app to web with less effort.
The prototype is on her way and is in the very basic stage. Once the prototype is done, my plan is to create the project in google code and invite opensource developers around the world to contribute. All folks who are interested in playing with JavaFX and Linux can join and contribute.
The prototype which really influence me is the StockWatcher sample application. The vnstat gui will also look similar to this interface only.
Keep watch this space for more updates.

Vnstat GUI in JavaFX

Swing application framework

Swing application framework – a framework which will really give swing application developers a second life. Over a period of time swing applications gain more maturity and stability, but lack a framework and I believe this is the one which fills the gap. Some of the very common problems faced by swing developers are well addressed in this framework and provided implementations for them. Some of the exciting features from my angle are

1. Application Life cycle managment
2. Action management
3. Task management
4. Saving session state of the application
5. Local storage
6. Resource management

I’m planning to use the same framework for the creation of the swing based vnstat gui. I got some issues with my java install, my gui is not starting up properly. My AMD 64bit and java versions have slight hiccups with java gui’s. google is telling me to upgrade my java to the latest one will fix the issue. I need to upgrade my java tomorrow and start working.

Swing application framework

Internet usage using vnstat

My internet bill gave the first surprise yesterday. I got amazed after seeing my usage for the last one month. Unfortunately i do not have any option to check my usage from my provider. I decided to look for a good montoring tool in my opensource world itself. I came across nearly 15 good tools for monitoring the bandwidth usage, all are good but lacks some of the modules/functions i require. My search got ended up after seeing the cool small application vnstat. All the information i require is available at a single command. Just amazed to see such a wonderful command.
But one thing which clearly lacks is a wonderful gui which alerts me whenever i exceed my daily usage, hmmm quiet an annoying requirement, but yes i need that.
Finally i decided to come up with an interface for this cute command line in which I can incorporate my requirement also. I will be starting the work tomorrow. As a java developer, i need to find a real base for creating java desktop apps for Linux. I was evaluating some of projects for the past couple of days. One project which strikes me is the java-gnome project. But for developing an interface for vnstat i do not really require api’s from this particular project.

I believe core java api’s can provide me the stuff what i was looking for.

Internet usage using vnstat