To enable JGroups on ubuntu system

While you are using jgroups on ubuntu you might get this exception

INFO: JGroups version: 2.6.16.GA
org.jgroups.ChannelException: failed to start protocol stack
	at org.jgroups.JChannel.startStack(JChannel.java:1617)
	at org.jgroups.JChannel.connect(JChannel.java:366)
	at org.jgroups.demos.Draw.go(Draw.java:174)
	at org.jgroups.demos.Draw.main(Draw.java:144)
Caused by: java.lang.Exception: problem creating sockets (bind_addr=shekhar/127.0.1.1, mcast_addr=228.10.10.10:45588)
	at org.jgroups.protocols.UDP.start(UDP.java:389)
	at org.jgroups.stack.Configurator.startProtocolStack(Configurator.java:129)
	at org.jgroups.stack.ProtocolStack.startStack(ProtocolStack.java:402)
	at org.jgroups.JChannel.startStack(JChannel.java:1614)
	... 3 more
Caused by: java.net.SocketException: bad argument for IP_MULTICAST_IF: address not bound to any interface
	at java.net.PlainDatagramSocketImpl.socketSetOption(Native Method)
	at java.net.PlainDatagramSocketImpl.setOption(PlainDatagramSocketImpl.java:309)
	at java.net.MulticastSocket.setInterface(MulticastSocket.java:424)
	at org.jgroups.protocols.UDP.createSockets(UDP.java:527)
	at org.jgroups.protocols.UDP.start(UDP.java:385)

To solve this you need to disable ipv6 on ubuntu. To do that do the following

java -Djava.net.preferIPv4Stack=true -classpath /home/shekhar/JB431/opt/jboss-soa-p-5/jboss-as/lib/concurrent.jar:/home/shekhar/JB431/opt/jboss-soa-p-5/jboss-as/common/lib/commons-logging.jar:/home/shekhar/JB431/opt/jboss-soa-p-5/jboss-as/server/all/lib/jgroups.jar org.jgroups.demos.Draw
Advertisements

Introducing Spring Roo, Part 3: Developing Spring Roo add-ons

Spring Roo is a RAD tool that lets you build applications (mainly web) quickly and easily. Under the hood, Spring Roo is based on OSGI add-on architecture, which makes it easy to extend Spring Roo by adding add-ons. Spring Roo provides commands to create add-ons that can be very easily made available to the Spring Roo user community. In this article, we first talk about Spring Roo architecture, talking about how Spring Roo leverages its own add-on architecture to provide different features, then we will create add-ons using the Roo shell and modify them to suit our needs. Please read the third article at IBM DeveloperWorks.

Java Puzzler : They just find me !!

Couple of days back I wrote a piece of code which was behaving in an unexpected manner. I was confused what was happening. Take a look at the sample code below and predict its behavior

package com.shekhar;

public class JavaPuzzler {

	public static void main(String[] args) {
		JavaPuzzler javaPuzzler = new JavaPuzzler();
		javaPuzzler.doSth();
	}

	public void doSth() {
		float f = 1.2f;
		if (f >= 1.0) {
			f = 0.9999999999999f;
		}
		InnerClass innerClass = new InnerClass(f);
		System.out.println(innerClass.getValue());
	}

	private class InnerClass {

		private float value;

		public InnerClass(float value) {
			if (value >= 1.0f) {
				throw new IllegalArgumentException(
						"Value can't be greater than 1.0f");
			}

			this.value = value;
		}

		public float getValue() {
			return value;
		}
	}
}

My initial expectation was that I would get value 0.9999999999999f as answer.Try it and find the answer. Share your answer and reasoning in comments.

How to exclude a sub package from Spring component scanning?

Suppose you are using Spring component scanning and you don’t want to scan classes in the sub-package you should use <context:exclude-filter> subtag of <context:component-scan> tag as shown below

<context:component-scan base-package="com.test.ws">
	<context:exclude-filter type="aspectj" expression="com.test.ws.client.*" />
</context:component-scan>

Here we have defined a aspectj pointcut which will exclude all the classes in the sub-package.