Thursday, October 25, 2012

Tuesday, October 23, 2012

The sensible man

Jon Pither is the sensible man. He writes a practical argument for Clojure over Java. Which is more industrial, Scala or Clojure? Yes.

Thursday, October 18, 2012

Unsafe magic heap

A brilliant post from Martin Thompson, Compact Off-Heap Structures/Tuples In Java, using sun.misc.Unsafe to avoid VM-managed heap and bypass JVM memory limits. Not of the feint of heart.

UPDATE: A lot of interesting things in Thompson's comments.

Monday, October 15, 2012

JSR-255 (JMX2) and Guice

On a new project with Guice, then, how do I magically wire my managed objects to JMX? Sadly JSR-255, aka JMX2, did not make JDK6 or JDK7 (there's always JDK8). I live in the here and now, and relied before on Spring JMX annotations and MBeanExporter.

There's no full implementation of JMX2, but covering a good minimal feature set is pojo-mbean. How to get Guice to register @MBean-annotated objects? Use injectors:

class SomeModule extends AbstractModule {
    @Override
    protected void configure() {
        bindListener(Matchers.any(), new JMXTypeListener());
    }
}

class JMXTypeListener implements TypeListener {
    @Override
    public <I> void hear(TypeLiteral<I> type,
            TypeEncounter<I> encounter) {
        Class<? super I> rawType = type.getRawType();
        // From pojo-mbean; eventually JSR-255
        if (rawType.isAnnotationPresent(MBean.class))
            encounter.register(new InjectionListener<I>() {
                @Override
                public void afterInjection(final I injectee) {
                    try {
                        // From pojo-mbean; eventually JSR-255
                        new MBeanRegistration(injectee,
                                objectName(rawType)).
                            register();
                    } catch (Exception e) {
                        encounter.addError(e);
                    }
                }
            });
    }

    private static <I> ObjectName objectName(Class<? super I> type)
            throws MalformedObjectNameException {
        return new ObjectName(type.getPackage().getName(), "type",
                type.getSimpleName());
    }
}

HTML5 Tips

I rarely have use for these things, but this one is highly practical: 8 Superlative Practices for Efficient HTML5 coding.