el-ri
Occasionally I need the EL reference implementation in my projects. JARS are hard to find. They seem to be provided by JBoss MAven2 repositories only. The repository URL is http://repository.jboss.org/maven2 .
javax.el
el-api
1.2
provided
javax.el
el-ri
1.2
provided
VisualVM 1.0 RC
One of the sessions of TheServerSide Java Symposium in Prague was about JMX support in Java. During the talk Jean Francoise Denise briefly demoed a new tool VisualVM based on the Netbeans Platform. Today I did some experiments and found it quite useful. It is also utilizing the NetBeans plugin mechanisms to provide extensibility (e.g in order to monitor JMX Beans you must install the MBeans plugin).
.
The tool even provides a profiler. I haven’t even looked at it closer. Though I believe it is quite useful to have it available for ad doc profiling without requiring any external tools!
Hibernate entity-name
In a complex application a persistent entity is typically used by multiple use cases. These use cases put different requirements on mapping such a persistent entity. For example, in a simple case only basic attributes must be mapped whereas in a more complex situation for the same entity a larger set of attributes (+ relationships) must be mapped.
When mapping a persistent entity, tradeoffs must be made regarding performance and the required code to implement the solution.
For the above scenario a developer would probably just map all of the persistent attributes (regardless whether they are required in all of the use casesor not) and eventually map relationships with some lazy loading enabled.
Dealing with it this way mostly works even in larger projects but can totally fail in others (especially when mappings are created by more than one developer and no design rules are in place).
Hibernate provides a mechanism to deal with this kind of troubles very well. One can actually provide multiple mappings for a single persistent class through the mapping attribute ‘entity-name’.
For example I had a situation where an entity had a primary key but also an alternate key which was used heavily in other entities for referencing this one.
So I just created 2 different mappings for this one class, mapping different attributes as id.
When referring to a specific mapping the ‘entity-name’ attribute is used
When using the Hibernate API, look out for overloaded methods that allow passing in a entity-name!
Sun compiler silently accepts annotation syntax error
Today I experienced another strange thig with the eclipse compiler. I coded some annotations that contain some syntax error which I wasn’t aware of since the IDE didn’t highlight it. The @@ManagedOperationParameters( { @ManagedOperationParameter(name = "category", description = "Logger category"), }) annotation is not correct, trying to compile it with the Sun compiler fails (can you spot it?).
@ManagedOperation(description = "Get the logging level for a category")
@ManagedOperationParameters( { @ManagedOperationParameter(name = "category", description = "Logger category"), })
public String getLoggerLevel(String category) {
return LogManager.getLogger(category).getLevel().toString();
}
After reporting this a a eclipse JDT bug I was pointed at that this is allowed syntax (see JLS) but the sun compiler does not properly implement syntax checking! So I should rather see to report this against the Sun compiler. Still it is strange that this syntax is allowed at all!!!
Hibernate isPersistent Element
Rarely you need to be able to detect whether some class or property is managed by Hibernate (i.e. it is mapped) or not. In this case SessionFactory.getClassMetdata helps with this problem.
It returns mapping information or throws an exception if it is not mapped!
Change log4j logging level at runtime using JMX/Spring
Monitoring application servers is a daunting task. Without the right instrumentation of your code it is even impossible. I try to use log4j as much as possible and in general I’m very generous regarding logging levels. But occasionally the console just gets flooded with logging output. Typically then I would modify the logging configuration files and restart the server which may be very time consuming and unnecessary.
In the past I had used JMX to switch logging levels at runtime for various projects. The first time now I have tried this with the Spring framework and it worked like a charm (did you expect anything else). I’m making the solution public in case I need this for future projects and to document the steps required!
First, a bean is required that uses the logging API (here log4j) to manage the logging level.
/*
* Copyright 2002-2008 Martin Ahrer.
*
* $Id$
*/
package at.martinahrer.blueprint.log4j;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;
/**
* @author Martin Ahrer
*
*/
@ManagedResource(objectName = "at.martinahrer.blueprint.log4j:name=Logging", description = "Logging", log = true, logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200, persistLocation = "logging", persistName = "logging")
public class Logging {
@ManagedOperation(description = "Set the logging level for a category")
@ManagedOperationParameters( { @ManagedOperationParameter(name = "category", description = "Logger category"),
@ManagedOperationParameter(name = "level", description = "Logging level") })
public void setLoggerLevel(String category, String level) {
LogManager.getLogger(category).setLevel(Level.toLevel(level));
}
@ManagedOperation(description = "Get the logging level for a category")
@ManagedOperationParameters( { @ManagedOperationParameter(name = "category", description = "Logger category") })
public String getLoggerLevel(String category) {
return LogManager.getLogger(category).getLevel().toString();
}
}
It’s been annotated with Spring JMX annotations to provide JMX meta data. Next, we need to export the bean as a JMX Bean. This is supported very well by the Springframework’s MBeanExporter.
Finally to connect to the MBeanServer using jconsole the JVM (running the MBean) must be started with the system property -Dcom.sun.management.jmxremote set.
JSF Days 08 will be held in Vienna from 12.3.08-14.3.08
JSFDays will take place on March 12th to 14th in the premises of FH Technikum Wien. The conference is hosted by IRIAN Solutions Gmbh.
Among the speakers are Edward J. Burns, Kito Mann, Alexander Jesse.
Swinglabs PDF Renderer
Today I had a chance to test the Sun PDF Renderer (see a previous post). After a first glance I have to say it is damned fast! The Viewer itself loads extremely fast (of course it doesn’t have to load all the plugins like the Adobe Reader) and also loading a document is like nothing!
IBM and SAP Open Source their JVM Diagnostics Tools
A few weeks ago already I came across a InfoQ article which discusses plenty of tools for hunting down memory problems.
SwingLabs PDF Renderer
In 2003, developers at Sun Labs developed a PDF Renderer which in december has been released under the LGPL as part of SwingLabs. So now it should be much easier to integrate PDF solutions into rich client apps.
