My 10 favorite links on Software architecture, scalability and design

1. The Internal Design of Force.com’s Multi-Tenant Architecture (Video)

2. Dan Pritchett on Architecture at eBay (Video)

3. Orbitz.com Architecture with Brian Zimmer (Video)

4. Scalability Principles

5. An Unorthodox Approach to Database Design : The Coming of the Shard

6. Domain Driven Design and Development In Practice

7. The Challenges of Latency

8. LinkedIn – A Professional Network built with Java Technologies and Agile Practices

9. LinkedIn Communication Architecture

10. JAX TV: Java-Programmierung im Multicore-Zeitalter (Java Programming in the age of multicore processors) by Angelika Langer

Veröffentlicht in Allgemein, Software-Development | Kommentieren

Freemarker Templates: Layout / Decorators with Shared Variables in Data Model

This tutorial is about the Freemarker template engine and it explains how to build a custom Layout / decorator mechanism similar to Tiles.
I have build my own Layout mechanism similar to Tiles, because it seemed the easiest to me so far and I didn’t want to include the Tiles lib in my app to keep things simple.

Here is what I want to do:

I have 2 templates.

1. A template layout.ftl which defines the basic layout (the decorator)

1
${screen_content}

Note the ${customPageTitle} page variable which is what I am talking about here. I will come to that later.

2.A second template content.ftl which defines my content.

This is my custom content, which should be displayed in the the screen_content variable of the layout.ftl template.

This template should be able to set the customPageTitle in the layout.ftl by doing a

${assign("customPageTitle", "This is custom test title rendered inside the layout template")}

The point in this post is the expression ${assign("customPageTitle", "This is custom test title rendered inside the layout template")} .

Usually in Freemarker you would have written:

<#assign customPageTitle="This is custom test title rendered inside the layout template">

But the problem is that this will not write that new *customPageTitle* variable to the underlying dataModel so that it can be used in the layout.ftl.

But it is possible. Continue with the serverside servlet code which renders the templates.

3. Render both templates in the servlet / java code
In my Servlet I am basically doing rendering of the 2 templates.
First I render the content.ftl and then the layout.ftl. The rendered output of the content.ftl is put into the data model so that it can be outputed by the layout.ftl

1
2
3
4
5
6
7
8
9
10
11
12
 
// 1. parse the content
Map dataModel = RequestContext.getInstance().getContext();
dataModel.put("assign", new DataModelModifier(dataModel)); // this is my own custom assign function.
 
String customContent = TemplateRenderer.getInstance().render("content.ftl", dataModel);
 
// 2. pass it in the model of the layout
dataModel.put("screen_content", customContent);
 
// 3. Render the complete layout
resp.getWriter().println(TemplateRenderer.getInstance().render("layouts/layout.ftl", dataModel));

Note: TemplateRenderer, RequestContext are *not* Freemarker classes. They are own helpers in my application.

You ask at this point what is actually the class DataModelModifier and why can the content.ftl do a ${assign("customtitle", "This is custom test title set inside a different template")} ?

The DataModelModifier which makes a method available in Freemarker. They are used like normal variables. see Method in the Freemarker Doc.

This class basically gets are reference to our data model which we want to modify and in the exec(List arguments) method we are just adding a value to our dataModel hashMap.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
protected static class DataModelModifier implements TemplateMethodModel{
 
private final Map dataModel;
 
public DataModelModifier(Map model) {
this.dataModel = model;
}
 
public Object exec(List arg0) throws TemplateModelException {
 
if (arg0.size() != 2) {
throw new TemplateModelException("Wrong arguments. key, value required");
}
 
this.dataModel.put((String) arg0.get(0), arg0.get(1));
return "";
}
 
}

Finally...

What I wanted to achieve is that the content.ftl template can assign a value to the variable "customPageTitle" which is rendered in the layout.ftl template which is a different template.
By default FTL does NEVER modify the dataModel according to the Freemarker Documentation under: http://freemarker.sourceforge.net/docs/pgui_misc_multithreading.html

From Freemarker doc:
It is impossible to modify the data-model object or a shared variable with FTL, unless you put methods (or other objects) into the data-model that do that. We discourage you from writing methods that modify the data-model object or the shared variables. Try to use variables that are stored in the environment object instead (this object is created for a single Template.process call to store the runtime state of processing), so you don't modify data that are possibly used by multiple threads. For more information read: Variables

But exactly this is what I am trying to do, and at the moment it sounds totally reasonable to me. I just don't know what the pitfalls are. I know that there are some risks too:
It can be kind of dangerous and error prone practise to let FTL modify the dataModel because it can lead to accidently overwriting of values which lead to strange errors.
But on the other hand it gives you great flexibility to build web applications. I will see when I will run into first problems with this approach.

Conclusion
Here is what we need in order to build our own custom template layout / decorator:

1. 2 templates. one for the layout and one for the actual content.
2. We need to render the content template first and make the output available in the layout template.
3. we need a custom class which allows the dataModel to be modified inside the templates via FTL.
4. we need to make this class available in the dataModel as a Freemarker Method. That means this class needs to implement the TemplateMethodModel interface
5. The content template uses this custom method (based on that class): ${assign("key","value")}

I hope that this tutorial helps somebody out there too.

Veröffentlicht in Software-Development | Kommentieren

Getting Hibernate to work with plain OSGI (using Equinox and Jetty in it)

Collection of links on my way to get Hibernate to work in my first OSGI application based on Equinox.

Hibernate and OSGi: An elaborate solution

OSGI Bundle Repository

SpringSource Bundle Repository

Veröffentlicht in Allgemein, Software-Development | Kommentieren

Getting started with Maven2

This article is just a central place where I want to collect all the steps and links which I found useful while learning Maven2 and migrate and existing project from Ant to Maven2.
The reason I have picked Maven2 is that the new application I am developing uses Spring and OSGI and the Spring guys are also using Maven. As I am still learning I want to avoid opening to many fronts and possibilities for errors.

Nice tutorial for Spring / OSGI and Maven2
Maven Getting started guided
How can Maven benefit my development process
The pain of switching from Ant to Maven (very good post, funny too read, thoughts of developer migrating :) I am sure I will suffer the same)
Maven2 Eclipse Plugin
Better builds with Maven (Free E-Book)

Screencast about PAX-Running + Spring OSGI

Veröffentlicht in Allgemein, Software-Development | Kommentieren

Version 1.0 is not version 2.0

I am working since a couple of years in client-facing software projects in the e-commerce area.
Most of them were german clients of varying sizes which outsourced development of their e-commerce projects.
One thing I realized was that many those projects had issues after going live.
that is nothing new, but those issues were in my opinion mainly because of one fact:

The client wanted to do too much at a time.

I am under the impression that in many german projects i have worked, the clients never go live with version 0.9 which has less features and is not perfect.
instead they want to to have version 1.0 but actually expect it to be version 2.0….of course in time and in budget!

Experience told me that this doesn’t work. Instead you should try to start small with the most simple setup possible to achieve the business goal.
That is my personal opinion of course.

I have tried to come up with a set of questions which should help Software projects to go live successfully:

Q: What is the most important functionality which is needed for launch?
A: E.g. for an online store it is products, the possibility for customers to have a shopping cart and a successful and short checkout and payment process.
that’s it: nothing more! people should buy your stuff. Don’t stop them from doing that with all kinds of features!

Q: Which features are used the most?
A: if something you want to implement is most likely not used by at least 90% of the users….leave it out in version 1.0
After going live monitor your site and analyse which areas could improve with your new feature ideas.

Q: “But all of our competitors have those features…”
A: “Do you actually know if users need those features?” Try to stick out of the crowd and do less,
but do this better than your competitor.

Q: why don’t we just put more people on the project to get all of our crazy ideas done?
A: Do you actually know that you can get fired for this question? More people are like more features: they makes things more complex.
And complexity is not easy anymore. Avoid complexity in phase one. You still can make things more complex
when you once have understood even the simple setup.

Maybe it’s those project budgets who are responsible for this mess. Bugdets are agreed for a certain
period of time and it is expected that the budget is used only for this time. So the stakeholders try
to get as much as possible out of that budget in that time. I think people should start to think different:
Split projects into phases/stages right from the beginning and stick to the magic number 3.


Phase 1:

- the most simple setup, to go live. No “nice to have” features, only the most used stuff.

Phase 2:
- Add most important “nice to haves” which are based on analysis of Phase 1.

Phase 3:

- Here you can get experimental. Your business is running and stable. There is room to try out something new.

It would be nice to get some feedback about experiences from other people.
Maybe that is a german thing…mentality..you know all the stereotypes have a bit of truth in it :)
I would be interested in experience from other countries…are people more brave there and try to risk to do actually less ?

Veröffentlicht in Allgemein, Software-Development | Kommentieren

Mit Solid bei Radio Treibstoff

live und unplugged gaben wir unseren Song “Make you heal” zum besten.



Unser naechstes Konzert ist am Samstag d. 8.3. im JC HUGO in Jena zusammen mit Mastoles + Rhythmsphere

Veröffentlicht in Allgemein | Kommentieren

Leap Year Problems in FTP package of apache.commons.net

A collegue and I just found out that the FTP fuction listFiles() has a problem exactly today on Feb . 29th as we have leap year.

We just guest this, but as we have found this blog entry we were pretty confident.
http://blogs.lodgon.com/johan/Leap_year_issues_in_apache_commonsnet

Unfortunatelly also still an unassigned issue for the guys 
https://issues.apache.org/jira/browse/NET-188

If you have strange problems today with tools that rely on this framework you should have some more coffee and wait for tomorrow ;)

Christoph

Veröffentlicht in Allgemein, Software-Development | Kommentieren

Gute Nachrichten

Vorschriften im Verfassungsschutzgesetz NRW zur
Online-Durchsuchung und zur Aufklärung des Internet nichtig

Das finde ich gut…Lest selbst…

Veröffentlicht in Allgemein | Kommentieren

Krasser Tischsynthi

Veröffentlicht in Allgemein | Kommentieren

Toronto nicht nur kalt sondern “frozen”

…hach ja das Eaton Centre….da waer ich gern dabei gewesen :)

Veröffentlicht in Allgemein, Canada | Getagged | Kommentieren