HotSpot Arithmetic

Recently I was tracking down a spurious issue in the RabbitMQ Java client library that was returning null values from a call where it just didn't seem possible that it could return null. This is a brief article about a very curious issue in the Java Hotspot compiler. If you are just interested in the HotSpot issue, then just skip the section about it was discovered in the client library.

Click to read more ...

Posted on Monday, August 31, 2009 at 12:49AM by Registered Commenter0x6e6562 in | Comments2 Comments

Scalarizing Velocity

It is quite well documented that Scala is a boon to those who need to extend or integrate Java based applications and libraries. Recently, I found myself implementing some some new back end functionality for a website that uses Velocity to render its frontend. Whilst doing this, a few gotchas arose:

  • Scala collections do not work out of the box with a Velocity foreach loop;
  • Velocity expects the attributes of an object instance to be exposed via the JavaBean getter/setter convention;

However, a small amount of googling some simple solutions for these problems.

Automatically Convert Scala Collections To Java

Whilst the reverse operation is well documented, there does not appear to be an inbuilt mechanism to convert Scala collections to Java. The solution to this has been provided by Jorge Ortiz's scala-javautils library on Github.

This uses an implicit conversion that allows you to invoke a function called asJava on any Scala collection to get it converted to a Java collection. Just refer to the README on the Github project page to see how easy this is. After applying this to my Scala collections, the Velocity templates are now able to iterate through them.

Expose Attributes As JavaBean accessors

One of the nice things about Scala is the paradigm shift away from unnecessary JavaBean accessors. However, Velocity, unless I'm unaware of of some magical configuration parameter, follows the JavaBean mantra, which can be a hassle when you just want your template to read the properties of a class instance.

Thankfully there is an on-board feature that can auto-generate getters and setters for your attributes. By annotating a field with the @BeanProperty annotation, the Scala compiler will automatically generate these methods for you, thus saving you from unnecessary boilerplate in your Scala code. An example looks like this:

package foo

import reflect.BeanProperty

class Bar {
  @BeanProperty var id:Long = -1
}

This allows you to use plain jane JavaBean accessors in your Velocity templates.

If Scala Can Drive Velocity

A third option may be of interest to you, if you are invoking the template application from within Scala code. Martin Kneissl wrote this Scala wrapper for Velocity, which addresses the Java collection issue in Scala.

YMMV.

Posted on Sunday, June 7, 2009 at 10:28PM by Registered Commenter0x6e6562 in | Comments1 Comment

Work Distribution in RabbitMQ

The next major release RabbitMQ contains a feature called QoS, which means egress flow control in AMQP parlance. This article describes a practical application of this feature using a competing consumer work distribution pattern. The example code uses the RabbitMQ Java client, but this feature is not Java-specific and the same principles apply to any language client.

Click to read more ...

Posted on Monday, January 26, 2009 at 10:37PM by Registered Commenter0x6e6562 in , | Comments1 Comment

Capabilities For Messaging

This article introduces the potential usage of capabilities as an access control mechanism in messaging middleware. It describes the motivation behind a proof-of-concept implementation that demonstrates the feasibility of a capability based approach to securing access in the RabbitMQ message broker. Whilst it was decided not to further develop this paradigm in Rabbit, the experiences gained from it may be valuable for anybody contemplating using capabilities to implement access control. Though not strictly necessary, a basic understanding of the AMQP execution model can be advantageous to appreciate the implications of this article.

Click to read more ...

Posted on Thursday, January 22, 2009 at 07:49AM by Registered Commenter0x6e6562 in | Comments3 Comments | References1 Reference

How I Install RabbitMQ On OSX

A little while ago, Rany Keddo wrote an article about how to get RabbitMQ up and running on OSX. If you are looking for a super easy way to install RabbitMQ, please read that article rather than this one. This article is just a description of how a RabbitMQ developer runs RabbitMQ on OSX.

Click to read more ...

Posted on Saturday, November 15, 2008 at 10:07PM by Registered Commenter0x6e6562 in , , | Comments1 Comment
Page | 1 | 2 | 3 | 4 | 5 | Next 5 Entries