Adam Bien's Weblog

Monday Aug 30, 2010

Hacking Bookstore in a Bookstore ...with Java EE 6 - FREE JUG Session

Already looking forward to the JUG session in Hamburg. This time I will try to implement interactively a bookshop with Java EE 6, without any wizards, code generations, templates and other unfair stuff :-).
Because JUGs are fun - I will try to show as many Java EE 6 features as possible, and so probably over-engineer the application a bit. I promised that several times already - but now its time to proof the "lightweightness" of Java EE 6 in the IDE and not only on slides. I would introduce at least REST, JSF 2, CDI (JSR-330 and JSR-299), JPA, Bean Validation, EJB 3.1, Mocks, Unit Tests probably Maven (depends on the internet connection). Please prepare some heretical questions, or ideas.

See you at the bookstore "Lehmanns", 8 pm. They should also have some of "Real World Java EE Patterns - Rethinking Best Practices" books.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Wednesday Aug 18, 2010

Mail Of The Week: What I Can And Cannot Do With Java EE 6

Got an interesting email with questions regarding Java EE restrictions. Some answers:

>"I have installed Glassfish 3.0.1 and am using NetBeans 6.9.1 for implementing stuff"
Congrats - you saved about 5h :-).

  1. I have a web service running on Glassfish. What can I do now to access an RMI based server? Can I do this: HelloWorldRMI hdl = (HelloWorldRMI) Naming.lookup("rmi://localhost:2000/HelloWorldRMI"); String helloString = hdl.sayHello("WS");
    Yes you can. It works perfectly with all servers I know. This is what I do with greenfire.dev.java.net to access the native driver.
  2. Can I also open a socket from the same web service to another C++ based server?
    You can open client sockets, but not server sockets. I did it in the past with JBoss, Glassfish and WLS. The spec is a bit fluffy here.
  3. Can I write something to a file?
    It will work on most application servers, but it isn't compliant. It is also problematic regarding consistency and concurrency.
    You could write a JCA connector for transactional file access. It is easier, than you may think. I wrote a JCA-File connector in my book Real World Java EE Patterns - Rethinking Best Practices See page 181 - Generic JCA connector. My transactional example is comprised of ...4 classes and one XML file.
  4. Can I create my own classloader and load classes through there?
    It will mostly work, but is not compliant."...Allowing the enterprise bean to access information about other classes and to access the classes in a manner that is normally disallowed by the Java programming language could compromise security..."
  5. Can I dynamically create classes like this: MyClass myClass = (MyClass) Class.forName("...my.MyClass").newInstance(); String returnString = myClass.sayHello(className);
    This is perfect - except obtaining EJBs and CDI managed beans that way :-)


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Thursday Aug 12, 2010

What Is The Value Of A Software Architect?

(My) definition of the architect's role: "Software Architect is someone who is able to break down customers (=product owners, sponsors etc.) vision in more or less fine grained software artifacts"
I prefer the term "vision" over requirements, because most of the time requirements happen to be unstable and the customer actually unsure.
An architect should also immediately inform the customer about the impacts of his functional and non-functional requirements. Pro-active consulting in the definition phase about the consequences of high availability, modularization, distribution, security etc. is crucial and safes real money. The architect should be especially well experienced with possible problems and side-effects.

To provide a real value to the company, the architect should not only sell his ideas to the developers, but also convince them with hard facts and be open for feedback (a single architect just cannot be smarter, than a whole developer team). The problem here: it is very hard to convince developers with PowerPoint, Visio or plain UML-diagrams. A better idea is to verify the high level ideas with Proof Of Concepts - small applications or code snippets, and some test results (memory consumption, scalability, performance, testability). This easiest the communication a lot. Developers feedback will be a lot better, and there is no better concept explanation, as high level and clean Java, Ruby, Scala etc. code. Furthermore the PoC could evolve to a concept prototype and the could be used as a sample for a tutorial for new developers.

...my definition of developer's is: "Developer is an architect, who just don't want or is not able to deal with the translation of high level requirements into low level code, and enjoys to code more". Therefore an architect is a developer, who enjoys the translation and likes communication, meetings and everything else what is needed to extract the requirements from the customer.

An architect should be only a temporary role. Otherwise it will be harder to keep up with the technology and you will end up in an "ivory tower": "...From the 19th century it has been used to designate a world or atmosphere where intellectuals engage in pursuits that are disconnected from the practical concerns of everyday life. As such, it usually carries pejorative connotations of a wilful disconnect from the everyday world; esoteric, over-specialized, or even useless research; and academic elitism, if not outright condescension..." [from wikipedia]


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Wednesday Aug 04, 2010

JUGs, Un-Workshops, No-Slides Sessions, Interactive Hackings ...with Java EE 6 (the lightweight stuff)

  1. JUG Darmstadt: Stop Talking, Start Hacking "Session" in Darmstadt (24.08.2010)
  2. Java EE 6 Patterns, or one week Real World Java EE 6 in Hamburg (30.08-03.09.2010) - some places left - will take place
  3. I promised a talk at the JUG HH in between 30.08.-02.09.2010 - but the JUG guys seems to be on vacations. If you have another ideas for a JUG freestyle session in Hamburg in this period - let me know. In worst case we could occupy StarBucks :-)
  4. ch-open Workshop:Its Not A Trick - It's Java EE 6. Live - from installation to deployment There were > 24 registrations several weeks back. Looking forward to this one. I will use only few slides and a lot my keyboard. It will be an interactive hacking workshop.
  5. SIG Java: Java EE 6 from the IDE perspective, 09.09 in Munich
  6. JBoss OneDayTalk:Lightweight, Lean and Productive with Java EE 6, 01.10.2010 in Munich
  7. JavaOne in San Francisco, 19.09-23.09.2010: S313248 Creating Lightweight Applications with Nothing but Vanilla Java EE 6, S313250 JavaFX Script: The Java Patterns Killer, S313278 Java EE 6 Panel: What Do We Do Now?, S314243 Hacking Heating Systems with Java EE 6, JavaFX, and Scripting
  8. End 2 End Java EE 6 in Munich (20.10-22.10.2010) - we will build together a fullstack application. Furthermore I will try to answer as many questions, and solve as many problems as possible. In the last workshops we eliminated several millions lines of J2EE code, just during the breaks :-)
  9. Workshop: Xtreme Productivity with Java EE 6 in Munich, 04.11-05.11.2010 We will concentrate on productivity and "clean code" with Java EE 6. The aim of the workshop is rethinking of existing patterns and best practices and align them with Java EE 6


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Monday Aug 02, 2010

Why stateful and local anti-facades are KISS

The Gateway exposes rich and persistent domain objects directly to the presentation logic. Because the domain objects are well encapsulated already - it is rather an advantage, than a shortcoming. Because of simplicity and built-in aspects, an EJB 3.1 happens to be the simplest and leanest candidate for a Gateway implementation.

Why local (to JSF 2, Wicket or a Fat Client)?

  1. Rich domain objects (JPA 2) contain business logic per definition. A call to method can change the state not only of the target entity, but of the whole connected graph. In the local case the EntityManager will correctly recognize the changes and compute deltas (change sets) and persist all changes at the end of the transaction. In remote case you will have to implement the same functionality - what is actually duplication.
  2. In local case you don't have to care about lazy loading. The entities gets just loaded on demand.
Why stateful (means: keeping the entities attached between requests)?
  1. In complex scenarios the data synchronization between layers becomes a challenge. If you keep you entities managed between requests, there is nothing left to do. You can even bind them directly to the UI - and it will still work.
  2. For every request you will have to build the domain graph again and again. This is not only complex, but it does not necessarily scale better, than a stateful solution

Local, stateful facades are not necessary the silver bullet, but the resulting architecture is very lean. It mainly consists of only domain objects, with a few Gateways.
Before you start prematurely "improving" the scalability and start with bloated applications, it is more reasonable to concentrate on the core business logic and stress test continually the application. In some cases a stateful architecture wont't scale. In this case you will have to provide the synchronization, delta-computation afterwards - with demand documented with stress test results.

[See Gateway, page 101 in "Real World Java EE Patterns Rethinking Best Practices" book for more in-depth discussion]


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Thursday Jul 08, 2010

A Day In Paris (JUG) With Java EE 6

Back from JUG Paris. It was almost a conference (~200 attendees). It was my first time in Paris -> I really like the city. Although I was said to got some competition by the football world championships, the room was packed.I predicted France to become the football world champion (I'm a true football expert :-)) - the attendees liked my expertise in this area.

I started with slides and ended in the IDE. What I really enjoyed - was the amount of good questions (from AOP, to SmallTalk). The situation escalated in the breaks, where some attendees asked me several questions at the same time concurrently. These questions were the best.

In the last part I build a JUG Management System with CDI, EJB 3, JPA, REST (JSON+XML), a bit security, Servlets and in the last two minutes I introduced JSF 2. Because of time, I started to answer questions in the IDE :-).
After the session we spend about 2 hours in restaurant and another 2 hours in a bar - still discussing Java EE, Clustering, Failover, scalability, private / public Clouds Java, even JINI. We discussed 98% Java and 2% private stuff (like the relation of a freelancer to vacations :-)).

Paris JUG is really well organized - and all participant seem to have lots of fun. Really enjoyed that. Already looking forward to SophiaConf in Nice. What also interesting - there is a female group of Java Hackers in Paris. This could be the beginning of a female Java Champions division as well.


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Friday Jun 25, 2010

Java FX CSS Reference Available

The appearance of UI-Controls in Java FX can be either configured programmatically, or with CSS. See this comprehensive CSS reference. Hopefully it will be distributed with the official SDK doc in the next release...
Its a kind of "Convention Over Configuration" again :-).


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Monday Jun 21, 2010

EJB 3.1 + Hessian = (Almost) Perfect Binary Remoting

EJB 3.1 + REST are perfect combo for HTTP and resource style programming. REST is not very well suited for the exposure of already existing interfaces. The RPC-misuse of REST will result in hard to understand and so to maintain code.
With hessian it is very easy to expose existing Java-interfaces with almost no overhead. Hessian is also extremely (better than IIOP and far better than SOAP) fast and scalable. The size of the whole hessian library (hessian-4.0.7.jar) is smaller than 400 kB and so compatible with the "Kilobyte Deployment" style of Java EE 6 programming and deployment.

To expose an existing EJB 3.1 with hessian:


@Stateless
public class CurrentTime {
    public long nanos(){
        return System.nanoTime();
    }
}

You will need an interface:

public interface TimeService {
    public long nanos();
}


...and hessian-specific implementation of the endpoint:


public class HessianTimeEndpoint extends HessianServlet implements TimeService{
	
    @EJB
    CurrentTime currentTime;
	
    @Override
    public long nanos() {
        return currentTime.nanos();
    }
}


The hessian enpoint is an servlet - so the dependency injection works here without any XML configuration. You can just inject your no-interface EJB 3.1 view bean into the servlet.
The client side is also very lean. You only need a two lines of code to get a reference tot he proxy:

public class HessianTimeEndpointTest {
    private TimeService timeService;
	@Before
    public void initProxy() throws MalformedURLException {
        String url = "http://localhost:8080/EJB31AndHessian/TimeService";
        HessianProxyFactory factory = new HessianProxyFactory();
        this.timeService = (TimeService) factory.create(TimeService.class,url);
        assertNotNull(timeService);
    }
    @Test
    public void nanos() {
        long nanos = this.timeService.nanos();
        assertTrue(nanos>0);
        System.out.println("Nanos: " + nanos);
    }
}

HessianServlet inherits from GenericServlet and not from HttpServlet. This is a shame, because you will have to use a web.xml deployment descriptor, instead of a single annotation @WebServlet:

<web-app >
    <servlet>
        <servlet-name>TimeService</servlet-name>
        <servlet-class>com.abien.patterns.business.sf.hessian.HessianTimeEndpoint</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TimeService</servlet-name>
        <url-pattern>/TimeService</url-pattern>
    </servlet-mapping>
</web-app>

You will find the executable project (tested with Netbeans 6.9 and Glassfish v3.0.1) in: http://kenai.com/projects/javaee-patterns/ [project name: EJB3AndHessian].
The whole WAR (EJB 3, Servlet, web.xml and the hessian "framework") is 393 kB. 385 kB hessian, and 7 kB EJB + Servlet :-)


The initial deployment of the WAR with EJBs took:

INFO: Portable JNDI names for EJB CurrentTime : [java:global/EJB31AndHessian/CurrentTime!com.abien.patterns.business.sf.CurrentTime, java:global/EJB31AndHessian/CurrentTime]
INFO: Loading application EJB31AndHessian at /EJB31AndHessian
INFO: EJB31AndHessian was successfully deployed in 807 milliseconds.


Don't worry: the subsequent deployments are substantially faster :-):

INFO: Portable JNDI names for EJB CurrentTime : [java:global/EJB31AndHessian/CurrentTime!com.abien.patterns.business.sf.CurrentTime, java:global/EJB31AndHessian/CurrentTime]
INFO: Loading application EJB31AndHessian at /EJB31AndHessian
INFO: EJB31AndHessian was successfully deployed in 568 milliseconds.

[See also Service Facade pattern, page 69"Real World Java EE Patterns - Rethinking Best Practices]


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Monday Jun 14, 2010

A French And Free Java EE 6 Week - Some Slides, More Code

The free Java EE 6 events in the week of 05.07-09.07.2010 will start at July the 6th in Paris. I will give a (hopefully openspace-like / interactive) presentation with the title Lightweight Killer Apps with Nothing But Vanilla Java EE 6.

In the same week I will give a releated presentation Java EE 6 - Leaner Than POJOs in Nice.
Java EE 6 is so lightweight - that it may look overly complicated on slides. For that reason I will spend the majority of the time in the IDE. Hope it is o.k.
Thanks for the invitation (and sorry for the rollbacks in the past)! I guess I'm the only speaker with a truly french last name - but without any capability of speaking french :-).


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Saturday May 08, 2010

How Popular Is Actually Java EE 6?

I'm back from the JAX 2010 - one of the biggest european Java conferences. There was lot more interests in Java EE 6, than expected:

  1. The "Simpler? - Is Impossible - Java EE 6" Workshop was fully booked - with 75 reservations. The actual number of attendees was approx. 100-150. Even the repetition at the very last day was well attended (12-20 attendees I had far more attendees at the end, than at the beginning :-)).
  2. The "60 Minutes With Java EE 6" talk was also well attended - it took place in one of the biggest rooms (the keynote room).
  3. We got a table with the topic "Weightless Beans" for the open space part of the conference. Because of the number of attendees, we had expand to the next table near us - and had a lot of fun and nice conversations about Java EE 6 (EJB, CDI, JPA) and the craziest errors in production.
  4. Java EE 6 trainings are almost sold out. I increased the max-number of attendees to 20.
  5. We asked the audience after our (Peter Rossbach, a Tomcat-Committer and me) Tomcat + openEJB session, who would be interested in a Tomcat+EJB distribution. More than half attendees were interested.
  6. Several conference attendees reported me that they are in the process of migration to Java EE 6 ...from Java EE 5

JAX was really nice conference with great food and interesting topics. Already looking forward to W-JAX! Thanks for attending the workshops, sessions - your feedback is highly appreciated.

 


[my tweets]  Rss My book: Real World Java EE - Rethinking Best Practices

Meta-stuff / Interviews
My Recent Book
Java One 2009
JavaONE 2008 Interview
Search
...the last 150 posts
...the last 10 comments
Links
Visitors
License