JicarillaWiki   IocContainerInternals UserPreferences
 
HelpContents Search Diffs Info Edit Subscribe XML Print View

This wiki is in 'slumber' mode, just like its associated sourceforge project. Edits are disabled, the content is potentially stale and is not maintained. That said, it contains some really useful stuff still. Enjoy!


WORK IN PROGRESS

This paper is a work in progress. Please go away now and check back later (it will be announced on my weblog when its supposed to be readable, and probably again if it ever really gets finished).

Introduction to (IoC) Container Internals

(This work is licensed under a [WWW]Creative Commons License.)

Introduction to this introduction

There are a lot of containers in the java world. I found many developers consider container development to be something of an arcane art left to a handful of systems-level programmers who do the complex stuff so the rest of the world can focus on things like business needs.

That's bad. Just like every programmer should know or be able to figure out how to create a rough equivalent of a !HashMap or !ArrayList, every programmer should also be able how to create the rough equivalent of a container. IMNSHO (In My Not So Humble Opinion). This paper takes you on a pragmatic tour, full of samples, through the internals of your average container.

About the author

LeoSimons is a young programmer who switched from being a fulltime developer to being a parttime physics student. He's been active with the [WWW]Avalon project for years, has followed the [WWW]PicoContainer project from its inception, has developed several container solutions of his own, and has studied the internals of half a dozen other projects.

He regularly writes on different kinds of computer-related topics on his [WWW]weblog and publishes essays and articles of wildly varying quality on [FrontPage this wiki].

Target audience

This document assumes you are a java programmer with some experience, and that you know what [WWW]Inversion of Control is (roughly, at least). I'm also assuming you're actually interested in how things like [WWW]Tomcat work on the inside. If you are not a java programmer, but very smart anyway, this essay may still make some sense to you, or it may not. Let me know.

Container defined

A "container" is that part of your software which hosts other parts of your software. The virtual machine (JVM) that runs every java program is a kind of container. A servlet engine is a container. An EJB container is (well, duh!), a container. A HashMap can be used as a container; the same goes for a directory service like JNDI.

Most containers contain specific things. The Swing !JContainer class contains !JComponents. A servlet container contains servlets. A virtual machine contains java programs.

Most containers do some specific things to the specific things they contain. A Swing JContainer instance handles (together with other pieces of the Swing framework) positioning a JComponent on the screen. A servlet engine instantiates, configures and otherwise manages the contained servlets and web applications. It also feeds them requests and provides the means for making the servlets send responses to those requests.

These specific things the containers do are what adds value above the use of something as simple as an ArrayList. While the ArrayList is very generic and broadly usable, it doesn't do a lot. We want to offload some of our core software needs to the container.

The thing we want to offload most often is the "boring" stuff, the "plumbing". You use an EJB container because you want to focus on architecting the solution to some business problem, and not on "plumbing" like persistence, clustering, or remoting.

IoC Container defined

An IoC container is a container which supports a software architecture that follows the principle of [WWW]Inversion of Control. Well-known IoC containers are listed on the RelatedProjects page. One of the most famous IoC containers is not usually mentioned as an IoC container at all -- the servlet engine.

IoC containers come in nearly all shapes and sizes. The smallest IoC container in popular use fits into a 30kb jar archive and can be embedded at many different points in your application, while some of the bigger ones can be many megabytes in size. But they share a few common traits, and that's what the rest of this essay is about.

Before we get our hands dirty...

We're going to start with a really simple idea of an IoC container, and then introduce more and more complex architectures. In order to keep this essay somewhat readable, none of these examples will be actual, full-fledged, runnable containers. I will try to provide links to related "real-life" projects though.

The obligatory sample...

"Hello world" is quite dull. And "hello world" samples don't have any resemblance whatsoever to "real world" use of IoC containers. So we're going to be hijacking my favorite tv series, [WWW]The Simpsons, for inspiration, components, and comic (hopefully) relief.

The Simpons also features as the primary characters in the [WWW]IoC Technology Compatibility Kit I'm developing. If you want full samples that you can compile and run in real-life containers, take a look at there.

Contents


PythonPowered
EditText of this page (last modified 2007-02-18 14:14:22)
FindPage by browsing, title search , text search or an index
Or try one of these actions: AttachFile, LikePages, LocalSiteMap, SpellCheck

Creative Commons License
The contents of this wiki are licensed under a Creative Commons License.