Archive for the ‘Jan's Blog’ Category

Spring 3 training course

Monday, November 30th, 2009

It is my pleasure to announce that we now have Practical Spring 3 training course. It is a four-day course aimed at beginner Spring developers.

So, if you’re experienced Java developer and want to learn about the Spring Framework, book the course and, in four days’ time, you will be able to create three-tiered Spring 3 web application.

The course outline is

Anatomy of Spring application

Why Spring and how does Spring fit into your application.

What does Spring do?

Dependency injection and AOP; we explain the dependency injection concepts, bean lifecycle, we sprinkle it with the Spring annotations, including SPEL! We then press on with aspect-oriented programming, showing AOP support in the Spring Framework.

The workers

Understand how Spring fits into the data access and middle tiers. We go from JDBC to Hibernate and sprinkle it with a bit of Spring transaction management.

The web

Overview of modern web applications; understanding how Spring’s MVC support makes web programming really easy and efficient. We wrap up with REST support!

The goodies

If there is still some time left at the end of the course, we can include large-scale data processing (using JDBC batching and job monitoring); after which, we show that Spring Batch 2.0 offers the solution out of the box!

Custom arguments for @RequestMapping methods

Friday, October 23rd, 2009

So, Spring MVC fans, let’s say you have a @RequestMapping-annotated method in your controller, but you would like to include a custom argument, in addition to the standard ones like Model, HttpServletRequest, and HttpServletResponse.
The solution is to implement a WebArgumentResolver. As an example, we’ll create a CurrentDateWebArgumentResolver; as its name suggests, this resolver will be able to set any Date argument in the controller method to current date.
We have to write

public class ContextExtractingWebArgumentResolver
    implements WebArgumentResolver {

    @Override
    public Object resolveArgument(MethodParameter methodParameter,
        NativeWebRequest webRequest) throws Exception {
        if (Date.class == methodParameter.getParameterType()) {
            return new Date();
        }
        return UNRESOLVED;
    }
}

We then wire-in the argument resolver in our Spring application context configuration file:

<bean class="org.springframework.web.servlet.mvc.annotation.
      AnnotationMethodHandlerAdapter"
    <property name="customArgumentResolver">
        <bean class="package.ContextExtractingWebArgumentResolver"/>
    </property>
</bean>

Once done, we can create a @RequestMapping-annotated method in our controller and include the Date argument; that argument will now receive the current date. For example, we can have

@Controller
public class HomeController {
    @RequestMapping(value="/index", method=RequestMethod.GET)
    public void index(Date date, Model m) {
        m.addAttribute("now", date);
    }
}

The model that will be passed to the view after making a GET request to the /index URL will include attribute named now; the value of the attribute will be the current time.
Naturally, this is just a simple example and injecting current date is not very enterprisey thing to do, but using the approach I have outlined, you can now set much more useful argument types. Do not forget that the implementation of the WebArgumentResolver is a Spring bean, thus having access to all features available in the Spring application context.

Spring MVC Volume II

Wednesday, October 21st, 2009

It was my pleasure to deliver my Spring MVC talk at the Java User Group meeting in London yesterday. I loved the audience–they asked the right questions at the right time; at times they were paying too much attention and spotted a bug! Mea maxima culpa, all is corrected now.

The slides and the source code are available at http://github.com/janm399/smvc/tree/master.

I’d love to hear suggestions for the next talk–I am thinking about advanced Spring MVC, where we take a look under the hood of the AnnotationMethodHandlerAdapter and its friends. Alternatively, we could leave the cushy OO world behind and dive into AOP, with focus on [Spring|Dynamic] AOP.

Please comment or tweet to @honzam399.

Spring MVC volume II

Thursday, September 24th, 2009

I will be presenting my Spring MVC talk at the next Java User Group meet up on 20th October, this time at UCL. It won’t be just a repeat of the old talk, there will be some very interesting changes.

Oh, and one more thing!

frau and laser

Go to http://www.meetup.com/Londonjavacommunity/calendar/11439650 for the event details and registration form.

Today’s web applications

Tuesday, September 22nd, 2009

I gave a talk on today’s Java EE and related web applications at yesterday’s London Digital Week event at Skills Matter. I had a full room of geeks keen to find out what I think about web application development. I hope that all attendees learned at least one new thing and that they’ll all find the time to try out Spring, Ruby on Rails or Grails.
To get started, you can download the source code of the talk from http://github.com/janm399/ldw/tree/master; the PDF version of the talk is available at http://github.com/janm399/ldw/raw/master/talk/ldw-pdf.pdf.

I’m looking forward to seeing most of you again at the next Java User Group or Spring User Group event!

Spring MVC at London JUG

Friday, September 4th, 2009

I had the privilege of giving a talk on Spring MVC at yesterday’s London JUG meeting. I had a full room of Java programmers keen to find out about how to write Spring MVC web applications. I hope that all attendees went away with good understanding of just how easy it is to write the Ms, Vs and Cs in Spring MVC.
You can download the source code of the talk from http://github.com/janm399/smvc/tree/master; the PDF version of the talk is available here.

I’d be happy to give a repeat of the talk at another JUG meeting or, if you prefer, give another talk on Spring-related topic. Spring AOP seemed to be quite popular!

That’s what I call performance

Thursday, August 27th, 2009

We are completing work on caching and routing tier we added to a lived-in system. The performance increase is very substantial and I will write a lot more about how we achieved this next week.
For now, I’ll wet your appetite with a screenshot that says it all

Service node statistics

Service node statistics


P.S. Yes, we’re talking about the RDTSC and System.nanoTime()!

Jeabu is coming

Monday, August 24th, 2009

Our new open-source project, Jeabu, is on its way. If you are very adventurous and interested in the earliest code, pull it from http://github.com/janm399/jeabu/tree/master.

COBOL is fifty

Friday, August 14th, 2009

Not today, of course, COBOL celebrated its fiftieth birthday in April. It is the hidden language, no one will openly admit that they have COBOL systems, yet there are millions of lines of COBOL code that no one dares to throw away. The number one reason is “if it ain’t broke, don’t fix it”, closely followed by the fact that software rewrites usually end in tears. Joel Spolsky gives excellent evidence on his blog.

Why is COBOL still out there?

So, how come COBOL has survived for so long? It is an old, cumbersome language; yet, it has modern compilers and runtime environments. You can compile your COBOL program on 32bit Windows, on 32 and 64bit Linux, HP-UX, Solaris, AIX, and many others.
Seven years ago, I worked in Ortex and they (not me, I was the cool new dude) were churning out thousands of lines of COBOL code every day.
I helped replace the aging Windows 3.1-style user interface with something that looked a bit more modern, but underneath the pretty UI, we were still talking to green-screen UNIX COBOL monster. And there lies the key to COBOL’s continued success.

What did COBOL give us?

It did not use complex binary protocols, it relied on the XML of the seventies — fixed width text messages. This simple data exchange format lends itself to easy integration with other systems. As long as your system can read and write fixed-width text, you can talk to COBOL-based systems — OK, I know I’m leaving out details, but bare with me.
Fast forward to 2006 and watch the WS-* approach. Why, did the WS-* people ask, are our systems talking to each other in closed binary formats; why can’t we use an easy to read and write format? Why aren’t we using XML? It turns out that WS-* approach is still cumbersome. For example, you cannot determine what a WS-* call will do just by looking at the endpoint, you need to examine the payload. Hmmf!
Enter REST. Again, we are sending structured plain text, but this time around, we’re making the most of the HTTP protocol. We use the HTTP methods properly and we give meanings to the URIs.

nmnon

Wednesday, August 12th, 2009

If you are in charge of a garden-variety Linux system, you’ll probably like nmon. It is a performance monitoring tool that combines statistics for the core kernel objects. You can see process list (similar to top), memory, network, block I/O and many other statistics, all in nice ncurses-based environment.

nmon screenshot

nmon screenshot


Interested? Get downloadin’!