Patch For Flex Builder 3 Plugin to Work With Eclipse 3.4 (Ganymede)

I installed few days ago new version of Eclipse (Ganymede) and today I tried to install flex builder v3.

The installation went fine, but I got the following exception when trying to open Flex editor in Eclispe: “…org.eclipse.jface.util.Assert$AssertionFailedException: Assertion failed…”.

After Googling for some time I came across the following fix. So… there you go

Australian Citizenship – The lodgement

Finally the moment that I have been anticipating for has come – today I have lodged my application to become Australian citizen. Wooo hoooo :D

I’ve been waiting for this moment for the past 5 years, and now this is a dream come true! I still remember that day, that moment when I was sitting in an airplane and starring outside at Brisbane airport on a rainy July day…

.. and look at me now – I am applying to become a proud citizen of this beautiful and amazing country…

I cant really describe this feeling, but in one word?
Priceless …

Hibernate – How To Map Two Collections of The Same Type in The Same Entity

Recently during development, I encountered a situation where I had to map two collections in the same entity, having collections and the entity it self of the same type.

I had persistent entity – Rule. Rule could have children rules: “action” rules and “else” rules. Children rules were also of type Rule.

Basically it was a one-to-many relationship mapping of an entity to itself twice:
Entity Rule could have two different collections of the same object type – Rule. The collections represented “action” and “else” rules.

The challenge that I faced was during XML generation of the persisted entity Rule:

I could successfully persist entity Rule with its children Rules to DB. But, when I was generating the XML, Hibernate was not able to differentiate between “action” and “else” rules and was adding every child Rule to each collection. This was causing the same entity to appear once in each collection:

<?xml version="1.0" encoding="UTF-8"?>
<Rule id="1">
	<ruleType>-1</ruleType>
	<actionChildren>
		<rule>1</rule>
		<rule>2</rule>
	</actionChildren>
	<elseChildren>
		<rule>1</rule>
		<rule>2</rule>
	</elseChildren>
</Rule>

I needed to “tell” somehow to Hibernate which child entity Rule should be added to which collection. I am not sure if my solution is the best in this case, but I created a discriminator property inside entity Rule – “ruleType”.

Respectively, in HBM file, in the mappings of one-to-many relationships, I specified by using SQL query, which rules should be added to the collection when XML is generated. The SQL query was inside where attribute of <list> element.

It done the trick for me – when I was adding a child rule to a parent entity, I was specifying child rule type. Therefore, Hibernate was generating XML correctly by adding “action” rules and “else” rules to their respective collections.

Here is entity Rule:

package org.example.rules;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Rule implements
			Serializable {

private static final long
	serialVersionUID = -76784L;

private int idx;
private int ruleType = -1;
private Rule parentRule = null;

private List<Rule> actionChildren =
		new ArrayList<Rule>();

private List<Rule> elseChildren =
		new ArrayList<Rule>();

/**
 * Default constructor
 */
public Rule() {

}

/**
 * @return the 'action' children
 */
public List<Rule> getActionChildren() {
	return actionChildren;
}

/**
 * @param children
 *            'action' children to set
 */
public void setActionChildren(List<Rule> actionChildren) {
	this.actionChildren = actionChildren;
}

/**
 * @return the 'else' children
 */
public List<Rule> getElseChildren() {
	return elseChildren;
}

/**
 * @param children
 *            'else' children to set
 */
public void setElseChildren(List<Rule> elseChildren) {
	this.elseChildren = elseChildren;
}

/**
 * Adds an 'action' child to the current rule
 *
 * @param actionChild
 *            The rule to be added as a child
 */

public void addActionChild(Rule actionChild) {
	if (!this.actionChildren.contains(actionChild)) {
		actionChild.setParentRule(this);
		this.actionChildren.add(actionChild);
	}
}

/**
 * Adds an 'else' child to the current rule
 *
 * @param elseChild
 *            The rule to be added as a child
 */

public void addElseChild(Rule elseChild) {
	if (!this.elseChildren.contains(elseChild)) {
		elseChild.setParentRule(this);
		this.elseChildren.add(elseChild);
	}
}

/**
 * @return the ruleType
 */
public int getRuleType() {
	return ruleType;
}

/**
 * @param ruleType
 *            the ruleType to set
 */
public void setRuleType(int ruleType) {
	this.ruleType = ruleType;
}

/**
 * @return collection index
 */
public int getIdx() {
	return idx;
}

/**
 * Sets collection index
 * @param collection index
 */
public int setIdx(int idx) {
	this.idx = idx;
}

/**
 * @return parent rule of the current rule
 */
public Rule getParentRule() {
	return parentRule;
}

/**
 * @param ruleParent
 *            the ruleParent to set
 */
public void setParentRule(Rule parentRule) {
	this.parentRule = parentRule;
}
}

Rule HBM file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="org.example.rules.Rule"
	table="org_example_rules_Rule" node="Rule">

<id name="id" column="id" node="@id"
			unsaved-value="0">
	<generator class="native" />
</id>

<!--
Used to help Hibernate to discriminate
between children rules
-->
<property name="ruleType" column="ruleType"
								node="ruleType" />
<!--
Attribute 'where' holds SQL query used to help Hibernate
to discriminate between children rules of type 'action'
and children rules of type 'else'.

Since two children rule lists in the current HBM are of
the same type (org.example.rules.Rule), Hibernate needs
a 'hint' how to discriminate which rules belong to
which list when XML is generated.

If ruleType equals to '1', it means that the child
rule is 'action' rule.

If ruleType equals to '2', it means that the child
rule is 'else' rule.
-->
<list name="actionChildren" embed-xml="true"
		where="ruleType=1" cascade="all">

	<key column="parentrule_id" />
	<list-index column="idx" base="0" />
	<one-to-many class="org.example.rules.Rule"
		node="rule" embed-xml="false" />
</list>

<!--
If ruleType equals to '2', it means that the child
rule is 'else' rule.
-->
<list name="elseChildren" embed-xml="true"
		where="ruleType=2" cascade="all">

	<key column="parentrule_id" />
	<list-index column="idx" base="0" />
	<one-to-many class="org.example.rules.Rule"
		node="rule" embed-xml="false" />

</list>

<!--
Read-only index column, represents position of
the element in the list
-->
<property name="idx" column="idx" node="idx"
		update="false" insert="false" type="int" />

<!--
Embed XML must be equals to 'false',
otherwise when XML is generated for
children rules, parent XML will be
generated recursively
-->
<many-to-one name="parentRule" node="parentRule"
	column="parentrule_id" class="org.example.rules.Rule"
	not-null="false" insert="false" update="false"
	embed-xml="false" />

</class>
</hibernate-mapping>

Generally, I would not advise to design persistent entities in this way, it can create problem later on. For example if there is a need to delete child entities. It can become a bit tricky, since entity has relationship to it self.

Suggestions? Flames?

Brainteaser: Hidden Iterators

… While locking can prevent iterators from throwing ConcurrentMofdificationException, You have to remember to use locking everywhere a shared collection might be iterated. This is trickier than it sounds …

Brian Goetz p.83-84

Question: The following code could throw ConcurrentMofdificationException, even though add() is synchronized, why?

public class HiddenIterator  {
     private final Set set = new HashSet();

public synchronized void add(Integer i) {
     set.add(i);
}

public synchronized void remove(Integer i) {
     set.remove(i);
}

public void addTenThings() {
   Random r = new Random();
   for (int index = 0; index &lt; 10;  index++;) {
       add(r.nextInt());
   }

   System.out.println("Added ten elements to set: " + set);
}
}

Looking forward for your answers dear readers

Singleton Pattern and Problem With Double Checked Locking

There are several ways to initialize singleton object. Some are thread safe and some are not. Until the last two days I thought that double-checked locking idiom offers the best solution for singleton initialization in multi threaded environment. Well its not.

To begin, I want to describe briefly several ways to initialize singleton:

  • Lazy initialization
  • Eager initialization
  • DCL
  • Class holder lazy initialization
  • Enum singleton

Lazy initialization
The goal of lazy initialization was to defer initialization of an object until it is actually needed, while making sure that initialization is done only once. Lazy initialization example illustrated below:

public class Singleton{

	private static Singleton instance = null;

	private Singleton() {  }

	public static Singleton getInstance() {
		if (instance == null)  {
		instance = new Singleton();
	}
        return instance;
    }
}

This will work fine in single-threaded environment. Unfortunately since getInstance() is not synchronized, two different instances of the object can be returned if two threads will access getInstance() method concurrently. Which makes this lazy initialization unsafe in multi threaded environment.

Unsafe lazy initialization can be fixed by making getInstance() synchronized:


	public class Singleton{

	private static Singleton instance = null;

	private Singleton() {  }

	public static synchronized Singleton getInstance() {
		if (instance == null)  {
			instance = new Singleton();
		}
		return instance;
	}
	}

However, in this case there is performance hit for every invocation of getInstance() method. Synchronized methods runs very slow compared to unsynchronized methods. I haven’t tested this issue my self, so i cannot tell by how much slower.

Eager initialization
By using eager initialization, the synchronization cost incurred for each method call is eliminated:

	public class Singleton{
		private static Singleton instance = new Singleton();

		private Singleton() {  }

		public static Singleton getInstance() {
			return instance;
		}
	}

The problem with eager initialization that Singleton object is instantiated regardless whether it is going to be used or not.

DCL
Double-checked locking (DCL) idiom was created to allow lazy initialization of a singleton object, without performance reducing costs as a result of synchronization. Unfortunately it does not work. Lets have a look why:

public class Singleton {

  private static Singleton instance = null;

  private Singleton() {  }

  public static Singleton getInstance() {
	if (instance == null)  {
		synchronized(Singleton.class)  {
			if (instance == null)  {
				instance = new Singleton();
			}
		}
	}
	return instance;
	}
}

First there is a check whether initialization is needed with out synchronization, and if the instance is not null – then use it.
Otherwise, synchronize and check again if instance is null by making sure that only one thread will initialize the shared Singleton.

The problem with DCL is that code of fetching reference to constructed Singleton object does not require synchronization.
Lets say that thread ‘a’ has entered synchronized block, made the instance not null but hasn’t executed the constructor yet. At this stage thread ‘b’ preempts thread ‘a’. Thread ‘b’ checks if the instance is not null, and since its not, it returns reference to a partially constructed Singleton object.

In other words – thread ‘b’ sees a current value of the Singleton object reference instead of its stale value, which causes the object to be seen in invalid or incorrect state.

Class holder lazy initialization

Instead of DCL, lazy initialization class holder idiom offers better solution for singleton initialization in multi threaded environment, with the same benefits as DCL:

public class SingletonFactory {

  private static class SingletonHolder {
     public static Singleton instance = new Singleton();
  }

  public static Singleton getInstance()  {
     return SingletonHolder.instance;
  }
}

The SingletonHolder class initialization is deferred until its actually used, and because Singleton is initialized with static initializer, no additional synchronization is needed.
The first invocation of getInstance() by any thread causes SingletonHolder to be loaded and initialized during which time the Singleton is initialized through static initializer.

Enum singleton
Joshua Bloch in his book “Effective Java” offers a new interesting solution to initialize a Singleton by using Enum with a single type:

public class SingletonEnum {
  INSTANCE;

  public void someMethod() {
     ...
  }

  public void anotherMethod() {
     ...
  }
}

Joshua claims:

“…a single-element enum type is the best way to implement a singleton…”

Some people may argue against this approach by saying that this is not a class, but an enum – it enumarates plus enums cannot be subclassed. Well in case of a singleton there is no point in subclassing, since singletons have private constructors and singletons dont really ment to be subclassed. Lets have a look if Enum singleton is indeed the best solution so far:

1. Enum singleton is final
2. It is serializable
3. It is a single instance in multithreaded environment
4. Does not allow invokation of private constructors through reflection attacks

I think its quite original solution.

I will appreciate your comments regarding this post. Cheers.

Resources:
Effective Java
Java Concurrency in Practice

Double-checked locking and the Singleton pattern

Drools – Stop Executing Current Agenda Group and All Rules

Sometimes, depends on your business rules in your application, there is a need to stop current agenda group or all rules from continuing to execute. It wont help setting a focus to another agenda group, since previous agenda will still remain in a stack. So in this post I want to show how to prevent rules in a particular agenda group from continuing to execute by clearing the agenda and also how to stop all rules totally.

Please note, in this example I am using agenda-groups to drive execution flow.

I created a short DRL file and a DSL template to demonstrate how clearing agenda and stopping of all rules can be achieved.

The DRL file:

expander template.dsl;

/*****************************************
 First default rule to kick in
******************************************/
rule "baserule"
salience 100000
auto-focus true
agenda-group "first-group"
when
      True
then

end

/*****************************************
 Second rule to kick in
******************************************/
rule "1"
salience 1000
agenda-group "first-group"
when
      True
then
      Goto agenda "second-group"
end

/*****************************************
 Third rule to kick in
******************************************/
rule "2"
salience 1000
agenda-group "second-group"
when
      True
then
      Do something
end

/*****************************************
 Fourth rule to kick in

 Current rule stops agenda "second-group"
 from continuing to execute, and the
 focus will be returned back to
 agenda "first-group"
******************************************/
rule "3"
salience 900
agenda-group "second-group"
when
      True
then
      Stop agenda "second-group" //clear current agenda
end

/*****************************************
 This rule never kicks in, since agenda
 "second-group" was cleared by rule "3"
******************************************/
rule "4"
salience 800
agenda-group "second-group"
when
      True
then
      Do something
end

/*****************************************
 Fifth rule to kick in

 After clearing agenda "second-group", the
 focus will be returned here
******************************************/
rule "5"
salience 900
agenda-group "first-group"
when
      True
then
      Do something
end

/*****************************************
 Sixth rule to kick in
 Current rule stops execution of all rules
******************************************/
rule "6"
salience 800
agenda-group "first-group"
when
      True
then
      Stop all
end

/*****************************************
 This rule never kicks in, since all rules
 execution was stopped by rule "6"
******************************************/
rule "7"
salience 700
agenda-group "first-group"
when
      True
then
      Do something
end

The DSL template:

[when]True=eval(true)
[then]Do something=
      System.out.println("Doing something");
[then]Stop all=drools.halt();
[then]Goto agenda "{agenda}"=
      drools.setFocus( "{agenda}" );
[then]Stop agenda "{agenda}"=
      drools.getWorkingMemory().
		clearAgendaGroup("{agenda}");

Basically what happens is: once the execution reaches rule “3″, I am calling for clearAgendaGroup() method to clear agenda, hence to remove it from the stack. As a result of the clearing, rule “4″ will never be executed.

When focus is returned back to agenda “first-group”, it lands on rule “5″. When the execution reaches rule “6″, I am calling for drools.halt() method to stop execution of all rules.

Keep in mind that in Drools 3 there is no halt() method. It came with Drools 4. If you want to achieve the above result of stopping all rules in Drools 3, you can call for drools.clearAgenda();

You noticed that I am using “drools” object and calling some methods on that object in my DSL template. Well “drools” object is actually KnowledgeHelper class, which is part of Drools library. It provides several APIs, for example method halt(), setFocus() and getWorkingMemory().

Keep in mind that I did not actually tested these particular DRL and DSL, but this example is based on real scenario that I have tested.

Comments/questions/flames are welcomed

Ouch!

Yesterday one of the developers that I work with lost all his work that he has done for the past two months! Apparently what happened was that the poor bagger did not commit anything to CVS for the past two months. So yesterday for some mysterious reason he has overridden his local changes with the outdated copy of the source code from CVS and tried to recompile everything. I don’t know why he did it.

I think he was almost crying telling me about the amount of work that was lost. During the conversation, it became obvious to me that for his luck, he had somewhere all the classes JARed as a backup (from before he has overridden the changes).

When I heard it, I said “Dude… you can decompile the classes! You can get the source code back” …

Ohhh… the look on his face after I said it – priceless …

Marshalling VS Serialization

The two terms are very very similar, and often treated the same. Quite few responds on various forums contradict each other, which made me a bit confused. So to make it clear for my self I decided to summarize what i understood from the resources I have read on the Internet:

Serialization:

  1. Technique of converting a state of an object (or object instance in different words) into a byte stream.
  2. To send object over the network, it needs to be serialized first, thus converted into to a sequence of bytes.

Marshalling:

  1. Technique of encoding an object to send it over the network and decoding it on the other end. Which is stub and skeleton mechanism, where stub is the local client and skeleton is the remote server.
  2. Besides the object state, marshalling also records codebases.
  3. Marshalling is used for sending objects through sockets. Off course objects must be serialized serialized before sending over the network.
  4. Marshalling is a way to create byte stream so that the copy of the original object can be recreated on the other side. When object is “unmarshalled” on the other side, object’s class definitions are loaded.
  5. Marshalling is a form of serialization, thats why I think some people treat teh two the same.

Thats it… I think… Did I miss something?

JBoss Clustering Architecture – Distributed Replicant Manager

My understanding of Distributed Replicant Manager (DRM) is that it allows you to attach some serialized data (stub) to a cluster node and manage it.

Examples of this data include the list of stubs for a given RMI server. Each node has a stub to share with other nodes. The DRM enables the sharing of these stubs in the cluster, and allows one to know which node each stub belongs to.

In case one of the nodes leaves the cluster, its stub is automatically removed from the list of replicants (stubs) that DRM maintains.

Also for each set of replicants DRM holds an id, which is identical on all nodes in the cluster.

I used DRM to attach a replicant to a node in the cluster. The replicant contains a String which holds a node IP that i get from jboss.bind.address property. Every time my cluster is going through a topology changes, my service bean on the master node will prints out replicant list.

My service MBean as follows:

package com.example;

public class CoordinatorHAService extends
	HASingletonSupport implements
			CoordinatorHAServiceMBean  {

    private static Logger logger =
	Logger.getLogger(CoordinatorHAService.class);

	/**
	 * Can be used instead of the constructor
	 * defined in jboss-service.xml
	 */
	private static final String BIND_ADDRESS =
		System.getProperty("jboss.bind.address");

	/**
	 * Custom name for this HA partition, overrides
	 * the default HA partition name which is
	 * canonical name of this MBean
	 */
	private final static
	String COORDINATOR_HA_SERVICE_NAME =
		"ServiceName:CoordinatorHAService";

	/**
	 * Current node IP
	 */
	private String nodeIp = null;

	/**
	 * Constructor that gets value of this node IP
	 * from 'jboss.bind.address' property
	 * defined in jboss-service.xml
	 *
	 */
	public CoordinatorHAService(String nodeIp) {
		this.nodeIp = nodeIp;

	}

	public void startService() throws Exception {

	try {
	/**
	 * Call for super must be done before getting
	 * HAPartition. If super is not called, HAPartition
	 * will be 'null'
	 *
	 * Alternatively you can use InitialContext to get
	 * default partition, then you dont have to make
	 * a call for super.startService(). I havent
	 * tested it, so I am not sure of the results.
	 *
	 *
	 * InitialContext ic = new InitialContext();
	 * String partitionName = ServerConfigUtil.getDefaultPartitionName();
	 * String partitionJndi = "/HAPartition/" + partitionName;
	 * HAPartition partition = (HAPartition) ic.lookup(partitionJndi);
	 */
		super.startService();

	/**
	 * HAPartition gives access to the replicant manager,
	 * which I am using to add node replicants to.
	 */
		HAPartition partition = super.getPartition();

		if (partition != null) {
			partition.getDistributedReplicantManager().add(
					this.getServiceHAName(), this.getNodeIp());
		}

		} catch (Exception e) {
			this.stopService();
		}

	}

	synchronized public void stopService() throws Exception {
		super.stopService();
	}

	public boolean isMasterNode() {
		return super.isMasterNode();
	}

	/**
	 * Called when node is elected as a master node
	 */
	public void startSingleton() {

	}

	/**
	 * Called when node stops acting as a master node
	 */
	public void stopSingleton() {

	}

	/**
	 * Override this method only if you need to provide
	 * a custom partition wide unique service name.
	 * The default implementation will usually work,
	 * provided that the getServiceName() method returns
	 * a unique canonical MBean name.
	 *
	 */
	public String getServiceHAName() {
		// return super.getServiceHAName();
		return CoordinatorHAService.COORDINATOR_HA_SERVICE_NAME;
	}

	/**
	 * Called when there are topology changes in the cluster.
	 */
	public void partitionTopologyChanged(List newReplicants,
												int newViewID) {
		super.partitionTopologyChanged(newReplicants,
												newViewID);

		/**
		 * If current service is the master node -
		 * print replicants in the cluster
		 */
		if (this.isMasterNode()) {

			List clusterNodeIps =
				new LinkedList(newReplicants);

			for (String clusterNodeIp : clusterNodeIps) {
				logger.info("Replicant IP: " + clusterNodeIp);
			}
		}

	}

	/**
	 * Gets current node's IP
	 */
	public String getNodeIp() {
		return nodeIp;
	}
}

..and this is my jboss-service.xml below:

<?xml version="1.0" encoding="UTF-8"?>

<server>
    <mbean
	code="com.example.CoordinatorHAService"
	name="com.example:service=CoordinatorHAService">
	<constructor>
	<arg type="java.lang.String"
		value="${jboss.bind.address:127.0.0.1}" />
	  </constructor>
     </mbean>
</server>

In JBoss clustering architecture, DRM sits on top of HAPartition which abstracts the communication framework.

Maybe this is not the most right way to do it, but I do find DRM useful if I want to manage information about my cluster nodes, and I dont want to rely on HAPartition to provide me with such information.

The moment a new node joins the cluster, I insert its IP to my set of replicants. So I always have accurate and recent information about nodes in my cluster. In case of a dead node, my list of replicants gets updated with IP of the dead node removed from the list. The source code is attached to this post or you can just do copy/paste if you feel like it.

JBoss clustering is a very big topic. So if someone is interested, JBoss group provides a PDF book called JBoss AS Clustering on their website, its really useful and easy to understand. It walks through and talks about fundamental concepts of clustering. The book is a bit long but worth while to have a look ;)

Any comments or/and flames about this post are welcomed …

cheers

jboss clustering replicant manager sourcecode

Java Generics and Reflection

Hi, the other day I had a situation, where in my code at run time I had to determine the super type of the Class that I obtained. To sub type my classes, I used generics.

In case my obtained Class was of expected super type, I had to invoke a super class static method on the subclass Class using reflection.

I used these concepts and prepared a short tutorial, I also attached source files to this post in case someone wants to download them. What I did was I created an abstract class, and an extending child class using generics. In my test client, I determine the super type of my child class at run time and then I invoke a static method using reflection.

Reflection also allows to invoke methods, constructors and change value of fields that are private. It is often called “reflection attack”. In my post Hack any Java class using reflection attack, I give several examples about reflection attack.

Ok, back to the topic now:

My abstract parent class:

import java.io.Serializable;
import java.util.Date;

public abstract class AbstractParentEntity
		<E extends AbstractParentEntity>
				implements Serializable {

    private static final
	long serialVersionUID = 5419258598746186610L;

	public static Long getSomeLongValue() {
		return new Long(999);
	}

}

My extending child class:

import java.io.Serializable;

public class ChildEntity extends
	AbstractParentEntity<ChildEntity>
			implements Serializable {

     private static final long
	serialVersionUID = -2271176823058287608L;

	private String name;

	public ChildEntity()  {

	}
}

My test client:

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;

public class Test {

	//canonical name of my child class
	private static final String
		CHILD_CLASS_NAME = "ChildEntity";
	//name of the static method i am going to invoke
	private static final String
		PARENT_METHOD = "getSomeLongValue";

   public static void main(String[] args) {

	Thread thread = Thread.currentThread();

	ClassLoader classLoader =
			thread.getContextClassLoader();

	try {

	//use class loader to create a Class for
	//a given class name
	Class subclass = Class.forName(CHILD_CLASS_NAME,
				true, classLoader);
	System.out.println("Subclass canonical name: ["
		+ subclass.getCanonicalName() + "]");

	//get superclass Class from the subclass
	Class superclass = subclass.getSuperclass();
	System.out.println("Super class canonical name: ["
		+ superclass.getCanonicalName() + "]");

	//get the type of subclass
	Type subtype = subclass.getGenericSuperclass();
	System.out.println("Subclass type: ["
		+ subtype.toString() + "]");

	//check whether my subclass type starts with
	//class name of my super type, if true - my subclass
	//is indeed of type of my superclass
	if (subtype.toString().startsWith(
			superclass.getCanonicalName())) {

	System.out.println("Class: [" +
		subclass.getSimpleName()
		+ "] is type of ["
		+ superclass.getSimpleName() + "]");
	}

	// 'null' assumes empty array
	Method method = subclass.getMethod(PARENT_METHOD,
				(Class[]) null);

	/*
	* public Object invoke(Object obj, Object args)
	*
	* If the underlying method is static, then the specified 'obj'
	* argument is ignored. It may be null.
	*
	* Parameters: obj - the object the underlying method is invoked
	* from args - the arguments used for the method call
	*/

	System.out.println("Invoking static parent method: [" +
		PARENT_METHOD + "] on extending subclass...");
	Object objResult = method.invoke(null, (Object[]) null);

	System.out.println("Some value: [" + objResult.toString() + "]");

	}
	catch (SecurityException e) {
		e.printStackTrace();
	}
	catch (NoSuchMethodException e) {
		e.printStackTrace();
	}
	catch (IllegalArgumentException e) {
		e.printStackTrace();
	}
	catch (IllegalAccessException e) {
		e.printStackTrace();
	}
	catch (InvocationTargetException e) {
		e.printStackTrace();
	}
	catch (ClassNotFoundException e) {
		e.printStackTrace();
	}

	}
}

Basically what happens is: iI compare whether the Type of my subclass: AbstractParentEntity starts with the canonical name of my super class: AbstractParentEntity.

When using generics, this will always return true if my subclass extended from my super class.

When I successfully determined the subclass type, i invoked static method using reflection. Below you can see the output of my program:

Subclass canonical name: [ChildEntity]
Super class canonical name: [AbstractParentEntity]
Subclass type: [AbstractParentEntity<ChildEntity>]
Class: [ChildEntity] is type of [AbstractParentEntity]
Invoking static parent method: [getSomeLongValue] on extending subclass...
Some value: [999]

If you never used generics in Java (those who moved on to Java from C++ will know what generics are), Sun offers a nice generics introduction tutorial which explains the basics.

Basically generics allow you to abstract over types. When you use generics in your code it becomes safer and clearer. So i think it worth while having a pick at it :)

Comments / corrections / flames?