Monday, 30 March 2009

Some notes from Sun GlassFish portfolio tech talk, London

Sun GlassFish and GlassFish portfolio - Sun talk London, Regis House 25-03-2009

Some notes that I managed to take whilst at the talk.

Claimed to be the fastest Java EE AS

V2.0 -> reference implementation for Java EE 5
V3.x -> reference implementation for Java EE 6

Java EE standard 10 years old

Metro -> Interop between MS and Java WS.* standards

GlassFish is Open Source under CDDL and GPL 2 license

Transparent development

Organic growth into middleware areas

First appearance 2005
V2 in 2007
Current v2.1 in Feb 2009

6-700 downloads per month, 8 million in the last year / ~28k per day

GlassFish portfolio is a set of related technologies including the AS
  • Enterprise server (including support for SNMP)
  • Web space server (joined with Life Ray - social networking & portal technologies)
  • Web sack (a complete (L)(S)(?)AMP stack)
  • GlassFish ESB (SOA platform) for integration, connectors, adaptors

Java EE + Ruby on Rails, PHP and other frameworks

(note - what is SFA?)

Enterprise version adds:
  • Performance advisor, performance monitor, SNMP, self management and alert manager
  • Update center

Example / reference sites:
  • - Glassfish & OpenMQ
  • GlassFish, message queue and mysql (started by using community edition)
  • North american Nationwide Health Information Network - connect (NHIN- Connect)
  • OpenESB
  • ESB.SOA framework
  • Facebook - large mysql based system ~70million users

GlassFish has same levels and structure in terms of support and licensing as MySQL

Web Services: WS.*
  • Metro is core in GlassFish AS
  • Project Metro Web services stack provides high level WS stack with security, reliability etc -> .NET 3 interoperability (incorporates project tango - MS .NET interop)


  • JAX-RS JSR-311 Java API for RESTFul Web Services
  • Annotation based server side API
  • HTTP Centric
  • Server Side only
  • Servlet or SE deployment

Jersey project provides implementation for JSR-311


Similar / faster than Weblogic and Websphere

GlassFish V3:
  • OSGi: Apache Felix as default (origins in JSR-8)
  • 1 sec startup
  • 21Mb download
  • admin and update tool downloaded on demand

Add-ons, modules available from update center:
  • EJB 3.1 (preview
  • jRuby on Rails (new WAR packaging required)
  • Grails (also on GFv2)
  • Jersey and Metro (Web services)
  • jMaki (AJAX)

  • NetBeans and Eclipse
  • Embedded GlassFish API

MicroKernel approach - modularity - base App server + on demand module loading, extensible and customizable

("Eclipse Con" -> announces GlassFiish bundle available)

Db connection pooling and connection (connector) pooling (JCA)

V3 Prelude
  • available from -> using modular (microkernel) v3 ideas with existing EE5 technologies -> this version is supported!
  • v3 prelude is Java EE Web layer only (i.e. servlets, JSPs etc but no Enterprise beans etc)

Compile / Deploy on Change support, dynamic debug loop (netbeans & eclipse), incremental compile of all Java EE artifacts. Auto-deply of all Java EE and static artifacts

Support for: JRuby, Ruby, Groovy, Grails, Python, jython, django, jmaki, JavaScript phobos

Ruby / jRuby and rails can be run on 2.1 today (by packaging up dependancies), on v3 available as OSGi jRuby container

  • Quercis (Caucho) opensource GPL php 5 implementation in Java
  • War Packaging
  • Java Bridge

V2 -> ee 5
V3 -> prelude with EE5 support
V3 -> early access is EE6 spec (but not supported)

GF Web Stack:
  • Apache HTTPd
  • Sun web server 7 (most scalable web server - now open sourced!) optimized for multi-core CMT (chip-based Multithreaded) systems - 2x scaling vs. Apache & Tomcat
  • lightpd
  • memcached
  • mod_jk, perl, ruby, PHP Ruby, Python, Squid, Tomcat

Current GF web stack is 1.4 (Python 2.5.2, Squid 2.6, Tomcat 5.5.27, memcached 1.2.5, mysql 5.0.67)

  • JSR 208 JBI (Java business Integration)
  • Plug-able integration into backbone
  • "Metacontainer" - add new containers within the container, extend the AS
  • BPEL, WS-*, XSLT, FTP, LDAP, HTTP, DB service and binding
  • Based on OpnESB -> / community
  • Maybe engines and connectors to things like Corba etc

What's next -> -> OpenESB V3 - next gen of SOA

(JBI and SCA stated as "complimentary, not conflicting")

GF: Web Space server (project web synergy)
  • Portlet spec JSR-268 and more (social networking, communities)
  • OpenSSO, identify mechanisms
  • Compelling web UIs

GF enterprise manager:
  • Performance advisor
  • Alerts
  • JDBC pool management - automatically tunes JDBC connection pool to optimize performance etc

Sailfin (Ericson contribution) telco, SIP, VOIP, Instant messaging

dtrace etends into Apache and PHP

Revamped PetStore 4 part tutorial -

OpenSSO -> new concept "express builds" - milestone interim builds from Open Source community in between main supported releases


New White-papers on GlassFish portfolio launch:
  • Comparison with Tomcat
  • Performance optimization
  • GF with identify and MySQL

Training available in Camberly, BSG in London etc

  • GlassFish
  • Database-driven application development
  • Others available (I didn't get time to note them down) -> god launch pad for developer information -> gives examples and real usage info

Migration tools:

built in tools to detect and advise on code usage (for EE standards and vendor specific code dependancies)



JavaFX mobile - answer to J2ME shortcomings -> many tutorials and demos

GlassFish profiles - Developer mode (no clustering etc) but fast start up and change deployment


DAS - Domain Administration server looks after a cluster, deploy to the domain administration server and it deploys to the cluster nodes.

Session replication between cluster nodes, zero down time when switching between nodes

install with -cluster switch

Cluster elements run "node-agents" to talk to the DAS

Extra sections in the admin console -> shows cluster nodes

GlassFish performance monitor - enterprise only (TBC)?

V3 Prelude - web tier only (web apps) but fully functional

Presentation has now been published here:


Sunday, 8 March 2009

Apple iPhone Development - introduction and resources

Apple iPhone Development:

So, it seems like everyone's doing it these days, but that's no excuse for me not to join in is it?...

Objective-C you say, isn't that a bit like Smalltalk?
xCode, what's that exactly?
Cocoa, Nibs? what the?!?

Well there's much to learn, but most of it seems reasonably straightforward. The Apple documentation is good, there are videos to watch and tutorials, most of these resources can be found via the Apple iPhone dev center on the Apple website. From what I've gathered so far, its quite far removed from previous mobile development I've done, such as J2ME and .NET CF.

Armed with a new Apple Mac I'm making some notes as I venture into the unknown.

Firstly, here are a bunch of useful resources:

iPhone Dev center:

iPhone Developer Program:

iPhone SDK:


Objective-C is an object orientated version of the C language. Specifically for the iPhone, Objective-C 2.0 is used.

Objective-C has been influenced by Smalltalk, yes that's the OO language with all the [] in it.

iPhone development guide:

First iPhone application:

The current latest version of the iPhone OS and iPhone SDK is 2.2.1 (whilst at the time of writing this 3.0 is in beta preview).

The next version, 3.0 is to be officially launched soon, the SDK should be available before the official OS release, in theory. What's in it, what's different I don't know yet, but hopefully it will be largly compatible with the current version, whilst adding some interesting new features into the mix. Rumoured are things like the much awaited support for copy, cut and paste for example.

HTTP and XML, web services:
Interested in hooking up an iPhone application with some web services, some means to make an HTTP request and parse XML is needed, here are a couple of resources on this:

Simple solution using some utility code:

A more advanced solution:

Useful article on RESTful clients:


Sunday, 1 March 2009

Prime factorization, a comparison between Haskell and Scala

Haskell is a powerful and expressive pure lazy functional programming language with some interesting properties. Haskell is of course named after the famous logician Haskell Curry who's name can be found in both the Haskell language and the process of "currying" functions.

By way of example and comparison the task of finding prime numbers is shown in Haskell and then its equivalent is shown in Scala.

We can see the conciseness of Haskell and the power of lazyness in expressions of the form:


which creates an infinite list of integers from 3 upwards. This seeming impossibility can be handled in a lazy functional language because the infinite list is not evaluated up front, rather the list is only evaluated when needed so the list is finite at any given point in time.

So, in essence a lazy language is one where an expression is only evaluated when it's needed, unlike an imperative language where it's evaluated when declared.

Haskell: prime factorization example:

divides :: Integer -> Integer -> Bool
divides d n = rem n d == 0

ld :: Integer -> Integer
ld n = ldf 2 n

ldf :: Integer -> Integer -> Integer
ldf k n | divides k n = k
| k^2 > n = n
| otherwise = ldf (k+1) n

factors :: Integer -> [Integer]
factors n | n < 1 = error "Invalid argument: argument must be positive"
| n == 1 = []
| otherwise = p : factors (div n p) where p = ld n

If the above is saved in a file (called say primefactorization) and loaded into Hugs (Hugs is a Haskell interpreter shell based on Haskell 98 - using the :l command as follows:

Main> :l c:\Dev\haskell\primefactorisation

Scala: prime factorization example:

package test

object PrimeFactorisationTest {

def divides(d : Int, n : Int) = {
(n % d) == 0

def ld(n : Int) : Int = {
ldf(2, n)

def ldf(k : Int, n : Int) : Int = {
if (divides(k, n)) k
else if ((k*k) > n) n
else ldf((k+1), n)

def factors(n : Int) : List[Int] = n match {
case 1 => Nil;
case _ => {
val p = ld(n)
p :: factors(n / p)

def main(args : Array[String]) {
if (args.length == 1)
val n = Integer.parseInt(args(0))


Main> factors 12343434

Both programs produce the same output and are functionally equivalent - it's also clear to see there's a reasonably similarity in both conciseness and expressiveness of the two languages, where Haskell possibly has the slight edge in some respects such as use of the "where" construct.


Following on from the excellent comments on the Haskell version from Don Stewart, turning the code into something that can be compiled and executed natively, rather than being interpreted using Hugs, roughly involves the following steps.

Install GHC

Rename the file to have a .hs file extension

Add a main that can process the arguments:

main = do
[n] <- getArgs
print (factors (read n))

add import to provide environment functions such as getArgs to the top of the file:

import System.Environment

Compile the file:

$ghc --make primefactorisation.hs

Run the executable:

$ time ./primefactorisation.exe 12343434

real 0m0.140s
user 0m0.015s
sys 0m0.015s

and there we have it, a functional executable.

Don Stewart also makes a good point about being able to leave out all the type information.

In particular Haskell uses the powerful Hindley-Milner type inference algorithm to allow minimal (often zero) use of explicit type declarations.