Archive

Archive for the ‘Education’ Category

Found a Foreword and Releasing that Java EE 7 Cat

May 23rd, 2013 No comments

It time to release that cat out of the bag, I feel now. I have the pleasure of announcing that the great Markus Eisele has agreed to write the foreword to my forthcoming book: Java EE 7 Developer Handbook from Packt Pub.

Markus Eisele is an Oracle ACE  Director, a champion of Java Enterprise Edition, knowledgeable in messaging systems and is a German author of note. He lives and works in Germany; and Markus is famous for sending scores of valuable tweets on Java EE and related technology as the user @myfear. I am very pleased to have Markus be an early access reviewer for book and he recently accept my invitation.

Now that cat has been released; and it is finally free. I can let you also know a few more things. I am using my time on the contractor bench of truth to dig deep and finish writing the remaining content of the book. The aim of this book project is to have it fully ready for September 2013; published, printed and shipped for  JavaOne.

Currently, the chapters sort of look like this:

  • Chapter 1 Introduction
  • Chapter 2 CDI
  • Chapter 3 EJB
  • Chapter 4 Essential JPA
  • Chapter 5 Intermediate JPA
  • Chapter 6 Java Servlets 3.1
  • Chapter 7 WebSocket 1.0
  • Chapter 8 JAX-RS 2.0
  • Chapter 9 JMS 2
  • Chapter 10 Bean Validation 1.1
  • and more

The content is subject to change, of course, and all of the usual caveat emptors and legal clauses apply. Sadly, I decided to drop the JSF content out of the book, because we are rather too close for comfort to page limits for hardware printers.

+PP+

PS: I have a couple of other secret helpers out there and they know who they are. Thanks to you also.

Build GlassFish 4.0 Snapshots Yourself

March 16th, 2013 Comments off

This post is about building GlassFish 4.0 snapshots release yourself and includes hacks.

I found the official Instruction for FullBuild of GlassFish and then decided to build the server myself. Sometimes, you may not want to wait for the GlassFish build files to be promoted by the team. In this entry, I reference Artifactory as a private Maven repository, of course, you can use something else as well.

Checkout the source code for GlassFish 4.0 yourself from Subversion:

svn checkout https://svn.java.net/svn/glassfish~svn/trunk/main glassfish-main

You need to hack the Maven Settings file for your workstation to exclude Eclipse artifacts.Here is an example of the settings.xml, which I configured.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0

http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <!--Maven http://maven.apache.org/settings.html -->
  <localRepository/>
  <interactiveMode/>
  <usePluginRegistry/>
  <offline/>
  <pluginGroups/>
  <servers>
      <server>
         <id>ACME-ARTIFACTORY-PRIVATE</id>
         <username>administrator</username>
      <password>password</password>
    </server>
  </servers>
	<mirrors>
		<mirror>
		  <id>maven-central</id>
		  <url>http://repo1.maven.org/maven2/</url>
		  <mirrorOf>central,!eclipselink.repository</mirrorOf>
		</mirror>
	</mirrors>
  <proxies/>
  <profiles/>
  <activeProfiles/>
</settings>

Before we can compile the entire GlassFish code, we need to hack POM files so that they install artifacts into our private Artifactory server instead of the Maven Central.

Add the following Stanza to the POM files in the distribution:

	<distributionManagement>
		<repository>
			<id>ACME-ARTIFACTORY-PRIVATE</id>
			<name>acme-releases</name>
			<url>http://peabody.internal.acme.com/artifactory/ACME-ARTIFACTORY-PRIVATE</url>
		</repository>
		<snapshotRepository>
			<id>ACME-ARTIFACTORY-PRIVATE</id>
			<name>acme-snapshots</name>
			<url>http://peabody.internal.acme.com/artifactory/ACME-ARTIFACTORY-PRIVATE</url>
		</snapshotRepository>
	</distributionManagement>

In the above Stanza, edit the definitions from ACME to the Artifactory server that you privately own, then copy it the following POM files:

  • main/pom.xml
  • main/appserver/javaee-api/pom.xml
  • main/appserver/pom.xml
  • main/nuclues/pom.xml

This is a nasty hack, because I don’t like that you can’t set change the deployment server and credentials from a configuration. Other source code allow configuration of the deployment server through Maven Profiles or even property files.

Make sure that your Maven settings are correct for Artifactory deployment and also we set up Maven build process. Set the environment variable MAVEN_OPTS so that there Maven has enough memory and the permanent generation is high enough to avoid out of memory exceptions during compilation.

MAVEN_OPTS=-Xmx1024m -Xms256m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled

If you have 16GB RAM workstation, why not just max it out for compiling the entire GlassFish? The Garbage Collection algorithm is changed to the concurrent mark and sweep algorithm and we also set the enabled class unloading enabled.

You are ready to compile, entering the following commands:

cd glassfish-main
svn update
mvn clean
mvn install -DskipTests=true

Make yourself a hot beverage and snack for about 20 minutes on a decent Intel Core i5/i7 machine (2012). Have a break. Notice that we avoid running the unit tests here, we skip the tests, because we just want a working release in repo, quickly, which is just not to say testing is bad.

After successful compilation of all of the modules, now you are ready to deploy to the private Maven repository. If you have followed the earlier instruction, about copying the stanza to the individual POM files, then you can execute this command from root.

cd glassfish-main
mvn deploy -DskipTests=true

After deploying the artifacts to Artifactory, check the repository for snapshot 4.0 release, they should all be there.

Now descend to the Java EE project folder. Hack the POM file, glassfish-main/appserver/javaee-api/javax.javaee-api/pom.xml. It is missing the maven source plugin in the build section, and therefore, by default, it does not generate the sources JAR, which is useful for seeing the new JavaEE 7 APIs!

Find the XPath project/build/plugins and append the following stanza to this POM.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Execute the following command line, to deploy the Java EE api artifacts

cd glassfish-main/appserver/javaee
mvn deploy -DskipTests=true

For some reason, the main execution does not install javax.javaee-api artifacts automatically. Executing this line generates JAR and SOURCES JAR for the three underlying modules: javax.javaee-api, javax.javaee-web-api and javax.javaee-endorsed-api.

Go Artifactory and see that the artifacts have all been deployed. You can then write a Gradle build file like this:

repositories {
    maven {
        credentials {
            username 'administrator'
            password 'passowrd'
        }
        url 'http://peabody.internal.acme.com/artifactory/ACME-ARTIFACTORY-PRIVATE'
    }
    maven {
        url 'https://maven.java.net/content/groups/promoted'
    }
    maven {
        url 'http://repository.jboss.org/nexus/content/groups/public'
    }
}

dependencies {
    providedCompile 'org.glassfish.main.extras:glassfish-embedded-all:4.0-SNAPSHOT'
    providedCompile 'javax:javaee-api:7.0-bpeter-private'
    providedCompile 'javax:javaee-web-api:7.0-bpeter-private'

    compile     'org.glassfish.main.extras:glassfish-embedded-all:4.0-SNAPSHOT'
    compile     'javax:javaee-api:7.0-bpeter-private'

    testCompile 'junit:junit:4.10'
}

Especially, note that the build version are annotated as 7.0-bpeter-private.

The last piece of the puzzle, which I have not yet worked out is how to configure the build.id Maven property so that I can customize the build number. It is a mystery, still. If you happen to know the answer, please give me a bell. Cheers!

+PP+ 2013
 

PS: The EclipseLink uses it own Maven repository for artifacts: http://wiki.eclipse.org/EclipseLink/Maven


 

Categories: Education, Glassfish, JavaEE, javaee7, Open Tags:

Agile Software Developer Terminology for New Programmers

December 21st, 2012 2 comments

This is a post for new developers, young, inexperienced or old and retraining into information technology.

Recently, I had a discussion with many engineers at one of those many London user group nights about how there is so much new stuff that we have to explain to people new to programming. One person had to coach a graduate developer on writing unit tests. Another person had to explain the reasons why dependency injection is better than dependency lookup.  I can recall similarly stuff, being able to gently and concise explain why we should have unit tests in the code, and why we need them.

Here is my current matrix of terms:

Term Description
YAGNI You Are Not Going To Need It – The issue hare is that far more code is written than necessary to solve or deliver application functionality. 

Classic symptom: Added unused finder methods to session beans in Java EE

DRY Don’t Repeat Yourself – writing code that has lot of duplication across methods, classes, packages and package object. 

Classic symptoms: Copy & Paste coding in unit tests and repeated metadata in entity and the front end

KISS Keep It Simple Silly [or Stupid] – a mantra to describe writing only code to solve the function problem instead of writing a less complicated codeAlso see Occam’s Razor.

 

Classic symptom: Too many abstract layers in a software application

WET Write Every Time – the antithesis to DRY, where code is deliberately written that repeats lots and lots of time in different classes, packages, and functions. 

Symptoms: Deciding to do things your way and instead of collaborating with the other developers and finding some common ground.Classic antidote: DRY, Unit Tests and Code Refactoring.

WETTT Write Everything Ten Thousand Times – the hyperbole colloquial version of WET
R3 Rules of Three – This is not the proprietary operating system of the same name, or the classic 1980′s arcade game, or either the description of a maxed out pimp-my-ride Volkswagen Golf; but the idea that when ever you have three duplicated parts of code in a method, function or classes then it is time to refactor the duplication in to single method. See Rule of Three computer programming. 

Related to DRY and WET

 

Class Symptom: Ignoring the code repeats because of time pressures, or the Scrum master says no, don’t do it in this sprint.

DBC Design By Contract – the idea of building a service from a contract first. In Java you write the interface as simply as possible and then secondly worry about the implementation class.

 

Interfaces are easier to refactor around and because you can plug different implementations into the interface you get higher cohesion and lower coupling.

 

Classic Example: JDBC specification since version 1.0. There are tons of implementations for different relational databases including MySQL, Postgres, H2, Derby etc.  Every Java programmer knows how to code against JDBC because that they don’t have to fight with an different implementation, which vary, because the DBC implied it will do the right thing most of the time.

 

Also related to standardisation of application programming interfaces.

BDUF or BUDF Big Up-Front Design – a problem with many large corporate institutions that sometimes require a 100 – 1000 page document full of business requirement before any software construction gets the green lightSome poor architect or business analyst will have spent weeks investigating and chatting to the business about the requirement, only for the development team to say the document is practically worthless.

 

Antidote: Get the technical lead and some key developers talking with the business and the analysts and the customer. Ideation sessions everybody!Symptom: Waterfall methodology and aspects of the investment banking IT culture

 

Antidote: Unknown, lots of people how tried to bring “Agile” with both a big A and small A to many of these institutions with some success and failure

Pink Book Describes the book with a Pink Cover called Extreme Programming Installed by Ron Jeffries, Ann Andersen, and Chet Hendrickson. I do not recommend this for new starters unless for reference, since the Pink Book is now rather old, 2000, there are other more recent Agile development books and courses that help new Java developers.
YOLO You Only Load It Once [If Ever] – this is related to fact that you want to have a single source of truth in an application system. This is problem of mis-architecture, where someone has not thought the functional requirement through enough.

 

Classic Example: Shopping Cart Service EJB – you only ever want one implementation of the pay-point in an application, albeit you will have many pay-point providers (credit and debit card third parties and PayPal)

 

The If-Ever part is YOLO and YAGNI added together. You are not sure of the another part of the system loads the data, so you decide to keep the component. (You probably want to put a logging client on the YOLOIF thing so that you can effectively decide to chuck the component if nobody has used the function in 12 or 18 months time.)

 

Digression: If you have find data that is constantly being uploaded to serve a web request then perhaps it really needs caching and not YOLO.

Spike A quick exploration of coding in Sprint in SCRUM methodology, which is also time-boxed inside a single sprint, usually. In a Spike you are probably are looking an new API, like a cloud service or user interface API like JavaFX or similar and basically you explore if the function can implemented relatively well in the new API.In short, you are trying to build some confidence in a new area before committing yourself and other resources to it. Spikes are usually contained and protected from the flow of the critical path and restricted to a time length. See SMART goals. Once your team has gained confidence and knowledge in the new “thing” then reasonable estimates can be made.

 

Classic Examples: Adopting a build system – moving from Apache Ant to Maven; moving from Subversion to Git; Adopting a new open source library

TDD Test Driven Development – often conflicted as not being fully explained as a change of discipline and mind.”You are only ever doing one of these four things: writing unit tests, writing production code, refactoring unit tests, and refactoring production code; and never doing more than one at these previous at the same time.”
TFD Test First Development – builds on the ideas of TDD and then extends the discipline to writing unit test code before any production code.”Once you have a brand new unit test written completely, then you make sure that new unit test(s) actually fail in order to switch over to writing production code ensures the the new test passes.  After you have done that, you refactor the tests. Run all tests for all the green bars. Refactor the production code and runs the tests for all the green bar.Repeat: Go back to the start; write a new unit to that will check validate operation of the next function for the application. Repeat with the same formula as above.”

 

Velocity This is often misunderstood as a very basic measurement on the Return-on-Investment for SCRUM/XP software development and it has nothing at all to do with financial services, budgets and/or reporting. The creators of SCRUM/XP now disuade velocity as a ROI indicator at all.

 

Velocity is the number of story points completed per team per iteration. To the SCRUM/XP  experienced: Velocity is equal to the aggregated units of work completed over aggregated time intervals, which implies you measure each progress of tasks in two or more sprints.

Story Point For each user story in the sprint or task, predict  how hard it is to implement by using unit of reference. 

Story points are usually written in Fibonacci numbers: 0, 1, 1, 3, 5, 8, 13, 21, 34, 55, 89, 144Every agile team in the world has a definition of a user story unit point.Teams decide on the backlog items in order to come up with predictions and these joint predictions every member of team go to decide what should applied to the next sprint.

DTSTTCPW Do The Simplest Thing That Could Possibly Work – Related to Spike and KISS in many ways. If you are pressed for time and some trading systems developers in investment bank are then this is your working life. 

DTSTTCPW certainly invites team collaboration and effective sound-boarding from other developers and members of the team, otherwise you are asking for trouble.

VoC Voice of the Customer – This is a term from SCRUM methodology, but I am about 20% unsure about this one; I believe 80% of the time to mean a proxy, a placeholder, for the real customer, the person who understands the business requirement and will of the customer. Because the true user is unavailable for some reason due to authority, culture or organisation, or even geo-location. 

Some people have amusing called this abbreviation, the Voice of Reason, especially when they do not enjoy working with the customer directly.

Unit Test In Java programming, a Unit Test is a Java JUnit framework test class or TestNG framework test class that specifically verified and validates a single function of work in an application 

A unit test requires a target, which can be a Java Class, a Service Bean, Managed Bean or something implements the said functionality.

 

Unit test are often seen as low-level fast and efficient tests.

Functional Test A functional test is a larger test, which can also be a unit test, designed to test packages of classes or sub part of the overall application infrastructure. Functional test validates if the application meets one of the customer’s external requirements on performance, results and efficiency.

 

Symptom: a functional test is not necessarily a unit test, and not all functional tests are acceptance tests.

Acceptance Test An acceptance test is the same as a functional test in name only. Acceptance tests are those where the customer wants to see the validation pass in order they sign of the implementation. 

Symptom: If the customer is disastisfied with the application at demonstration time, then at least the one of the acceptance test is broken. Add one in the next sprint.

SOLID A set of five principles:Single Responsibility, Open-Closed, Liskov Substitution, Interface Segregation and Dependency Inversion.
Single Responsibility Principle An object class, a service bean, web service, a function or procedure should have only one single responsibilitySymptom: It is hard to write unit test for complex object, because it doing WETTT
Open Closed Principle Open for extension and closed for modificationIt means you can subclass the object, but the object is encapsulated by not allowing an outside object to gainfully change the internals. 

Symptom: leakage in object implementation, hard code dependency, and not working with Java interfaces (or interface like constructs i.e. Scala traits and mix-ins)

Liskov Substitution Principle Idea of swap-ability and is expressed as a Design By Contract (DBC).I can swap in another object X which is an implementation of T if that objects is a type of T and the overall application works.This is the basis of mocking objects, mocking implementation frameworks; testing in general; proxy remote objects, persistence capable objects; application server and lifecycle monitoring situations; plug-and-play and restartable applications. I could go on, but I won’t.
Interface Segregation Principle A service interface that does only single specific functional thing is better than a service interface that does several different things. 

Symptom: Failure to adhere to the KISS principle. In days gone, the non standard C++ String libraries where everybody threw in the kitchen sink of methods for any operation that one would want to write that manipulated a C/C++ String (char*)

Dependency Inversion Principle Idea of not hard-wiring a direct relationship to a dependent into object.In Java EE world, you would use a dependency injection container such as CDI to inject different managed beans into a service bean. 

Dependency inversion also should mean in my humble opinion given up on managing the life-cycle of service components and beans. The lifecycle is managed by the application container, the cloud provider or whatever it is you are using.

 

In another school of thought: every application is managed these days, whether it is the operating system, a virtual machine or web container or mobile platform (iOS and Android). This is the way forward.

Design Patterns A classic book on Design Patterns by Erich Gamma et Al. 

Ask your local technical leader to lend you his or her copy of the book; and if they don’t have a copy then that really sucks. Tell them to give you a personal training budget and buy the book yourself!

Glad to be of service to all my readers.

Merry Xmas and Happy New Year 2013!

+PP+

PS: I, once, had a notebook and file with a lot more of these terms with or without explanations. If I find anymore abbreviations and terms that I will add to this blog entry.

NightHacking Tour with Stephen Chin

November 20th, 2012 Comments off

On Monday 19th November 2012, in the evening, I interviewed for the final episode of the Nighthacking tour by Stephen Chin, who is an Oracle Evangelist for Java, Chairperson of the JavaOne Program committee, and also a Java Champion a.k.a @steveonjava.

We talked about ScalaFX the open source Domain Specific Language and Scala library framework for JavaFX 2.x. I showed off my version of the JavaOne 2011 demo in Scala. It is called VideoCubeDemo.scala. We actually started to fix a bug in the demo. We checked into version control a quick fix that helped and pushed that to Mercurial.

I also talked about my upcoming reference book for JavaEE 7, which will be published by Packt. I demonstrated some of the example Context Dependency & Injection code that will feature in the book. I showed off JBoss WeldDeltaSpike and Arquillian framework. We discussed some of the other upcoming features of Java EE7 like JAX RS and WebSockets; and also how CDI could be used outside the container in a JavaFX application.

Many thanks to SkillsMatter for hosting us, in particular Wendy Devolder and Nick Devolder; and extra special medal goes to Ami Partridge for being very helpful, staying late into the evening to help us get this live stream out to the public with wired ethernet cables, router boxes, WI-FI and tea.



Video streaming by Ustream

Hosted by Skills Matter, the company behind the Scala Exchange and Grails Exchange.


SkillsMatter 2012

 

+PP+

Silicon Valley Code Camp 2012

October 16th, 2012 Comments off

After the exertions of JavaOne 2012, I was very glad of the relative warmth, wide-range green, autumn plucky country-side feel of Los Altos Hill. On Saturday, 6th October and partially Sunday 7th I was down at Foot Hill College for another dose of the Silicon Valley Code Camp.

For people in Silicon Valley, a weekend after JavaOne, and for a free event, this is training and education that is most affordable. The companies sponsoring SVCC including Microsoft, Box, Dice.com and others make it all possible.

 

DSCF4158
This is Peter Kellner being the Master of Cerenomies and reading the raffle-ticket winners

 

DSCF4152
This photos was taken during the speaker’s dinner late Saturday evening. Van Riper [R] and Kevin Nilson [L] organisers of the Valley Java User Group

 

DSCF4161
Wider focus view to the Foot Hills Campus, which is very well equipped for IT education, I thought.

 

 

DSCF4162 Another stunning view and memory of SVCC. What you cannot see is that the whole college on undergoing reconstruction, there are building works, trucks, pile heaps all around the campus as it is revamped.

 

DSCF4151
Saturday lunchtime. For October, it was rather warm during the day, the atmosphere definitely collegiate, relax and friendly. It was rather cold during the evening, bring a jacket and layers after 6pm!

 

DSCF4176
One lucky raffle-ticket proudly takes and loft over his head the XBox Console that he just won at the SVCC 2012! Am I regretful that I stopped running the JAVAWUG? In those moment like that one was, the easy answer is yes, because to see the joy of accomplishing something just by attending is priceless. However, an SVCC event is unlikely come to the UK any time soon, because we Brits need to adopt that Californian attitude of “What’s the worse thing that could possibly happen?”

 

I was very happy with the turnout for my talk on Saturday: Leveraging Java EE7 and the Cloud with the JavaFX, Room 4305. In the end, I talked for 35 minutes, and the rest was demonstrating JavaFX 2 to the attendees. A smaller audience than JavaOne, but nevertheless they appear attentive and appreciative.

The follow day, I bumped, into Dave Nielsen, of CloudCamp fame, whilst he was given an interesting talk about cloud computing. My ideas about PaaS being standardised next year, were way off, I learnt. There is so much disruption and innovating in Cloud, in his opinion, Dave Nielsen, reckons standardisation is more like two years into the future. Dave Nielsen is one of the member organiser of the OASIS CAMP, an effort to standardise cloud services.

 

DSCF4141
Microsoft brought there own XBox black Mustang muscle car, polycarbonate trim and folds, custom modifications were fitted by the infamous West-Coast Customs, yet another “Pimp My Ride” production. This particular car had a digital LCD dashboard, two screens, it was coupled with a Nokia smartphone app with the ability to remote start (disabled), a projector was installed into the boot and also featured two separate XBox console complete with controllers. Of course, the boombox sound was out of this world.

 

DSCF4146
Code Camp #svcc2012

 

IMG_1288
I started reading Joshua D. Sureth’s Scala in Depth book, which was the only book that I bought during JavaOne 2012. I used to buy lots in previous years, too much to read in so little time. Now I restrict myself to one, if any.

 

+PP+

Silicon Valley Code Camp 2012

October 8th, 2012 Comments off

The Silicon Valley Code Camp is a free event organised Peter Kellner and others every year in October. The SVCC talkes place at Foot Hill College, Los Altos Hills, California. It is now in its seventh edition, which in my opinion extraordinary.

This years unofficial attendance was about 3800 participants, over range of technologies. It is not just a Java conference, the SVCC embraces native programming languages like C++; web development through JavaScript and Dart; the JVM platform with  Java, Scala and Groovy;  Microsoft technologies, Silverlight, C# and DotNet; and non-development sessions such how to find start-up funds, cloud computing and even how to recruit the best team in the valley.

What astounds me is that this is all available free to attendees, the sponsors pay the hosting, hiring and the obviously for food and beverages. This is training and education for free, albeit the speakers are not trained professional educators, but mostly from my witness, they do know what they are talking. To submit a talk here, you just volunteer your services. It is a decision, can I make the time and effort to lecture or speak about a topic that is interesting for attendees? If you can do that, then it is good chance to change the world. After all, it is the learning experience, in my opinion, it is chance I feel to give back something to community that somebody gave in the past to me.

Here are my slides to my talk Leveraging Java EE 7 and the Cloud with JavaFX, which took place on Saturday 6th October at 3pm

The attendance was smaller than JavaOne, but I am not disappointed in that at all, the smaller the audience size, the more intimate it is, the chance to get to know and ask questions about the developers. Why they like Java? What are they hoping to achieve? From these question, I was able to tailor the presentation slightly to be more about JavaFX than JavaEE.

Java EE 7 is now repositioned from Moving to the Cloud to HTML5 Web Sockets and RESTful services. It is draft specification and you can download the latest document from the JCP.org under JSR 342, which probably needs an update.

I met several members of the community including:

  • Van Riper
  • Kevin Nilson
  • Andres Almaray
  • Ixchel Almaray
  • Csaba Toth
  • Chris Richardson
  • Peter Niederwiesen
  • Dave Nielsen

 

+PP+

TUT5466 – JavaFX 2: A Java Developer’s Guide

October 2nd, 2012 Comments off

TUT5466 – JavaFX 2: A Java Developer’s Guide

Peter Pilgrim – Developer Consultant, Independent Contractor
Stephen Chin – Java Evangelist, Oracle

Tuesday, Oct 2, 12:30 PM – 2:30 PM – Hilton San Francisco – Continental Ballroom 1/2/3

Source Code is here temporarily

Build it with Gradle

A Note to self

task myZip(type: Zip) {
 from '.'
 into "${archivesBaseName}-${version}"
// into 'javafx-developer-guide-J1-2012'
 include 'src/**'
 include '*.xml'
 include '*.gradle'
 include '*.txt'
 exclude {
 details ->
 details.file.name.equals('.gradle')
 }
}

Building ScalaFX 1.0 with Gradle 1.1

August 28th, 2012 2 comments

After becoming a little disenchanted with the SBT for Scala, I wanted an alternative that was more logical, simpler to understand and had a better user experience. After all, the whole point of a domain specific language is to make the writing of the script, formulae or grammar to be affordable to the users. A DSL must be comprehensible to the users, it must be relatively easy to write the script in the language of the domain, and surely must be mostly free of annoyances. The great examples of course are spreadsheets like Excel, the XML Stylesheet Language for Transformations (XSLT) and shell scripts (like DOS, BASH).

I recently added a build.grade file to the ScalaFX project. Here is a screen cast about how to use Gradle build instead of the current SBT file.

Building ScalaFX 1.0 with Gradle 1.1 from Peter Pilgrim on Vimeo.

The only sore point so far, I have found with Gradle, is that the project takes it name from the containing folder. In other words, I found that force setting the artifactId does not work.

group = 'org.scalafx'
artifactId = 'ScalaFX-javaone-2012'  // This does not work
version = '1.0-SNAPSHOT'

That might be worth considering when moving project folders around in order to make a quick research branch for a delta, or look at some other committer’s changes separately from your own.

Because Gradle is written in Groovy, you have the full power of that dynamic language to play with. I was able to write a groovy task to push a UNIX bash launcher script in less than ten minutes. I was also able to run a launcher within Gradle for the Colorful Circles demo app. The Gradle documentation is a lot better than SBT, in my humble opinion.

In SBT, if you missed adding a single blank line between statement declarations, or you forgot to add an extra delimiter between to Seq() or perhaps used the wrong method name “+” versus “++” then you could be lost for quite a long time.

It would good to see how the Scala Plugin for Gradle could work with recently announced Zinc and Incremental Compilation from Typesafe. After reading that blog post, I think Zinc, Gradle and Scala plug-in should just work. Has anyone tried this combination yet? I have not yet.

PS: Under Windows, you need to comment out the “chmod” line in the build.gradle for now. I will fix this later on before the 1.0 release.

PS PS: With the Vimeo, you might prefer to click on the HD option to see improved clarity.

+PP+

Ubuntu ActiveMQ Initialisation Scripts

March 30th, 2012 Comments off

Recently, I have been working with Ubuntu in a Virtual Box VM and setting up ActiveMQ for testing. I wanted to create a VM with an already running ActiveMQ as a service, whenever I started it. In order to do this, I set up ActiveMQ as a Linux intialisation service. I installed ActiveMQ first by following the very helpful blog entry here, which was a little out of date. It only explained how to create an ActiveMQ Init.d if you have Sys V Linux/Unix machine. So I went about customising the information for a Ubuntu machine, and the results are now here. Here are my scripts, the first is located at /home/activemq/activemqstart.sh. This script launches the service and is  owned by the Linux user activemq.

</pre>
#!/bin/bash # Start ActiveMQ if [ ! -f ${HOME}/activemq.env ]; then echo "Cannot read activemq.env" 1>&2; exit 99 fi . ${HOME}/activemq.env ${ACTIVEMQ_HOME}/bin/activemq start # fini
<pre>

Here is the script file /home/activemq/activemqstatus.sh, which shows the administrator the status of the service.

</pre>
#!/bin/bash # Probe ActiveMQ if [ ! -f ${HOME}/activemq.env ]; then echo "Cannot read activemq.env" 1>&2; exit 99 fi . ${HOME}/activemq.env ${ACTIVEMQ_HOME}/bin/activemq status # fini
<pre>

Here is the script file /home/activemq/activemqstop.sh, which allows the administrator to halt the service.

</pre>
#!/bin/bash # Stop ActiveMQ if [ ! -f ${HOME}/activemq.env ]; then echo "Cannot read activemq.env" 1>&2; exit 99 fi . ${HOME}/activemq.env ${ACTIVEMQ_HOME}/bin/activemq stop # fini
<pre>

Here is the environmental set-up script /home/activemq/activemq.env. Of course, if you wanted to, you could put this configuration elsewhere like in a .bashrc script. For my purposes, I wanted to refactor out the location of both components.

</pre>
: ${JAVA_HOME:=/usr/lib/jvm/java-6-sun-1.6.0.31} : ${JDK_HOME:=/usr/lib/jvm/java-6-sun-1.6.0.31} : ${ACTIVEMQ_HOME:=/opt/apache-activemq}
<pre>

Here is a version of ActiveMQ control script in /etc/init.d/activemq, which owned by the superuser root.

#!/bin/bash
#
# activemq       Starts ActiveMQ.
#
#
### BEGIN INIT INFO
# Provides:          activemq
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     1 2 3 4 5
# Default-Stop:      0 1 2 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by Apache Active MQ.
### END INIT INFO

# Source function library.
## . /etc/init.d/functions

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

[ -f /home/activemq/activemqstart.sh ] || exit 0
[ -f /home/activemq/activemqstop.sh ] || exit 0
[ -f /home/activemq/activemqstatus.sh ] || exit 0

RETVAL=0

umask 077

start() {
       echo -n $"Starting ActiveMQ: "
       su -c /home/activemq/activemqstart.sh activemq
       echo
       return $RETVAL
}
stop() {
       echo -n $"Shutting down ActiveMQ: "
       su -c /home/activemq/activemqstop.sh activemq
       echo
       return $RETVAL
}
status() {
       echo -n $"Probing status of ActiveMQ: "
       su -c /home/activemq/activemqstatus.sh activemq
       echo
       return $RETVAL
}
restart() {
       stop
       start
}
case "$1" in
 start)
       start
       ;;
 stop)
       stop
       ;;
 restart|reload)
       restart
       ;;
 status|probe)
        status
        ;;
 *)
       echo $"Usage: $0 {start|stop|restart|status|probe}"
       exit 1
esac

exit $?
# Fini

I will assume that you are familiar with creating Linux users and setting file owner and group permissions. Finally, I installed the new service with this following command:

sudo update-rc.d activemq start 20 1 2 3 4 5 . stop 80 0 1 2 6 .

This command installs the service for single-user, multi-user, network configured and display configured run-levels. HTH. Al Coda. ;-)

Categories: Administration, Education, Linux, Script, Ubuntu Tags:

QCon London 2012 Philip Wadler Answers “What is a Monad?”

March 9th, 2012 Comments off

Today, I am at the final day of the QCon London 2012 conference in partuculary in the Scala and Functional Languages track.

Philip Wadler gave an excellent presentation on functional programming and his belief about lambda calculas, mathematical formal logic and an advanced computer science. At the end of his talk, there was a lot of people who stayed behind for question answers. Of course, one of the audience members asked the proverbial question: “What is a Monad?”

Here is Professor Wadler, University of Edinburgh, best distinguished answer to this question?

e a

Stayed tuned for a full report on QCon London 2012 ;-)