Showing posts with label cloud computing. Show all posts
Showing posts with label cloud computing. Show all posts

Thursday, June 4, 2009

JavaOne 2009 Summary: Wednesday (Day 2)


Back again... well I'm sorry to write this but I could not make it yesterday to publish the summary of Wednesday. It was 2:15am and I was very exhausted after having been up since 7am. So, I still hope you enjoy this summary as I try to include as much infos as a can within the given time from different sources in the net and myself.

Related Posts so far:


JavaOne Day 2 Summary

=== Mobility General Session ===
  • Christopher David, Head of Development and Partner Engagement at Sony Ericsson, was the main speaker for the talk. During his presentation, Erik Hullman (a Senior Java Developer with Sony Ericsson) was given the task to develop a JavaFX Twitter client from scratch that at the end of the presentation should be deployed to three different devices!
    As if the task would not have been complex enough: People in the audience could send questions or comments to his Twitter accound that he answered in parallel to his programming efforts... and at the end, the same deployable artefact worked fine on all three devices. Sounds promising!!

    Rikko Sakaguchi, Corporate VP of Creation and Development

=== Technical Sessions Highlights ===
  • Hudson: Continuous Integration in the Cloud with Hudson
    (by Kohsuke Kawaguchi --> Blog)
    - I very much like the automated distribution approach: You start the Master Instance with Hudson installed as well as with the Hudson PXE Plugin (Prebuilt Execution Environment). After that you start the Slave Instance (on another machine) and boot from the network. That's it!
    - The defined target machines can be flagged with so called "labels" and can be used to ensure that Test Units aimed for Windows machines are executed on Windows boxes (and same for Unix boxes).
    - The Hudson Master instance can run on Windows or Unix.
    - Cloud: The demo was about the creation of a CI environment in Amazon EC2. It was very impressive how quickly the setup was done and executed successfully.
    - Hadoop: Kohsuke also mentioned the rather new plugin for Hadoop which makes Hudson run on Hadoop.
    - Slides: PPT



  • "Effective Java": Still effective after all these years
    (by Joshua Bloch)
    As in his other presentations, Joshua presented his content in a very nice way accompanied by his typical kind of humour... As of the end of the day, his book was again "Number 1" in the Bookstore's Top Seller List.

  • JPA 2.0 (by Linda DeMichiel)
    The new Criteria API as well as the introduction of the pessimistic locking modes were interesting to follow. Overall, the session was a little bit too much on the theoretical side.

  • WebBeans! Sorry: JCDI, Java Contexts and Dependency Injection: JSR-299
    (by Gavin King)
    I just like the way Gavin presents, he has his unique style, very straight forward and nice to follow. JCDI targets to support stateful objects, builds the glue between JSF and EJB, allows loose coupling with strong typing and introduces very nice concepts like BindingTypes and DeploymentTypes.

    After the speech we asked Gavin about the other "DI" related JSR submitted by Bob Lee (Google) and Rod Johnson (SpringSource): JSR-330. It states "This JSR targets Java SE, and it will lay a foundation for dependency injection in Java EE." So it seems that this is a big discussion at the moment as the JSR-299 has started 3 years ago and is nearly finalized now and could make it easily into the final release of Java EE 6 by end of this year whereas the newly submitted JSR would take at least 1 year until its finalization and would eventually postpone the release of Java EE 6 as 299 would directly depend on 330. I'm very curious how this gets resolved. My personal hope is that they agree on a common dependency injection foundation for SE and EE and include that one with potential EE specifics in the nearly finalized 299 (During the Java EE 6 Panel Discussion BOF, William Shannon meant that the EG would never accept two different DI specs on the Java Platform, so a common sense must be found, and quickly).
    Links around this discusssion:
    --> Bob Lee's initial post (from May 5th, 2009)
    --> Gavin King's statement (from May 7th, 2009)
    --> Bob's comment on Gavin's statement
=== BOFs ===
  • JSF Platform and Ajax: State of the Union
    with Ted Goddard (Lead Architect of ICEfaces), Andy Schwartz (Oracle ADF Faces) and Alexandr Smirnov (RichFaces)
    This kind of panel discussion was very interesting as each of the presenters talked about the current status and the progress towards JSF 2.0. RichFaces and ICEfaces convinced most (RichFaces because of its seemless integration with Seam and ICEfaces because of its architecture and the unique feature of automatic Ajax Push based on server-side DOM-diffing (more here)).
    Woodstock was not represented. As of the presenters there are no plans for further releases. On ICEfaces there is a migration plan described from Woodstock to ICEfaces.

    Ted Goddard


  • Java EE 6 Experts Discussion Panel
    hosted by Roberto Chinnici and William Shannon
    Good discussions, questions and comments... I was surprised that JSR-299 was not mentioned at all in the presentation about Java EE 6. After having asked the question why it is missing, a big *sigh* from Roberto Chinnici :-) (as expected), then responding that they were not yet sure about the inclusion of JSR-299 in Java EE 6. I reformulated my question what the current trend would be, rather "in" or "out". After eye-contacting with William Shannon, William meant "give him the full story"... Then the story around "JSR-299 vs JSR-330" has been described (see WebBeans above for more details).


    William Shannon and Roberto Chinnici

=== Pavilion ===
  • At the ICEfaces booth we met Micha Kiener (also from Switzerland) who is working for Mimacom. We were introduced to the overall architecture of ICEfaces and that looked really cool (server-side DOM diffing, Ajax Push). The demo showed a very elegant way of doing Interportlet Communication (IPC) on Liferay Portal 5.2. Really nice!!

  • And some pictures from the Pavilion and its entrance area...




    Dani at the SpringSource booth
    where it says "Eliminating Enterprise Java Complexity"
    ...





Cheers

Thursday, April 16, 2009

JBoss Seam on Google App Engine - First Steps

[UPDATE] The latest Morjarra release 1.2_13 as well as the latest Appengine SDK 1.2.2 seem to fix a couple of problems described below. My task backlog is actually growing :-) but I hope I find some time to look again how things work with these new versions.

I spent the last three weeks in a repetition course of the Swiss army - far away from any Java code. Naturally my fingers started to itch while reading the announcement of Google that their App Engine now supports Java! So I grabbed my MacBook to enjoy the sun, Java coding and Eastern holidays.

As I usually write web applications with JBoss Seam, I decided to give the framework a try in the Google cloud - preparing for a bumpy road as Seam founds on standards which are mostly listed as either not or not known to be working. The following article describes the (bad) tweaks I had to do to get something basic running - I guess if you start doing serious development, you might hit more walls.

First, install the Eclipse Plugin for App Engine and create a new project. I'll base my descriptions on this initial setup. Switch on sessions in appengine-web.xml:
<sessions-enabled>true</sessions-enabled>

Setting up JSF 1.2

Download the latest Mojarra 1.2 release [1.2_12] and put it in the WEB-INF/lib directory. You can configure the Faces servlet in web.xml as usual
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.seam</url-pattern>
</servlet-mapping>

Starting Jetty with only this will fail due to some incompatibilities of Jetty and Mojarra. As with Seam we will need JBoss EL anyway, we can configure Mojarra to use the JBoss EL ExpressionFactory. Add the JBoss EL JAR to WEB-INF/lib and the following XML to your web.xml:
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>

Now it's already patch time. Jetty in the Google environment seems to have a bug in its Servlet API implementation, missing the ServletContext.getContextPath() method (new in version 2.5). Also, Mojarra tries to be clever about initialization work and uses Threads in the ConfigManager - the App Engine SecurityManager will let the whole thing blow up. Something similar happens in the JBoss ReferenceCache class. All patched classes can be found here. Drop the Java code in your source folder, Jettys classloader will pick it up.

This will at least make the whole thing start up. I also added facelets (JAR file, view handler in faces-config.xml and view suffix in web.xml).

Unfortunately, using RichFaces components is an absolute no go on App Engine. RichFaces is full of references to AWT or JAI classes, which Google blocks completely. If anybody wants to try ICEFaces - good luck!

Adding Seam

Now it's time to add all the Seam stuff. Quite a couple of JARs to put into the application. I basically used Seam 2.1.1.GA and libraries from JBoss 4.2.3.GA. The complete list of what should go into WEB-INF/lib is shown in the screenshot below.



JTA is not even on the list of APIs Google gives a recommendation, so let's fall back on Java SE behavior. Configure components.xml with:
<transaction:entity-transaction entity-manager="#{entityManager}"/>


Although we cannot use Hibernate as persistence provider, Seam has a couple of dependencies to it (e.g. when using Hibernate Validators). As soon as we have it in the classpath, Seam activates its HibernatePersistenceProvider component. This will behave pretty bad, and for simplicity we just override this component:
@Name("org.jboss.seam.persistence.persistenceProvider")
@Scope(ScopeType.STATELESS)
@BypassInterceptors
@Install(precedence = Install.APPLICATION,
classDependencies={"org.hibernate.Session", "javax.persistence.EntityManager"})
public class OverrideHibernatePersistenceProvider extends PersistenceProvider {
}

Now also add a persistence provider as described in the Google docs and disable DataNucleus checking for multiple PersistenceContextFactory instantiations with this property in appengine-web.xml.
<property name="appengine.orm.disable.duplicate.emf.exception" value="true"/>


As before, also Seam needs a couple of patches. Main reasons for those are references to javax.naming.NamingException (which is not white listed, credits to Toby for the hint) and session/conversation components not implementing Serializable correctly. The last point is probably something not hitting Seam or your application the last time.

Identity

As a next step I tried to add some users to the application. Seam's Identity module builds around the javax.security.auth.Subject and Principal classes. Even though those classes are white listed, the SecurityManager blocks any attempt to add a Principal to a Subject. Well, how useful is that... As a quick fallback I integrated the Google Accounts API:
@Name("org.jboss.seam.security.identity")
@Scope(SESSION)
@Install(precedence = Install.APPLICATION)
@BypassInterceptors
@Startup
public class AppEngineIdentity extends Identity {

private static final long serialVersionUID = -9111123179634646677L;

public static final String ROLE_USER = "user";
public static final String ROLE_ADMIN = "admin";

private transient UserService userService;

@Create
@Override
public void create() {
userService = UserServiceFactory.getUserService();
}

@Override
public boolean isLoggedIn() {
return getUserService().isUserLoggedIn();
}

@Override
public Principal getPrincipal() {
if (isLoggedIn())
return new SimplePrincipal(getUserService().getCurrentUser().getNickname());
return null;
}

@Override
public void checkRole(String role) {
if (!isLoggedIn())
throw new NotLoggedInException();
if ((ROLE_ADMIN.equals(role) && !getUserService().isUserAdmin()) || !ROLE_USER.equals(role))
throw new AuthorizationException(String.format(
"Authorization check failed for role [%s]", role));
}

@Override
public boolean hasRole(String role) {
if (!isLoggedIn())
return false;
return ((ROLE_ADMIN.equals(role) && getUserService().isUserAdmin()) || ROLE_USER.equals(role));
}

@Override
public String getUsername() {
if (isLoggedIn())
return getUserService().getCurrentUser().getNickname();
return null;
}

public String createLoginURL(String destination) {
return getUserService().createLoginURL(destination);
}

public String createLogoutURL(String destination) {
return getUserService().createLogoutURL(destination);
}

public User getUser() {
if (isLoggedIn())
return getUserService().getCurrentUser();
return null;
}

private UserService getUserService() {
if (userService == null)
userService = UserServiceFactory.getUserService();
return userService;
}

}

Both create... methods can be used in the UI for generating login/logout URLs. Destination defines the URL the user gets redirected after successful login/logout. Also make sure that the identity configuration is removed from components.xml

Wrap up

Running this setup should give you a base for a very simple Seam app like in the screenshot below.



This first step has not been doing any persistence work, and my first tries with DataNucleus were not as straight forward as I had expected from a JPA implementation. Hope Google will catch up here with something more mature. Also, even the simple setup required a couple of nasty tweaks on the frameworks. Another big hurdle here are the runtime differences from production to local environment. For some serious work on App Engine, it's so far more recommendable to look into GWT.

Anyway, if you found this useful - looking forward to hear from your next steps in the cloud.