Skip navigation

 

Expressing dependencies between services using the <depends> tag is a very handy feature of JBoss. However, there are cases where services do not conform to the JBoss lifecycle model, or even if they do, the completion of their lifecycle methods does not express the dependency we want.

 

The typical use-case is delaying the starting of a custom service that hits a servlet, until *after* the Tomcat connectors are active, which in turn happens only after the server has completely started. This is possible using JMX notifications (i.e. subscribe to the jboss.system:type=Server, org.jboss.system.server.started notification).

 

A generalization of this technique has been added to JBoss v4.0.2 with the introduction of the BarrierController service. The service makes it easy to declaratively register and use *any* combination of notifications in the system as triggering events for the starting and stopping of a secondary Barrier MBean.

 

Then you can use the familiar <depends> tag to make your custom service depend on the Barrier, without having to worry about complex dependency issues.

 

A detailed description of the service can be found in our wiki.

 

dimitris@jboss

dimitris

Text Rulez!

Posted by dimitris Apr 24, 2005

 

Writing GUIs was never my forte and AFAIR the only "graphical" thing I've ever made (that I was actually proud of) was the user interface for a "pronounceable password generator". That was back in the college (1992?) where the assignment had been to create a password management system that would reduce the probability of having the users picking up bad password. Most students formed teams and build complex systems with Windows GUIs and dictionaries and rules to check password strength, and databases to record the passwords in use, so that you wouldn't choose it twice and stuff like that.

 

Being lazy to write any sort of persistence logic or complex GUI, I followed a different path. I worked on a algorithm that would produce completely random 10 characters words that would be nevertheless pronounceable (in English), so that you could actually memorize them. That resulted in about a dozen billion combinations of letters which was quite ok, but the fun stuff was that the system didn't have to keep any record at all about your choice (that would make the whole system less secure anyway) and the GUI collapsed to a single page with a text window in the middle. By pressing <space> the password generator was activated and passwords started rolling in that window at high speed (like symbols would roll in a slot machine). Pressing <space> a second time would stop that and the last ten password would show on the screen. You would start the engine again, until you had found a password that made your fancy. <esc> stopped the program and cleared the screen :)

 

That was coded in C, with the only non-standard C library call the gotoxy(int x, int y) from the Borland library. My solution to the problem was stupid enough to have a good chance of being useful and I got the 2nd best grade with a fraction of the code the other teams wrote. Most importantly I completely avoided having to learn Windows GUI programming :)

 

Now why I'm saying all this? While looking into making available through the jmx-console the memory pool information provided by the MemoryPoolMXBeans introduced in JDK5, I came across this text diagram that explains what the various memory pool metrics mean, in particular init, used, committed and max. The simple text diagram was so much nicer than the text explanation that I thought I should give it a try; for old time's sake :)

 

You can see the result here.

 

Text Rulez! :)

 

dimitris@jboss

 

To begin with, I'm a big fun of logging. In fact, I rarely use a debugger and only as a last resort. I've always believed that code is best debugged in your "head", as long as you know what you are doing. (It could be also that I'm just a louzy IDE user :)

 

For a long time, I admired the JBoss org.jboss.logging.Logger "wrapper" for a couple of reasons: the API is small, simple, and it only includes 5 + 1 levels of logging: ERROR, WARN, INFO, DEBUG & TRACE. (there is the FATAL level, but I doubt if it is ever used, it should be removed, really.)

 

Whenever you want to log something, it is almost a no-brainer to pick up the right logging level:

  • ERROR - A definite problem
  • WARN - Likely a problem, but can live with it
  • INFO - Common notifications, lifecycle stuff
  • DEBUG - Low volume debug
  • TRACE - High volume debug
(Compare this to java.util.logging.Logger ALL, CONFIG, FINE, FINER, FINEST, INFO, OFF, SEVER, WARNING, levels, or the entering() exiting() methods. It's almost hilarious!)

 

Then, there were those isInfoEnabled(), isDebugEnabled(), isTraceEnabled() performance enhancers that you could call in order to avoid preparing expensive logging output, that is never used. And as a sensible developer, I'd always use isDebugEnabled() whenever I would log.debug(..) any non-trivial stuff.

 

And all was well, until Adrian deprecated isDebugEnabled() (and isInfoEnabled()), and suddently the build bursted with ugly warnings, and eclipse started showing up those tiny yellow signs next to the slide bar. The code was not clean anymore...

 

Well, I could understand deprecating isInfoEnabled() (which is almost *always* enabled), but why isDebugEnabled()? Why now? Why me? That was cruel; we grew up with this method, we couldn't possibly live without it :)

 

Then as I started correcting warnings as I would come across them, by either removing the isDebugEnabled() statement all together, for logging messages that seemed of low-volume and of interest to the user, or turning this to a isTraceEnabled()/log.trace() combo for very detailed developer or high traffic logging messages, it all became clear: isLogDebug() was really not needed!

 

That was quite a revelation which brought to my mind pictures of Adrian with a "helo" hovering over his head (I've seen Richard Stallman doing this stunt wearing an "ancient" 1-foot hard disk as a helo, preaching his is Saint Ignucious, or something). Yes, Adrian, was telling the truth, and noboby listened (except Scott, of course :)

 

So now I'm a believer, too, and on top of that, I came to realise (or acknowledge?) that there is an ever better way to think about the log levels: INFO goes *always* to the console, DEBUG *always* to server.log, and TRACE *conditionally* to server.log. (ERROR and WARN are obvious.)

 

The usage of isDebugEnabled() gave the wrong impression that those debug messages may not be logged, which is rarely true. server.log is a tool primarily for the *users* of the server, to be able to troubleshoot problems and ask for help using informative log traces, from the forums (or the jboss support team of course :). In this regard, it is important that we don't log.debug() excessive information that is of no interest to the user; In other word, server.log size should always be kept relatively small or under control.

 

Another factor that isDebugEnabled() has been abused is due to the fact that in many cases we (developers) have used DEBUG for high traffic logging, that should really be TRACE. The reason being, we (developers) are usually lazy to enable the TRACE level in log4j.xml while developing, and we prefer to just use debug() instead, that we know it will work by default!

 

"If the user doesn't like this, she can turn if off", while the idea should really be, "I need to enable TRACE while I do development, and save server.log from being filled up with garbage, and the user from getting lost inside my verbose traces".

 

Happy Logging :)

 

dimitris@jboss

dimitris

Platform MBeans in JDK5

Posted by dimitris Mar 29, 2005

 

JDK5 comes bundled with a JMX v1.2 implementation and a set of monitoring MBeans called platform MBeans or MXBeans (do not confuse those with JBoss XMBeans :) Those MXBeans can be accessed through the platform MBeanServer, which is more or less a normal MBeanServer but it is instantiated by the JVM itself, upon first access.

 

A nice example of underlying usage of a platform MBean can be seen in (soon-to-be-released) JBoss v3.2.8/4.0.2. By utilizing the ThreadMXBean we can output to the jmx-console a full stack trace of all running threads in JBoss, without having to revert to the command line (as it was done previously). Of course, this only works when running under a JDK5+ runtime.

 

Check out our wiki for more info.

 

dimitris@jboss

 

It comes without surprise that advanced developers routinely extend JBoss with their own MBean services to do all sorts of interesting stuff. Additionaly, it is often the case that the produced mbean code is of a generic nature, or the developer has come up with a not-so-common use-case for which mbeans are a good fit.

 

Unfortunately (and this is often the nature of OpenSource), we rarely hear back from them! Wouldn&apos;t be great if we could somehow share the knowledge, or even better, incorporate some of the best ideas back to the JBoss codebase?

 

Driven by a request from this fellow here, I created a simple entry point in the JBoss Wiki for anyone that wants to share his/her experience with MBeans, or even better, some working piece of generic MBean code.

 

You may also try the JBoss User -> Management, JMX/JBoss forum as a starting point for discussing your own unique mbean use-case.

 

See you at the forums!

 

dimitris@jboss

 

In case you don't already know, ListenerServiceMBeanSupport is a cool subclass that you can extend if you want to write MBean services that are jmx notification listeners, too.

 

It solves the problem of subscribing for notifications, by externalizing the subscription configuration in XML, no matter how complex it is. It has some nice features like you can use ObjectName patterns (e.g. subscribe to all mbeans in the jboss.system domain (jboss.system:*) and it supports dynamic subscriptions too, that is, the baseclass will monitor new mbean registration and it'll subscribe to them if they match the subscription specification you have provided, even AFTER your service is started . You just need to write the callback (handleNotification2()) to process the received notifications. (Have a look at an example here.)

 

Starting from JBoss v3.2.8RC1 & v.4.0.2RC1, this mechanism has been extended to support arbitrary filters, too, using a filter factory plugin mechanism. (Previously you were only able to specify a NotificationFilterSupport filter.)

 

To learn all about this, take a look at the SubscriptionList examples in the Wiki documentation.

 

If you have some rather peculiar JMX notification subscription scenario that you cannot implement using ListenerServiceMBeanSupport, I'd be very interested to hear about, so please do post a message at the Users, Management,JMX/JBoss forum.

 

Enjoy!

 

dimitris@jboss

 

Most of the presentation slides from JBossWorld can now be found online at JBoss World Recap. There is a lot of valuable information in many of those presentation, so I would highly recommend everyone to have a look at the presentations corresponding to their subjects of interest.

 

I did a presentation as well, focused around the 3.x/4.x JBoss MicroContainer, under the title "Never Write A main() Again!". The original intension was to show that in most cases in which a server application needs to be created, whether it is EJB based or not, it makes perfect sense to reuse the JBoss MicroContainer (for example, start off with the "minimal" configuration) and just add your own extension in the form of MBean Services, rather than starting from scratch.

 

The same is true for your normal J2EE application, where you just want to add functionality to the server that is difficult to write using the "standard" J2EE tools (for example, a lightweight adapter to an external system, without the burden of creating a JCA resource).

 

In any case, the benefit is a very high degree of reusability of components that are really well tested and difficult to write (e.g. the unified classloading mechanism of JBoss that makes hot-deployment possible).

 

I've been doing MBean services with JBoss for almost 4 years now and while the whole idea is very neat and simple, it is impressive how few people actually know about the existence of this technology and its many uses. Most developers only get to learn about this in one of the JBoss trainings.

 

We now see the proliferation of various container-like projects coming about as the new "cool" thing, while it is true that JBoss has been doing this kind of stuff since year 2001.

 

In any case, I tried to distill in just a few slides the really essential stuff that you need to know in order to write your own MBean. This is not rocket science at all, and I usually need 15-20 minutes to get someone up to speed with writing her own MBeans and start extending JBoss in arbitrary ways. In fact, it is often the case that people, after they write their first MBean and see how easy it is, they want to go about and MBean-ize everything :)

 

Anyway, I hope you find the presentations useful.

dimitris

Welcome (Back)

Posted by dimitris Mar 6, 2005

 

After being with JBoss for almost a year now, and in the aftermath of JBossWorld (which was awesome, btw) I thought I should make my first blogging attempt. I hope I won't get to increase the entropy of the universe with useless rants and I'm certainly against those know-it-all bloggers that seem to have an opinion about everything and everyone. So I'll try to stick to where I suspect I may have something useful to say. In any case, if this is all seems Greek to you, this will be certainly my own fault :)

 

JBossWorld was great for many reasons, I got to meet once more the usual suspects, old and new JBoss developers, and a great deal of new people and others that  I only "virtually" knew through the forums. This is particularly important if you are a "remote" employee, who lives and breaths through an ADSL connection, so every opportunity for real interactions is simply invaluable.

 

We also had our "internal" JBoss Developer's conference before and after the main event, where we got to discuss the various JBoss projects, subsystems, roadmaps, new developments, etc. On the flight back home my head was still spinning from the design sessions, and the tons of ideas that naturally pop up in such a great environment (late night alcohol sessions might have something to do with that, too.) In any case, there was so much brain power in that conference room, amazing and exhausting at the same time. I just feel like going back and relaxing for a couple of days. We have lots of work to do :)

Filter Blog

By date: