Recent Posts
Archives

PostHeaderIcon When WebLogic always routes on the same node of the cluster…

Case

Since a couple of days I have met the following issue on my WebLogic server: one application is deployed on a cluster, which references two nodes. Load-balancing (in Round-Robin) is activated for JMS dispatching.

  • Yet, all JMS messages are received only by one node (let’s say “the first”), none is received by the other (let’s say “the second”).
  • When the 1st node falls, the 2nd receives the messages.
  • When the 1st node is started up again, the 2nd keeps on receving the messages.
  • When the 2nd node falls, the 1st receives the messages
  • and so on

Fix

In WebLogic console go to JMS Modules. In the table of resources, select the connection factory. Then go to the tab Configuration and Load Balance. Uncheck “Server Affinity Enabled“.

Now it should work.

Many thanks to Jeffrey A. West for his help via Twitter.

PostHeaderIcon MissingResourceException / Mule / i18n

The following error is among of the most hated ones in Mule ESB:
[java]java.util.MissingResourceException: Can’t find bundle for base name META-INF.services.org.mule.i18n.core-messages, locale en_US[/java].

I am not going to describe how to fix it, since several and various reasons may induce it. Anyway, here is an action plan to track and isolate the bug when it happens.

Usually, this MissingResourceException hides the actual error, instead of encapsulating and throwing it. For instance, consider the following stacktrace:
[java]Can’t find bundle for base name META-INF.services.org.mule.i18n.core-messages, locale en_USjava.util.MissingResourceException: Can’t find bundle for base name META-INF.services.org.mule.i18n.core-messages, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1427)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1250)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:952)
at org.mule.config.i18n.MessageFactory.getBundle(MessageFactory.java:211)
at org.mule.config.i18n.MessageFactory.getString(MessageFactory.java:181)
at org.mule.config.i18n.MessageFactory.createMessage(MessageFactory.java:108)
at org.mule.config.i18n.MessageFactory.createMessage(MessageFactory.java:59)
at org.mule.config.i18n.CoreMessages.initialisationFailure(CoreMessages.java:400)
at org.mule.module.scripting.expression.AbstractScriptExpressionEvaluator.getScript(AbstractScriptExpressionEvaluator.java:93)
at org.mule.module.scripting.expression.AbstractScriptExpressionEvaluator.evaluate(AbstractScriptExpressionEvaluator.java:54)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:274)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:210)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:170)
at org.mule.transformer.simple.MessagePropertiesTransformer.addProperties(MessagePropertiesTransformer.java:165)
at org.mule.transformer.simple.MessagePropertiesTransformer.transformMessage(MessagePropertiesTransformer.java:93)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:145)
at org.mule.transformer.AbstractMessageTransformer.transform(AbstractMessageTransformer.java:93)
at org.mule.DefaultMuleMessage.applyAllTransformers(DefaultMuleMessage.java:1305)
at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1265)
at org.mule.DefaultMuleMessage.applyTransformers(DefaultMuleMessage.java:1258)
at org.mule.transformer.AbstractTransformer.process(AbstractTransformer.java:118)
at org.mule.processor.ExceptionHandlingMessageProcessor.process(ExceptionHandlingMessageProcessor.java:25)
at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:185)
at org.mule.transport.AbstractReceiverWorker$1.doInTransaction(AbstractReceiverWorker.java:126)
at org.mule.transaction.TransactionTemplate.execute(TransactionTemplate.java:116)
at org.mule.transport.AbstractReceiverWorker.doRun(AbstractReceiverWorker.java:149)
at org.mule.transport.AbstractReceiverWorker.run(AbstractReceiverWorker.java:64)
at org.mule.work.WorkerContext.run(WorkerContext.java:309)
at org.mule.work.SyncWorkExecutor.doExecute(SyncWorkExecutor.java:41)
at org.mule.work.MuleWorkManager.executeWork(MuleWorkManager.java:251)
at org.mule.work.MuleWorkManager.doWork(MuleWorkManager.java:175)
at org.mule.transport.jms.MultiConsumerJmsMessageReceiver$SubReceiver.onMessage(MultiConsumerJmsMessageReceiver.java:326)
at com.ibm.mq.jms.MQMessageConsumer$FacadeMessageListener.onMessage(MQMessageConsumer.java:399)
at com.ibm.msg.client.jms.internal.JmsMessageConsumerImpl$JmsProviderMessageListener.onMessage(JmsMessageConsumerImpl.java:1023)
at com.ibm.msg.client.wmq.internal.WMQAsyncConsumerShadow.honourNoLocal(WMQAsyncConsumerShadow.java:566)
at com.ibm.msg.client.wmq.internal.WMQAsyncConsumerShadow.consumer(WMQAsyncConsumerShadow.java:400)
at com.ibm.mq.jmqi.remote.internal.RemoteAsyncConsume.driveConsumer(RemoteAsyncConsume.java:1527)
at com.ibm.mq.jmqi.remote.internal.RemoteDispatchThread.run(RemoteDispatchThread.java:395)
at com.ibm.msg.client.commonservices.workqueue.WorkQueueItem.runTask(WorkQueueItem.java:209)
at com.ibm.msg.client.commonservices.workqueue.SimpleWorkQueueItem.runItem(SimpleWorkQueueItem.java:100)
at com.ibm.msg.client.commonservices.workqueue.WorkQueueItem.run(WorkQueueItem.java:224)
at com.ibm.msg.client.commonservices.workqueue.WorkQueueManager.runWorkQueueItem(WorkQueueManager.java:298)
at com.ibm.msg.client.commonservices.j2se.workqueue.WorkQueueManagerImplementation$ThreadPoolWorker.run(WorkQueueManagerImplementation.java:1220)V.
[/java]

In IntelliJ IDEA, do Analyse > Analyse Stacktrace... > paste the trace (I have been shown the same tool for Eclipse, somewhere in the Console view). Now you can navigate easily in the code. Then you can notice, line #11, that the Exception you receive is raised by AbstractScriptExpressionEvaluator.
The corresponding piece of code is:
[java] try
{
script.initialise();
}
catch (InitialisationException e)
{
throw new MuleRuntimeException(
CoreMessages.initialisationFailure("An error occurred initialising script."), e);
}[/java]

Add a breakpoint at the level of the throw. Start the debugger, reproduce the bug. In the debugger, you can see the actual error, that is hidden in the stacktrace. In my case, it was a:
[java]org.mule.api.lifecycle.InitialisationException: Scripting engine ‘groovy’ not found. Available engines are: [com.sun.script.javascript.RhinoScriptEngineFactory@3d2227][/java]. Without the debugger, it would have been hard to guess that the original MissingResourceException was linked to a missing Groovy resource ;-).

PostHeaderIcon Sonar / Synchronization on interned XYZ could lead to deadlock

How to fix the Sonar’s following report?
[java]Multithreaded correctness – Synchronization on interned String could lead to deadlock [/java]

Replace lock on String with a lock on an immutable and/or non-serializable object, ie a simple Object.
Eg:
Replace:
[java] synchronized ("myString") {…}[/java]
With:
[java] synchronized (myObject) {…}[/java]

PostHeaderIcon Sonar / Inefficient use of keySet iterator instead of entrySet iterator

How to fix the Sonar’s following report?
[java]Performance – Inefficient use of keySet iterator instead of entrySet iterator[/java]

The report is explicit: replace loop on keySet with a loop on entrySet, which is faster
Eg:
Replace:
[java]for (Integer key : stressList.keySet()){
Stress stress = stressList.get(key);
}[/java]
With:
[java]for (Map.Entry<Integer, Stress>integerStressEntry : stressList.entrySet()){
Stress stress = integerStressEntry.getValue();
}[/java]

Yet, if you need only keys or only values of your Map, then use rather keySet() or values().

PostHeaderIcon Sonar / Constructor Calls Overridable Method

How to fix the Sonar’s following report?
[java]Constructor Calls Overridable Method [/java]

In the constructor of your class, assign the parameters to the right fields using the ‘=’ operator, and not the setXXX() methods. Indeed, the latter may be overriden by subclass.
Eg:
Replace:
[java]public Constructor(Param param){
setField(param);
}[/java]
With:
[java]public Constructor(Param param){
this.field = param;
}[/java]

PostHeaderIcon Sonar / Dead store of null to local variable

How to fix the Sonar’s following report?
[java]Dodgy – Dead store of null to local variable[/java]

Remove assignments at null of local variables that will not be read. Since Java 6, they have no interest and no effect on garbage collector.
Eg: remove the last assignment, in the line#4 [java]void foo(){
String goo = "hello world";
(…)
goo = null;
}[/java]

PostHeaderIcon Twitter within GoogleReader

Let’s say immediatly there is no miracle solution and it required a bit of work…

If the title is not explicit enough, the goal of this post is to give a way to include Twitter flow within your GoogleReader. IMHO, the main features of GoogleReader over regular Twitter are the following:

  • posts are stored on long term
  • posts can be searched or filtered by keywords
  • easy integration with Google Plus share button
  • ability to give a priority to feeds (as in Google Plus’s circles)
  • a simple interface to monitor all feeds

Unlike, following Twitter accounts on Google Reader (or even any other RSS aggregator) makes you lose the real time feature of Twitter.

This said, how to include your Twitter follow list within Google Reader syndication?

  • For each of the accounts you follow on Twitter, get the userId.
  • The easiest is to select a tweet > right click > source code > search the attribute “data-user-id”, get the associated number, eg: 813286 for @BarackObama, 50055701 for @MittRomney and 248309482 for my prefered one: @John_the_Cowboy ;-).
  • Alternatively, you can request the following service: http://www.idfromuser.com
  • In Google Reader, add a feed: https://twitter.com/statuses/user_timeline/XYZ.rss. Replace “XYZ” with the actual number retrieved before

Of course, this is not easy at all, as said in the disclaimer above. It is long, takes much time, and can become fastidious if you follow tens of people. Anyway, Google Reader users are geeks rather than newbies. You may create a Groovy script of setup a Mule instance to automatize de process ;-).

I suggest you to create one or many folders to gather the Twitter feeds.

PostHeaderIcon Move AVD default location on Windows

Two days ago, I twitted this:

Windows I hate you “PANIC: Could not open AVD config file”

Indeed, I tried to run an AVD (Android Virtual Device) from IntelliJ IDEA, in order to test my Android application. So far, I always ran AVD from KUbuntu, but a specific need I had to run on Windows Seven. The emulator could not start, because it was searching the actual AVD img file in the default folder, eg C:\Documents and Settings\<yourLogin>\.android\avd on Windows XP. Unfortunately, the folder could not be retrieved (a story of French special characters, such as ‘é’, ‘è’, ‘ç’, etc.).
Therefore, the question is: on Windows, how to change AVD default location?

I tried many more or less tricky solutions, but the simplest is the following:

  • close IDEA and AVD Manager
  • create an environment variable ANDROID_SDK_HOME (keys Windows + Pause), pointing to your target folder, eg: D:\workarea\honeycomb-sdk
  • create a .android subfolder, eg: D:\workarea\honeycomb-sdk\.android
    • if Windows does not allow you to create a folder of which name starts with a dot, then create it through Cygwin’s mkdir.
  • startup IDEA

PostHeaderIcon Training: Test Driven Development and Unit Testing Cooking Book

Last Tuesday I led a training session about Test Driven Development (TDD) in general, and Unit Tests in particular. I presented a series of best practices related to unit tests, as a set of “receipts”.
The target audience is developpers, either Java coders or other ones. The exercises have no interest from a Java perspective, but are intented at teaching the main concepts and tricks of unit testing.

The exercices are the following:

  • basics
  • methods within methods
  • layers and mocks
  • private methods
  • exceptions
  • loggers
  • new Date()

Here is the presentation:

The original OpenOffice file is hosted by GoogleDocs: Test Driven Development and Unit Testing Cooking Book

The source code of exercises and corrections are available at this link.

PostHeaderIcon How to call external shell in Groovy?

Going on learning Groovy, I faced the following case: how to call an external shell (or MS-DOS) command from a Groovy script?

It is very easy. The following example show how to display the Subversion status of the current folder:
[java]def proc = &quot;svn st&quot;
def sb = new StringBuffer()
proc.consumeProcessErrorStream(sb)

println proc.text + &quot;\n&quot; + sb.toString()
[/java]