Programming Blogs

Ubuntu 11.10 (Oneiric Ocelot) Linux distro Released

Ubuntu Computing - Mon, 02/20/2012 - 08:31
"There is nothing like a dream to create the future." - Victor Hugo

The Ubuntu team is pleased to announce Ubuntu 11.10, code-named "Oneiric Ocelot". 11.10 continues Ubuntu's proud tradition of integrating the latest and greatest open source technologies into a high-quality, easy-to-use Linux distribution.

For PC users, Ubuntu 11.10 supports laptops, desktops and netbooks with a unified look and feel based on an updated version of the desktop shell called "Unity", which introduces specialized "Lenses". Finding and installing software using the Ubuntu Software Centre is now easier thanks to improvements in speed, search functionality enhancements, and usability improvements. Aside from updates on the performance side, it's also more aesthetically appealing.

Ubuntu Server 11.10 has made it much easier to provision, deploy, host, manage, and orchestrate enterprise data centre infrastructure  services with the introduction of "Orchestra".  The Juju technical preview allows service developers to describe the deployment and  scaling requirements of their applications, in order to simplify  and enhance the dialogue between developers and operations teams. For those working on the ARM architecture, a technical preview is  also provided for the ARM server.

Read more about the new features of Ubuntu 11.10 in the following press releases:

  http://www.canonical.com/content/transforming-home-pc-ubuntu-1110
  http://www.canonical.com/content/client-cloud-ubuntu-1110-sets-pace-business-it


Standard maintenance updates will be provided for Ubuntu 11.10 for  18 months, through April 2013.

Thanks to the efforts of the global translation community, Ubuntu is now available in 38 languages.  For a list of available languages  and detailed translation statistics for these and other languages, see:

  http://people.canonical.com/~dpm/stats/ubuntu-11.10-translation-stats.html


Ubuntu 11.10 is the base for the newest 11.10 iterations of Kubuntu, Xubuntu, Edubuntu, Mythbuntu, Ubuntu Studio, and our newest addition  to this release cycle, Lubuntu!

Kubuntu:       http://kubuntu.org/news/11.10-release
Xubuntu:       http://xubuntu.org/news/11.10-release
Edubuntu       http://edubuntu.org/news/11.10-release
Mythbuntu:     http://mythbuntu.org/11.10/release
Ubuntu Studio: https://wiki.ubuntu.com/UbuntuStudio/11.10release_notes
Lubuntu:       https://wiki.ubuntu.com/Lubuntu/Announcement/11.10


Ubuntu 11.10 is also now available on two new ARM community-supported ports.
AC100 (Toshiba Tegra 2 Netbook): https://wiki.ubuntu.com/ARM/TEGRA/AC100
MX5
(Freescale i.MX53 QuickStart): https://wiki.ubuntu.com/ARM/MX5


To get Ubuntu 11.10

In order to download Ubuntu 11.10, visit:

 http://www.ubuntu.com/download/ubuntu/download


Users of Ubuntu 11.04 will be offered an automatic upgrade to 11.10 via Update Manager. For further information about upgrading, see:

 http://www.ubuntu.com/download/ubuntu/upgrade


As always, upgrades to the latest version of Ubuntu are entirely free of charge.

We recommend that all users read the release notes, which document caveats, workarounds for known issues, as well as more in-depth notes on the release itself. They are available at:

 http://www.ubuntu.com/getubuntu/releasenotes


Find out what's new in this release with a graphical overview:

 http://www.ubuntu.com/ubuntu/whats-new
 http://www.ubuntu.com/ubuntu/features


If you have a question, or if you think you may have found a bug but aren't sure, you can try asking in any of the following places:

 #ubuntu on irc.freenode.net
 http://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 http://www.ubuntuforums.org/
 http://askubuntu.com/


Help Shape Ubuntu

If you would like to help shape Ubuntu, take a look at the list of ways you can participate at:

 http://www.ubuntu.com/community/participate/


About Ubuntu

Ubuntu is a full-featured Linux distribution for desktops, laptops, netbooks and servers, with a fast and easy installation and regular releases.  A tightly-integrated selection of excellent applications is included, and an incredible variety of add-on software is just a  few clicks away.

Professional services including support are available from Canonical and hundreds of other companies around the world.  For more information about support, visit:

 http://www.ubuntu.com/support

Kate Stewart,
on behalf of the Ubuntu Release Team

More Information

You can learn more about Ubuntu in Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition) !

Categories: Programming Blogs

Ubuntu 11.04 "Natty Narwhal" Linux OS Released

Ubuntu Computing - Mon, 02/20/2012 - 08:31
"Form and function are a unity, two sides of one coin. In order to enhance function, appropriate form must exist or be created."
   -Ida P. Rolf
The Ubuntu team is pleased to announce Ubuntu 11.04, code-named "Natty Narwhal". 11.04 continues Ubuntu's proud tradition of integrating the latest and greatest open source technologies into a high-quality, easy-to-use Linux distribution.

To learn more about Ubuntu, check out Beginning Ubuntu Linux book from Apress.

For PC users, Ubuntu 11.04 supports laptops, desktops and netbooks with a unified look and feel based on a new desktop shell called "Unity". This version supersedes Ubuntu Netbook Edition for all PC netbooks.

Developer reference images are provided for select Texas Instruments (TI) ARM platforms, specifically the "PandaBoard" and "BeagleBoard".

Ubuntu Server 11.04 has made it easier to provision servers, and reduce power consumption.   Ubuntu Server 11.04 for UEC and EC2 has a new kernel and improved initialization and configuration options.

Read more about the features of Ubuntu 11.04 in the following press releases:

 http://www.canonical.com/content/ubuntu-transforms-your-pc-experience
 http://www.canonical.com/content/latest-ubuntu-offers-business-added-cloud-features-and-sleek-new-desktop-interface

 Standard maintenance updates will be provided for Ubuntu 11.04 for 18 months, through October 2012.

Thanks to the efforts of the global translation community, Ubuntu is available in 43 languages.  For a list of available languages and detailed translation statistics for these and other languages, see:

 http://people.canonical.com/~dpm/stats/ubuntu-11.04-translation-stats.html

Ubuntu 11.04 is also the basis for new 11.04 releases of Kubuntu, Xubuntu, Edubuntu, UbuntuStudio, and Mythbuntu:

       Kubuntu  http://kubuntu.org/news/11.04-release
       Xubuntu  http://xubuntu.org/news/11.04-release
      Edubuntu  http://edubuntu.org/news/11.04-release
     Mythbuntu  http://mythbuntu.org/11.04/release
 Ubuntu Studio  https://wiki.ubuntu.com/UbuntuStudio/11.04release_notes

To Get Ubuntu 11.04

To download Ubuntu 11.04, or obtain CDs, visit:

 http://www.ubuntu.com/download/ubuntu/download

Users of Ubuntu 10.10 will be offered an automatic upgrade to 11.04 via Update Manager. For further information about upgrading, see:

 http://www.ubuntu.com/download/ubuntu/upgrade

As always, upgrades to the latest version of Ubuntu are entirely free of charge.

We recommend that all users read the release notes, which document caveats and workarounds for known issues.  They are available at:

 http://www.ubuntu.com/getubuntu/releasenotes

 Find out what's new in this release with a graphical overview:

 http://www.ubuntu.com/ubuntu/whats-new
 http://www.ubuntu.com/ubuntu/features

If you have a question, or if you think you may have found a bug but aren't sure, you can try asking in any of the following places:

 #ubuntu on irc.freenode.net
 http://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 http://www.ubuntuforums.org/
 http://askubuntu.com/


Helping Shape Ubuntu

If you would like to help shape Ubuntu, take a look at the list of ways you can participate at:

 http://www.ubuntu.com/community/participate/


About Ubuntu

Ubuntu is a full-featured Linux distribution for desktops, laptops, netbooks and servers, with a fast and easy installation and regular releases.  A tightly-integrated selection of excellent applications is included, and an incredible variety of add-on software is just a few clicks away.

Professional services including support are available from Canonical and hundreds of other companies around the world.  For more information about support, visit:

 http://www.ubuntu.com/support

More Information

To learn more about Ubuntu, check out Beginning Ubuntu Linux book from Apress.

You can find out more about Ubuntu and about this release on our website:

 http://www.ubuntu.com/

To sign up for future Ubuntu announcements, please subscribe to Ubuntu's very low volume announcement list at:

 http://lists.ubuntu.com/mailman/listinfo/ubuntu-announce/


Kate Stewart,
on behalf of the Ubuntu Release Team

(copied mostly verbatim from Ubuntu announcement)

Categories: Programming Blogs

Ubuntu 10.10 Maverick Meerkat Has Been Released - See What's New In Both Desktop And Netbook Editions [WebUpd8]

Ubuntu Computing - Mon, 02/20/2012 - 08:31

Ubuntu 10.10 Maverick Meerkat final has just been released. I'm taking this opportunity to review the major changes (mostly on the UI) in both Ubuntu 10.10 Desktop and Netbook editions. If you're a regular WebUpd8 reader, you should already know all these changes but even so, read on for a new Unity video (recorded today) as well as a recap of the changes to Ubuntu Software Center, Unity and so on. 

Please note that as usual, the Netbook Edition video and screenshots have been taken on my desktop - that's because I personally do not like Unity and prefer my own netbook setup, but it has nothing to do with the Unity performance (which by the way works great now).


Ubuntu 10.10 Maverick Meerkat Desktop Edition Ubuntu Software Center Ubuntu Software Center has got a lot of changes in Ubuntu 10.10 Maverick Meerkat:

- A new look:


In the above screenshot you can also spot the "What's new" category which will hold new applications (application which are not available in the Ubuntu 10.10 official repositories at the Ubuntu 10.10 release date but are made available later on).

- A history tab shows what applications you've installed, removed or upgraded, day by day:

- A feature called "Where is it" displays the menu entry where you can find the newly installed applications. Also, for applications which have some plugins available, these are displayed below the application in the Ubuntu Software Center:

- The first paid application is available in Ubuntu Software Center in Ubuntu 10.10:

Yes, only one application for now - for testing purposes, but more are expected starting with Ubuntu 11.04 Natty Narwhal.

- Ubuntu Software Center now also handles .deb file installation (so when you double click a .deb file, it opens in Ubuntu Software Center).

Sound menu
Ubuntu 10.10 Maverick Meerkat comes with a new sound menu which by default displays the currently playing song in Rhythmbox, the album art (if the respective plugin has been enabled in Rhythmbox) and controls for previews / next tracks as well as play / pause. Other music players will be able to take advantage of this new Sound Menu, like Banshee (already available through an extension), Amarok and so on.

Ubuntu Font Familiy as the default desktop font
The Ubuntu Font Family, which has been in private beta for almost the whole Ubuntu 10.10 development has been made the default desktop font. The font is default for Application, Window title, and Desktop only and the size has been set to 11.

This change should be available in all the Ubuntu flavors: from Ubuntu 10.10 Netbook Edition to Kubuntu and so on.

F-Spot out, Shotwell in
F-Spot photo manager has been replaced in Ubuntu 10.10 Maverick Meerkat with Shotwell. Among Shotwell's features are tags and ratings support, basic editing like cropping, red-eye and color adjustments and publishing images to Facebook, Flickr and PicasaWeb.


Ubuntu One Ubuntu One has got lots of improvements, most under the hood, but there's one in particular that is worth mentioning: you can now stream music to your Android or iPhone. The applications for Andoid and iPhone are currently not available (they are in beta), but here is a screenshot thanks to Lifehacker:


Light Themes (Ambiance and Radiance) There weren't major changes to the Ubuntu "Light" themes, but they did get some further polishing. Futher more, Radiance has been tweaked to look like it was initially intended: a lighter version of Ambiance, not a separate theme.


(Ambiance - the default Ubuntu 10.10 theme)



Radiance

Wallpapers Like with every new Ubuntu release, Maverick Meerkat too got a new default wallpaper:

And of course, new community wallpapers:


Revamped installer

The Ubuntu installer got a new look, new slideshow and along with these, some new features:

- It can now install mp3 playback support so you can have that from your first Ubuntu login. You'll need a working internet connection for that though:

- Once you select the partition where you want to install Ubuntu, the formating and installation begins. So the installation takes place while you complete the rest of the process like selecting your location or entering your password thus the time required to install Ubuntu has decreased by simply changing the order installer steps order:

Here is a video (1 week old, but everything is the same in the final release) with the whole Ubuntu 10.10 Maverick Meerkat installation process I've recorded:


Ubuntu 10.10 Maverick Meerkat Netbook Edition (Unity) For Ubuntu 10.10 Maverick Meerkat Netbook Edition, everything is new compared to 10.04. Unity has replace the old Netbook interface and along with it, there are some other features designed to improve the usability on a netbook.

Unity comes with a launcher on the left side of the screen - it allows you to pin applications and it comes with some applets by default like a trash applet and a workspace switcher applet. It also has 2 quick access applets for the applications and files views (called Dash):



(Unity launcher)



(Unity - workspaces)



(Unity - applications pane)



(Unity - files pane (Dash))

The files and applications pane use Zeitgeist for displaying the recently used and most used items. The files are organized by type and date they were last accessed (as you can see in the screenshot above).

Clicking the Ubuntu logo in the top left corner will open the main application categories:

Ubuntu 10.10 Netbook Edition also comes with an Applications Menu - the applications menu is now displayed on the top panel (which by the way does not support any kind of customization, you can't remove or add applets - and it's not like in 10.04 when the panel was locked, now the panel itself doesn't support any customizations) and is not displayed in the actual applications anymore (Mac OSX style):

This however does not work for some applications like Firefox, Thunderbird, OpenOffice and so on.

Also, the maximize applications titlebar is automatically removed and the window title along with the close, minimize and maximize buttons are also displayed on the top panel:

All these are designed to provide more vertical space for netbooks.


You can't really get an idea on what Unity is from the screenshots, so I've recoded a video with Ubuntu Netbook Edition 10.10 Maverick Meerkat final:


(Video available in HTML 5 if you've enabled it on YouTube - watch it in HD!)


Multi touch out of the box
If you have a multi-touch capable device, expect an out-of-the-box touch experience that "just works" on Ubuntu 10.10 Maverick Meerkat. This is installed by default in Ubuntu 10.10 Maverick Meerkat Netbook Edition but you can install it on the desktop edition too (sudo apt-get install utouch).

Here is an old video (sorry, I don't have a multi-touch device to record a video myself) with this amazing feature - for an application which doesn't support multi-touch by default (Inkscape):


And of course, there are new versions for each application like Evolution 2.30.3 (even though Ubuntu 10.10 ships with GNOME 2.32.0), OpenOffice 3.2.1, Empathy 2.32.0 (with metacontacts), Gwibber 2.32.0.1 (with OAuth support for Twitter), PiTiVi (video editor) 0.13.5, Brasero 2.32.0 and so on. One note: Ubuntu 10.10 Maverick Meerkat has been released with Firefox 3.6 so we might not see an official way of installing Firefox 4.0 in this release.


Please note that there have been many more changes but I've only covered the most important ones or the changes I personally enjoy most in Ubuntu 10.10 Maverick Meerkat. For the whole thing, install Ubuntu 10.10 Maverick Meerkat yourself.

Download Ubuntu 10.10 Maverick Meerkat (or any 10.10 Ubuntu flavor)


Now, let's hear something from you too: did you upgrade to Maverick (Desktop / Netbook / Kubuntu or any other flavor)? And if so, how is everything working for you?

And that was it, we've covered it all. Well, almost. From the early Meerkat alpha to the final 10.10 (.10) version. If you want to follow the next Ubuntu version development (11.04 Natty Narwhal), do not forget to subscribe: RSS | Twitter | Facebook. More options in the top menu.
Source: http://www.webupd8.org/2010/10/ubuntu-1010-maverick-meerkat-has-been.html

Categories: Programming Blogs

Linux Mint 11 "Katya" Ubuntu-based OS released

Ubuntu Computing - Mon, 02/20/2012 - 08:31

The Linux Mint development team has announced the release of version 11 of Linux Mint – the project's latest major release of its Ubuntu-based Linux distribution. Code-named "Katya", Linux Mint 11 is based on Ubuntu 11.04 "Natty Narwhal" and includes the 2.6.38 Linux kernelLinux 2.6.39 was released one week ago.

I highly recommend Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition) for learning more about Linux Mint and Ubuntu.

Unlike the latest version of Ubuntu upon which it is based, the distribution features the GNOME 2.32 desktop environment, as well as the traditional Linux Mint desktop layout – Ubuntu uses Unity, developed in-house by the Ubuntu developers, as its default desktop. In an email, Linux Mint Founder and lead developer Clement Lefebvre previously told The H that the developers initially wanted to use GNOME 3, however, "With GNOME 2 we could rely on one of the most stable desktops available, full compatibility with GTK (on which most applications including our own tools are developed) and our current themes."


Linux Mint 11 features the GNOME 2.32 desktop environment, as well as the traditional Linux Mint desktop layout.

Other changes include a faster update manager with several user interface improvements, updates to the desktop settings tool, and a "much more polished" software manager. Software selection updates include replacing OpenOffice.org with the LibreOffice office suite, Banshee becoming the default music player and gThumb replacing F-Spot as the default photo application – Gwibber is no longer being installed by default.

Highlights of Linux Mint 11 :

  • Based on Ubuntu 11.04
  • Linux kernel 2.6.38
  • No Unity shell
  • GNOME 2.32.1
  • One-click installer for multimedia codecs and extra apps
  • Lots of improvements to The Software Manager tool
  • Performance improvements to The Update Manager tool
  • Various improvements to The Desktop Settings tool
  • A new set of wallpapers
  • mint-search-addon for Firefox 4, Chrome and Opera web browsers
  • Removed Gwibber
  • gThumb as default photo viewer
  • Banshee as default music player
  • LibreOffice 3.3 office suite
  • Overlay scrollbars
  • Updated Mint-X theme
  • Added 'apt download' command
  • Adobe Flash Player 10.2 plugin
  • Lots of bug fixes

More details about the release, including a list of known problems, can be found in a post on the Linux Mint Blog, in the release notes and on the New features in Linux Mint 11 page. Linux Mint 11 is available to download as a CD or DVD ISO image file for 32- and 64-bit systems from the project's site. A user guide and upgrade instructions are provided. The OEM Edition provides the same features as the standard version, but without including proprietary software, patented technologies or support for restricted formats.

Linux Mint aims to be user friendly and to provide a more complete out-of-the-box experience by including support for DVD playback, Java, plug-ins and various media codecs. It is currently the second most popular distribution on DistroWatch.com behind Ubuntu.

To learn more about Linux Mint and Ubuntu, the book Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition) is highly recommended.

(Article copied mostly verbatim from H Online announcement.)

Categories: Programming Blogs

Puppet Module for JBoss AS 7.1 "Thunder"

Spring vs Java EE Web Development - Fri, 02/17/2012 - 10:46

We at Bippo Indonesia and Soluvas love JBoss AS. Especially with the shiny new release 7.1.0.Final aka "Thunder".

And we love DevOps with Puppet too!

As the least contribution we could provide, our Puppet Module for JBoss AS on GitHub is available as an open source project.

It's currently a work in progress, but as time goes we hope to make it flexible with Puppet's parameterized class feature and hopefully able to do deploy/redeploy/undeploy operations, change logging features, user management, etc. Especially that JBoss has an excellent CLI tool, we hope the integration with Puppet will be relatively easy.

Thank you JBoss!


Reblogged from https://community.jboss.org/blogs/beyondjavaee/2012/02/16/puppet-module-for-jboss-as-71-thunder

Categories: Programming Blogs

UnproxyableResolutionException Workaround when using Scala Closures and javax.inject CDI Beans Together

Some powerful Scala programming language features like closures, pattern matching, and lazy vals don't work well with dependency injection frameworks like javax.inject aka CDI. This is due to stricter class structure requirements to enable proxying.

For example, this "innocent" code will not work:

  @Inject private var fbPhotoImporterFactory: Instance[FacebookPhotoImporter] = _
  @Produces @Named("facebookPhotoImporter") private var fbPhotoImporter: ActorRef = _

  @PostConstruct
  def init() {
    logger.debug("Starting FacebookPhotoImporter actor")
    fbPhotoImporter = Actor.actorOf(fbPhotoImporterFactory.get())
    fbPhotoImporter.start()
  }

It will throw:

Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001437 Normal scoped bean class com.satukancinta.web.Persistence is not proxyable because the type is final or it contains a final method public final javax.enterprise.inject.Instance com.satukancinta.web.Persistence.com$satukancinta$web$Persistence$$fbPhotoImporterFactory() - Managed Bean [class com.satukancinta.web.Persistence] with qualifiers [@Any @Default].
    at org.jboss.weld.util.Proxies.getUnproxyableClassException(Proxies.java:225)
    at org.jboss.weld.util.Proxies.getUnproxyableTypeException(Proxies.java:178)
    at org.jboss.weld.util.Proxies.getUnproxyableTypesExceptionInt(Proxies.java:193)
    at org.jboss.weld.util.Proxies.getUnproxyableTypesException(Proxies.java:167)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:110)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:126)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:345)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:330)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82)
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)
    ... 5 more

As you can see, my use code isn't exactly "edge cases".

It's actually a pretty common use case: create a Akka actor and pass a factory function to it, as a closure.
The code above doesn't look like it's using a closure, but it actually is when written like this: (same functionality, but still breaks CDI)

    fbPhotoImporter = Actor.actorOf { fbPhotoImporterFactory.get() }

I can see why CDI has a strict requirement, and I can also understand why Scala implements it the way it is (Scala developers definitely already has a lot of problems working around powerful Scala features into a very restrictive JVM bytecode requirements). This is the price we pay for having a somewhat inferior language (Java, please don't get offended) in the first place.

But I as an application developer want to have a quick fix for this issue. Re-coding the class in plain Java is one option, but it turns I don't need to. There is a workaround, by creating a helper method then using it:

  @Inject private var fbPhotoImporterFactory: Instance[FacebookPhotoImporter] = _
  @Produces @Named("facebookPhotoImporter") private var fbPhotoImporter: ActorRef = _
 
  def createFbPhotoImporter() = fbPhotoImporterFactory.get()
 
  @PostConstruct
  def init() {
    logger.debug("Starting FacebookPhotoImporter actor")
    fbPhotoImporter = Actor.actorOf(createFbPhotoImporter)
    fbPhotoImporter.start()
  }

Now Scala is happy and CDI is also happy. Yes it's a bit more verbose but not too bad. And I guess the code is now somewhat more understandable for Java guys. :)

Tip: To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.

Categories: Programming Blogs

UnproxyableResolutionException Workaround when using Scala Closures and javax.inject CDI Beans Together

Spring vs Java EE Web Development - Wed, 02/15/2012 - 23:49
Some powerful Scala programming language features like closures, pattern matching, and lazy vals don't work well with dependency injection frameworks like javax.inject aka CDI. This is due to stricter class structure requirements to enable proxying.

For example, this "innocent" code will not work:

  @Inject private var fbPhotoImporterFactory: Instance[FacebookPhotoImporter] = _
  @Produces @Named("facebookPhotoImporter") private var fbPhotoImporter: ActorRef = _

  @PostConstruct
  def init() {
    logger.debug("Starting FacebookPhotoImporter actor")
    fbPhotoImporter = Actor.actorOf(fbPhotoImporterFactory.get())
    fbPhotoImporter.start()
  }

It will throw:

Caused by: org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001437 Normal scoped bean class com.satukancinta.web.Persistence is not proxyable because the type is final or it contains a final method public final javax.enterprise.inject.Instance com.satukancinta.web.Persistence.com$satukancinta$web$Persistence$$fbPhotoImporterFactory() - Managed Bean [class com.satukancinta.web.Persistence] with qualifiers [@Any @Default].
    at org.jboss.weld.util.Proxies.getUnproxyableClassException(Proxies.java:225)
    at org.jboss.weld.util.Proxies.getUnproxyableTypeException(Proxies.java:178)
    at org.jboss.weld.util.Proxies.getUnproxyableTypesExceptionInt(Proxies.java:193)
    at org.jboss.weld.util.Proxies.getUnproxyableTypesException(Proxies.java:167)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:110)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:126)
    at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:345)
    at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:330)
    at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:366)
    at org.jboss.as.weld.WeldContainer.start(WeldContainer.java:82)
    at org.jboss.as.weld.services.WeldService.start(WeldService.java:89)
    ... 5 more

As you can see, my use code isn't exactly "edge cases".

It's actually a pretty common use case: create a Akka actor and pass a factory function to it, as a closure.
The code above doesn't look like it's using a closure, but it actually is when written like this: (same functionality, but still breaks CDI)

    fbPhotoImporter = Actor.actorOf { fbPhotoImporterFactory.get() }

I can see why CDI has a strict requirement, and I can also understand why Scala implements it the way it is (Scala developers definitely already has a lot of problems working around powerful Scala features into a very restrictive JVM bytecode requirements). This is the price we pay for having a somewhat inferior language (Java, please don't get offended) in the first place.

But I as an application developer want to have a quick fix for this issue. Re-coding the class in plain Java is one option, but it turns I don't need to. There is a workaround, by creating a helper method then using it:

  @Inject private var fbPhotoImporterFactory: Instance[FacebookPhotoImporter] = _
  @Produces @Named("facebookPhotoImporter") private var fbPhotoImporter: ActorRef = _
 
  def createFbPhotoImporter() = fbPhotoImporterFactory.get()
 
  @PostConstruct
  def init() {
    logger.debug("Starting FacebookPhotoImporter actor")
    fbPhotoImporter = Actor.actorOf(createFbPhotoImporter)
    fbPhotoImporter.start()
  }

Now Scala is happy and CDI is also happy. Yes it's a bit more verbose but not too bad. And I guess the code is now somewhat more understandable for Java guys. :)

Tip: To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.

Categories: Programming Blogs

AMD Catalyst 12.1 Driver on HP Pavilion dv6t Quad Hybrid Radeon with Linux Mint 12 / Ubuntu 11.10 Oneiric

Ubuntu Computing - Sun, 01/29/2012 - 12:14
I found a way to fully use the powerful AMD/ATI Radeon 6770M Hybrid Graphics Card inside HP Pavilion dv6t Quad Edition in Linux Mint 12 / Ubuntu 11.10 Oneiric. Thanks to the comment by Linux Hybrid Graphics blog!

Right now, I have configured by AMD hybrid graphics laptop to use the Radeon card when on AC power (and get dramatically improved 3D rendering performance), and use the Intel built-in card when on battery power. I'm not sure if I will actually ever need the 3D since I almost never do 3D gaming on Linux, I mainly work as programmer. But the functionality is there and ready. :-)

Here's my steps to get it to work:

  1. First, if you use vgaswitcheroo to switch off the dedicated Radeon graphics card, disable the command in /etc/rc.local by commenting it :
    #echo OFF > /sys/kernel/debug/vgaswitcheroo/switch

  2. Follow the steps in Installing Catalyst Manually from AMD/ATI Website.
    In AMD/ATI Catalyst Linux Driver download page, make sure to download new AMD Catalyst Linux Driver version 12.1 (aka 8.930) or newer

  3. Use the Intel i915 VAAPI driver to get hardware accelerated decoding when playing videos using VLC, to install:
    sudo apt-get install i915-va-driver

  4. If you mess up the system, follow instructions in ATI driver re-install fail.
After reboot, your laptop should work just fine.

I have several minor issues (not a blocker by any means):

  • I still experience video tearing, even after I do:
    sudo aticonfig --sync-video=on
    and turned VSync sldier to Always On in AMD Catalyst Center.
    Maybe it's because I need to do this configuration on the Intel card?

  • KDE 4.8.0 multi-monitor setup is acting weird. It does detect multiple monitors, and can configure the resolution, position, etc. but doesn't detect that it is using multiple monitors, i.e. maximizing/full-screen-ing windows make it fill the whole desktop, not just one screen.
    This is a bit annoying as I watch movies a lot on a 32" HDMI LCD TV but still want to browse or do other stuff on the laptop while watching
I'll give an update when I've got more news on them...

Find tips to optimize your Ubuntu 11.10 in Ubuntu Unleashed 2012 Edition: Covering 11.10 and 12.04 (7th Edition) !

Categories: Programming Blogs

Scala "Bug" with CDI Dependency Injection

“Sometimes”, Scala creates public final methods, although the .scala source defines
no public final method at all.
There are two things that CDI doesn’t like (which Scala “sometimes” generates):
1. public final methods
2. public fields
To investigate and reproduce these problems I created a scala-cdi project at GitHub.
public final method: The Bug Referencing a parent field from a closure / inner class triggers this behavior:
@RequestScoped @Named class IndexBean { private lazy val log = LoggerFactory.getLogger(classOf[IndexBean]) def testExecutor() = { val executor = Executors.newFixedThreadPool(4); executor.submit(new Runnable() { override def run(): Unit = log.debug("Executor is running") }) } } Compiles to:
$ javap -p IndexBean Compiled from "IndexBean.scala" public class com.soluvas.scalacdi.IndexBean extends java.lang.Object implements scala.ScalaObject{ private org.slf4j.Logger com$soluvas$scalacdi$IndexBean$$log; ... public final org.slf4j.Logger com$soluvas$scalacdi$IndexBean$$log(); Deploying this app in Weld will throw:
org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001437 Normal scoped bean class com.soluvas.scalacdi.IndexBean is not proxyable because the type is final or it contains a final method public final org.slf4j.Logger com.soluvas.scalacdi.IndexBean.com$soluvas$scalacdi$IndexBean$$log() - Managed Bean [class com.soluvas.scalacdi.IndexBean] with qualifiers [@Any @Default @Named]. at org.jboss.weld.util.Proxies.getUnproxyableClassException(Proxies.java:225) at org.jboss.weld.util.Proxies.getUnproxyableTypeException(Proxies.java:178) at org.jboss.weld.util.Proxies.getUnproxyableTypesExceptionInt(Proxies.java:193) at org.jboss.weld.util.Proxies.getUnproxyableTypesException(Proxies.java:167) at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:110) public final method: Workaround Create a final local variable to hold the parent instance’s value:
def testExecutor() = { val executor = Executors.newFixedThreadPool(4); // this avoids 'log' becoming 'final' like: // private org.slf4j.Logger com$soluvas$scalacdi$IndexBean$$log; // public final org.slf4j.Logger com$soluvas$scalacdi$IndexBean$$log(); val log = this.log; executor.submit(new Runnable() { override def run(): Unit = log.debug("Executor is running") }) } Which now compiles to:
$ javap -p IndexBean Compiled from "IndexBean.scala" public class com.soluvas.scalacdi.IndexBean extends java.lang.Object implements scala.ScalaObject{ private org.slf4j.Logger log; private org.slf4j.Logger log(); public field I’m not able to reproduce this yet...
Tip: To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.
Categories: Programming Blogs

Pentaho Data Integration Transformation and Step Architecture

Spring vs Java EE Web Development - Tue, 01/17/2012 - 11:44

After doing some Pentaho Data Integration (Kettle) work especially with JSON Output Step in PDI-7195 bug, I guess it's a good thing to describe visually how I see the PDI transformations and steps architecture.

Hopefully this is helpful for you and also to remind me when I'm confused because which Kettle step framework classes/interfaces relate to which ones is sometimes easy to forget. :-)

Learn how to process and integrate enterprise databases & data warehouses easily with Pentaho Data Integration 4 Cookbook.

Categories: Programming Blogs

When do work in Enterprise Application Integration field...

Spring vs Java EE Web Development - Sat, 01/14/2012 - 13:19

...be prepared to get ClassNotFoundException, ClassCastException,

and loads of other classpath and classloading problems often. :-)

(if you don't use OSGi, that is...)

Categories: Programming Blogs

When do work in Enterprise Application Integration field...

Spring vs Java EE Web Development - Sat, 01/14/2012 - 13:19

...be prepared to get ClassNotFoundException, ClassCastException,

and loads of other classpath and classloading problems often. :-)

(if you don't use OSGi, that is...)

Categories: Programming Blogs

Making JSF 2.0 Composite Components Ajax render-capable

Spring vs Java EE Web Development - Wed, 01/11/2012 - 23:55

If you for example have the following composite component in a JSF 2.0 Facelets XHTML template:

<sc:block title="Followers">

<h:panelGroup rendered="#{not empty userShow.user.followedByUsers}">

<ul>

<ui:repeat var="user" value="#{userShow.user.followedByUsers}">

<li><sc:user_link user="#{user}"/></li>

</ui:repeat>

</ul>

</h:panelGroup>

<h:panelGroup rendered="#{empty usefollowedByUsers}">

#{userShow.user.name} has no followers.

</h:panelGroup>

</sc:block>

and try do ajax render:

<a4j:commandButton value="Follow" action="#{userBean.follow(currentUser, userShow.user)}"

render="followPanel followers"

rendered="#{not currentUser.isFollowing(userShow.user)}"/>

This won't work for some reason. Wrong workaround is using a h:panelGroup and moving the id for ajax render there:

<sc:block title="Followers">

<h:panelGroup id="followers">

<h:panelGroup rendered="#{not empty userShow.user.followedByUsers}">

<ul>

<ui:repeat var="user" value="#{userShow.user.followedByUsers}">

<li><sc:user_link user="#{user}"/></li>

</ui:repeat>

</ul>

</h:panelGroup>

<h:panelGroup rendered="#{empty us.followedByUsers}">

#{userShow.user.name} has no followers.

</h:panelGroup>

</h:panelGroup>

</sc:block>

The correct solution is to put a #{cc.clientId} like below in the composite implementation:

<composite:implementation>

<section id="#{cc.clientId}" class="block">

<div class="block-inner clearfix">

<h2 class="block-title">#{cc.attrs.title}</h2>

<div class="block-content content">

<composite:insertChildren/>

</div>

</div>

</section>

</composite:implementation>

To learn more about Java Web Development using Java EE 6, I highly recommend The Java EE 6 Tutorial: Basic Concepts (4th Edition) (Java Series) by Eric Jendrock, Ian Evans, Devika Gollapudi and Kim Haase.

Categories: Programming Blogs

Implementing RichFaces ExtendedDataModel for JSF Paging with Spring Data Neo4j and Scala

JSF 2.1 and JBoss RichFaces 4.1.0 make it easy to do server-side paging and sorting, which improves performance of Java EE web applications significantly compared to returning list of all rows from the database and filtering it later in the application.

By implementing ExtendedDataModel, the data model can be used directly by rich:dataTable and rich:dataScroller JSF components.

ExtendedDataModel for Spring Data Neo4j Finder/Query Methods

To implement this on Neo4j graph database, by using Spring Data Neo4j finder methods we can implement ExtendedDataModel like below: (in Scala programming language)

package com.satukancinta.web

import collection.JavaConversions._
import org.ajax4jsf.model.ExtendedDataModel
import javax.faces.context.FacesContext
import org.springframework.data.domain.Page
import org.ajax4jsf.model.DataVisitor
import org.springframework.data.neo4j.repository.GraphRepository
import org.springframework.data.domain.PageRequest
import org.springframework.data.neo4j.aspects.core.NodeBacked
import org.ajax4jsf.model.Range
import org.ajax4jsf.model.SequenceRange
import org.slf4j.LoggerFactory
import org.springframework.data.domain.Sort
import org.springframework.data.domain.Sort.Direction
import org.springframework.data.domain.Pageable

abstract class FinderModel[E]() extends ExtendedDataModel[E] {
  private lazy val log = LoggerFactory.getLogger(classOf[FinderModel[E]])
 
  private lazy val rowCount: Int = {
    val result= getRowCountLazy
    log.debug("Total rows: {}", result)
    result
  }
 
  private var rowIndex: Int = _
  private var page: Page[E] = _
  private var pageData: List[E] = _
  private var lastRange: (Int, Int) = _

  log.trace("Created {}", this.getClass)
 
  def getRowCountLazy: Int
  def find(pageable: Pageable): Page[E]

  def setRowKey(key: Object): Unit = setRowIndex(key.asInstanceOf[Int])
  def getRowKey: Object = getRowIndex: java.lang.Integer
 
  private def loadData(range: Range): Unit = {
    val seqRange = range.asInstanceOf[SequenceRange]
    val curRange = (seqRange.getFirstRow, seqRange.getRows)
    if (lastRange == curRange) {
      log.debug("loadData returning cached")
      return
    }
    lastRange = curRange
   
    val pageNum = seqRange.getFirstRow / seqRange.getRows
    // ORDER BY name is painfully slow: https://groups.google.com/group/neo4j/t/f2219df41f5500a9
    val pageReq = new PageRequest(pageNum, seqRange.getRows/*, Direction.ASC, "y.name"*/)
    log.debug("loadData({}, {}) -> PageRequest({}, {})",
        Array[Object](seqRange.getFirstRow: java.lang.Long, seqRange.getRows: java.lang.Long,
            pageNum: java.lang.Long, seqRange.getRows: java.lang.Long))
    val startTime = System.currentTimeMillis
    page = find(pageReq)
    val findTime = System.currentTimeMillis - startTime
    log.debug("Page has {} rows of {} total in {} pages, took {}ms",
        Array[Object](page.getSize: java.lang.Long, page.getTotalElements: java.lang.Long,
            page.getTotalPages: java.lang.Long, findTime: java.lang.Long))
    pageData = page.toList
//    val pageIds = pageData.map( _.asInstanceOf[NodeBacked].getNodeId )
//    log.debug("Node IDs: {}", pageIds);
  }

  def walk(context: FacesContext, visitor: DataVisitor, range: Range, argument: Object): Unit = {
    loadData(range)
    for (val index <- 0 to pageData.size - 1) {
      visitor.process(context, index, argument)
    }
  }

  def isRowAvailable: Boolean = rowIndex < pageData.length

  def getRowCount: Int = rowCount

  def getRowData: E = {
    val result = pageData(rowIndex) // repository.findOne(rowKey.asInstanceOf[Long])
    val node = result.asInstanceOf[NodeBacked]
    log.trace("getRowData({}) = #{}: {}",
        Array[Object](rowIndex: java.lang.Long, node.getNodeId: java.lang.Long, node))
    result
  }

  def getRowIndex: Int = rowIndex
  def setRowIndex(index: Int): Unit = rowIndex = index

  def getWrappedData: Object = { null }
  def setWrappedData(wrappedData: Object): Unit = { /* dummy */ }

}

To use the FinderModel, it's much easier if we create a repository first and add some finder/query methods returning count and Page:

public interface InterestRepository extends GraphRepository<Interest> {

    @Query("START u=node({userId}) MATCH u-[:LIKE]->y RETURN COUNT(y)")
    public Long findUserLikeCount(@Param("userId") long userId);

    // ORDER BY name is still slow: https://groups.google.com/group/neo4j/t/f2219df41f5500a9
//    @Query("START u=node({userId}) MATCH u-[:LIKE]->y RETURN y ORDER BY y.name")
    @Query("START u=node({userId}) MATCH u-[:LIKE]->y RETURN y")
    public Page<Interest> findUserLikes(@Param("userId") long userId, Pageable pageable);

}

How to create a FinderModel instance from Java :

    @Inject InterestRepository interestRepo;
    private FinderModel<Interest> userLikesModel;

    @PostConstruct public void init() {
        userLikesModel = new FinderModel<Interest>() {

            @Override
            public int getRowCountLazy() {
                return interestRepo.findUserLikeCount(user.getNodeId()).intValue();
            }

            @Override
            public Page<Interest> find(Pageable pageable) {
                return interestRepo.findUserLikes(user.getNodeId(), pageable);
            }
        };
    }

And how to use this data model from a JSF Template .xhtml file:

<rich:dataTable id="interestTable" var="interest" value="#{userLikes.userLikesModel}" rows="20">
    <rich:column>
        <f:facet name="header">Name</f:facet>
        <h:link outcome="/interests/show?id=#{interest.nodeId}" value="#{interest.name}"/>
    </rich:column>
    <f:facet name="footer"><rich:dataScroller/></f:facet>
</rich:dataTable>

Quite practical, isn't it?


ExtendedDataModel for Spring Data Neo4j Repository

FinderModel can then be further subclassed to handle any Spring Data Neo4j repository:

class GraphRepositoryModel[E]() extends FinderModel[E] {
  private var repository: GraphRepository[E] = _
 
  def getRowCountLazy: Int = repository.count.toInt
  def find(pageable: Pageable): Page[E] = repository.findAll(pageable)

  override def getWrappedData: Object = repository
  override def setWrappedData(wrappedData: Object): Unit =
    repository = wrappedData.asInstanceOf[GraphRepository[E]]

}

And use it like this:

@Inject InterestRepository interestRepo;
private GraphRepositoryModel<Interest> interestModel;
   
@PostConstruct public void init() {
    interestModel = new GraphRepositoryModel<Interest>();
    interestModel.setWrappedData(interestRepo);
}

Hope this helps.

To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.

Categories: Programming Blogs

Scala closures vs Guava collection functions

Let me show you the same method using list transformations (aka "map" in functional programming speak), one in Java programming language:

    @GET @Path("user/{userId}/likes") @Produces(MediaType.APPLICATION_JSON)
    public Payload<Iterable<Map<String, Object>>> getUserLikes(@PathParam("userId") long userId) {
        User user = neo4j.findOne(userId, User.class);
        Iterable<Interest> likeInterests = user.getLikeInterests();
        Iterable<Map<String, Object>> likes = Iterables.transform(likeInterests, new Function<Interest, Map<String, Object>>() {
            @Override
            public Map<String, Object> apply(Interest interest) {
                HashMap<String, Object> row = new HashMap<String, Object>();
                row.put("id", interest.getNodeId());
                row.put("name", interest.getName());
                return  row;
            }
        });
        return new Payload<Iterable<Map<String, Object>>>(likes);
    }


And one in Scala programming language :

    @GET @Path("user/{userId}/likes") @Produces(Array(MediaType.APPLICATION_JSON))
    def getUserLikes(@PathParam("userId") userId: Long): Payload[Iterable[Map[String, Object]]] = {
        val user = neo4j.findOne(userId, classOf[User])
        val likeInterests = user.getLikeInterests
        val likes = likeInterests.map(interest =>
          Map("id"->interest.getNodeId, "name"->interest.getName) )
        new Payload(likes)
    }

Is Scala hard to read? I'll leave it to you to decide. :-)

To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.

Categories: Programming Blogs

Coding JSON REST JAX-RS Service Application to Access Neo4j Database in Scala

Spring Data Neo4j makes it easy to accessing graph data in Neo4j graph database.

After separating the AspectJ-enhanced Spring Data Neo4j node entities, relationship entities, and repositories, it's very fun to access the entities from a Scala web application. In this case, I'll show you a JAX-RS application written in Scala programming language, consuming and producing JSON in REST-style. The application exposes Spring Data Neo4j through HTTP, which can be accessed via curl or any other web client.

Java programming language version:

@Path("node") @Stateless
public class NodeResource {

    private transient Logger logger = LoggerFactory.getLogger(NodeResource.class);
    @Inject Neo4jTemplate neo4j;
    @Inject InterestRepository interestRepo;
   
    @GET @Path("interest") @Produces(MediaType.APPLICATION_JSON)
    public Iterable<Interest> interest() {
        ClosableIterable<Interest> records = neo4j.findAll(Interest.class);
        return records;
    }

    @GET @Path("user") @Produces(MediaType.APPLICATION_JSON)
    public Payload<User> getUser() {
        return new Payload<User>(neo4j.findOne(5L, User.class));
    }

    @POST @Path("interest")
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    public Response createInterest(Payload<Interest> payload) {
        logger.debug("createInterest {}", payload.data);
        Interest interest = payload.data;
        interest.persist();
        return Response.created(URI.create(String.format("interest/%d", interest.getNodeId())))
                .entity(new Payload<Interest>(interest)).build();
    }

    @DELETE @Path("interest/{id}")
    public Response deleteInterest(@PathParam("id") long id) {
        try {
            Interest node = neo4j.findOne(id,  Interest.class);
            node.remove();
            return Response.ok("deleted").build();
        } catch (DataRetrievalFailureException e) {
            return Response.status(Status.NOT_FOUND).entity(e.getMessage()).build();
        }
    }

    @GET @Path("interest/by/facebookId/{facebookId}")
    @Produces(MediaType.APPLICATION_JSON)
    public Payload<Interest> findInterestByFacebookId(@PathParam("facebookId") long facebookId) {
        logger.debug("findInterestByFacebookId {}", facebookId);
        Interest interest = interestRepo.findByFacebookId(facebookId);
        if (interest == null)
            throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity("Interest with facebookId="+ facebookId +" not found").build());
        return new Payload<Interest>(interest);
    }

}


Scala programming language version:

@Path("node") @Stateless
class NodeResource {

    private lazy val logger = LoggerFactory.getLogger(classOf[NodeResource])
    @Inject var neo4j: Neo4jTemplate = _
    @Inject var interestRepo: InterestRepository = _
    
    @GET @Path("interest") @Produces(Array(MediaType.APPLICATION_JSON))
    def interest: Iterable[Interest] = neo4j.findAll(classOf[Interest])

    @GET @Path("user") @Produces(Array(MediaType.APPLICATION_JSON))
    def getUser: Payload[User] = new Payload[User](neo4j.findOne(5L, classOf[User]))

    @POST @Path("interest")
    @Consumes(Array(MediaType.APPLICATION_JSON))
    @Produces(Array(MediaType.APPLICATION_JSON))
    def createInterest(payload: Payload[Interest]): Response = {
        logger.debug("createInterest {}", payload.data)
        val interest = payload.data
        interest.persist
        Response.created(URI.create(String.format("interest/%d", interest.getNodeId)))
                .entity(new Payload[Interest](interest)).build
    }

    @DELETE @Path("interest/{id}")
    def deleteInterest(@PathParam("id") id: Long): Response = {
        try {
            val node = neo4j.findOne(id, classOf[Interest])
            node.remove
            Response.ok("deleted").build
        } catch {
          case e: DataRetrievalFailureException =>
            Response.status(Status.NOT_FOUND).entity(e.getMessage).build
        }
    }

    @GET @Path("interest/by/facebookId/{facebookId}")
    @Produces(Array(MediaType.APPLICATION_JSON))
    def findInterestByFacebookId(@PathParam("facebookId") facebookId: Long): Payload[Interest] = {
        logger.debug("findInterestByFacebookId {}", facebookId)
        val interest = interestRepo.findByFacebookId(facebookId)
        if (interest == null)
            throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity("Interest with facebookId="+ facebookId +" not found").build
        new Payload[Interest](interest)
    }

}


Apart from less code and cruft, Scala code is not much different in structure.

If there are list processing functions or closures, then Scala code will read much easier, while the Java code will use Guava library and clunky syntax (at least until Java 8 arrives).

To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.

Categories: Programming Blogs

Graph Analysis with Scala and Spring Data Neo4j

Neo4j graph database is the an awesome technology for graph data persistence. With Spring Data Neo4j accessing graph data becomes even easier.

The easiest way to use Spring Data Neo4j is by enabling its AspectJ weaving. Because I wanted to use both Scala and Spring Data Neo4j in my web application, using both languages (AspectJ and Scala) in the same project isn't possible for now. A tip for you, separate the AspectJ-enhanced classes (@NodeEntity, @RelationshipEntity, and repositories) into a separate AspectJ project, then depend on the AspectJ from the Scala application.

The result is I'm able to fully utilize the versatile Scala and the excellent Spring Data libraries with Neo4j.

Now for mandatory code comparison between Java and Scala :-)

Java programming language version:

package com.satukancinta.web;

import java.util.List;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.neo4j.conversion.Result;
import org.springframework.data.neo4j.support.Neo4jTemplate;

import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.satukancinta.domain.User;

/**
 * @author ceefour
 * Various analysis of the social graph.
 */
@Named @ApplicationScoped
public class GraphAnalysis {
   
    private transient Logger logger = LoggerFactory.getLogger(GraphAnalysis.class);
    @Inject Neo4jTemplate neo4j;
   
    public List<MutualLikeRow> getMutualLikesLookup(User user) {
        logger.debug("getMutualLikesLookup {}/{}", user.getNodeId(), user);
        Result<Map<String, Object>> rows = neo4j.query("START x=node("+ user.getNodeId() +") MATCH x-[:LIKE]->i<-[:LIKE]-y RETURN id(y) AS id, y.name AS name, COUNT(*) AS mutualLikeCount", null);
        Iterable<MutualLikeRow> result = Iterables.transform(rows, new Function<Map<String, Object>, MutualLikeRow>() {
            @Override
            public MutualLikeRow apply(Map<String, Object> arg) {
                return new MutualLikeRow((Long)arg.get("id"), (Integer)arg.get("mutualLikeCount"),
                        (String)arg.get("name"));
            }
        });
        return Lists.newArrayList(result);
    }

}

Scala programming language version:

package com.satukancinta.web
import collection.JavaConversions._
import org.slf4j._
import javax.inject.Inject
import org.springframework.data.neo4j.support.Neo4jTemplate
import com.satukancinta.domain.User
import javax.enterprise.context.ApplicationScoped
import javax.inject.Named

/**
 * @author ceefour
 * Analysis functions of friend network graph.
 */
@Named @ApplicationScoped
class GraphAnalysis {

  private lazy val logger = LoggerFactory.getLogger(classOf[GraphAnalysis])
  @Inject private var neo4j: Neo4jTemplate = _
 
  def getMutualLikesLookup(user: User): java.util.List[MutualLikeRow] = {
    logger.debug("getMutualLikesLookup {}/{}", user.getNodeId, user)
    val rows = neo4j.query(
        "START x=node("+ user.getNodeId() +") MATCH x-[:LIKE]->i<-[:LIKE]-y RETURN id(y) AS id, y.name AS name, COUNT(*) AS mutualLikeCount", null)
    val result = rows.map( r =>
          new MutualLikeRow(r("id").asInstanceOf[Long],
            r("mutualLikeCount").asInstanceOf[Integer].longValue,
            r("name").asInstanceOf[String]) )
        .toList
    result.sortBy(-_.mutualLikeCount)
  }
 
}


As you can see, the Scala version is not only much more concise, easier to understand, but actually has added functionality (sorted using .sortBy) with less code. Thanks to collection functions and closure support.

To learn more about Scala programming, I recommend Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition.

Categories: Programming Blogs

Fix Jackson/JAXB JSON Serialization Problem with Spring Data Neo4j @NodeEntity Objects

Spring vs Java EE Web Development - Thu, 12/22/2011 - 20:09

Spring Data Neo4j @NodeEntity-annotated objects are proxy-enriched by Spring Data Neo4j aspects using AspectJ. There are times we want to expose these objects via JAX-RS REST API or JAX-WS / SOAP web services and then (by default) we will have problems.

The error stacktrace messages (here using JBoss AS 7.0.2) are along the lines of:

HTTP Status 500 - org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.neo4j.graphdb.DynamicRelationshipType and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.satukancinta.domain.User["enjoyActivities"]->org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet[0]->com.satukancinta.domain.Activity["persistentState"]->org.neo4j.rest.graphdb.entity.RestNode["relationships"]->org.neo4j.rest.graphdb.entity.RestRelationship["type"])

type Status report

message org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.neo4j.graphdb.DynamicRelationshipType and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.satukancinta.domain.User["enjoyActivities"]->org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet[0]->com.satukancinta.domain.Activity["persistentState"]->org.neo4j.rest.graphdb.entity.RestNode["relationships"]->org.neo4j.rest.graphdb.entity.RestRelationship["type"])

description The server encountered an internal error (org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.neo4j.graphdb.DynamicRelationshipType and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: com.satukancinta.domain.User["enjoyActivities"]->org.springframework.data.neo4j.fieldaccess.ManagedFieldAccessorSet[0]->com.satukancinta.domain.Activity["persistentState"]->org.neo4j.rest.graphdb.entity.RestNode["relationships"]->org.neo4j.rest.graphdb.entity.RestRelationship["type"])) that prevented it from fulfilling this request.

To solve this problem, annotate your entity class with @JsonAutoDetect(JsonMethod.NONE) :

import org.codehaus.jackson.annotate.JsonAutoDetect;

import org.codehaus.jackson.annotate.JsonMethod;

import org.codehaus.jackson.annotate.JsonProperty;


@NodeEntity @JsonAutoDetect(JsonMethod.NONE)

public class User implements NodeBacked {

then manually annotate each property you want to serialize with @JsonProperty :

@JsonProperty

public String getName() {

return name;

}

Now the JAX-RS Application works as intended and everybody is happy. :-) There's also a StackOverflow thread that discusses this problem.

To learn more about Java Web Development using Java EE 6, I highly recommend The Java EE 6 Tutorial: Basic Concepts (4th Edition) (Java Series) by Eric Jendrock, Ian Evans, Devika Gollapudi and Kim Haase.

Categories: Programming Blogs

How to Resolve Spring Data Neo4j / Jersey / Jackson Conflict with JBoss AS 7 RESTEasy

Spring vs Java EE Web Development - Thu, 12/22/2011 - 18:26

I'm using Spring Data Neo4j REST Client which uses Jersey JAX-RS Client. Unfortunately when deployed to JBoss AS 7.0.2, it conflicts with the built-in RESTEasy deployer (bug DATAGRAPH-159).

In order to run the application, jersey-server must be excluded :

<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-neo4j-rest</artifactId> <version>${spring-data-neo4j.version}</version> <exclusions> ... <exclusion> <artifactId>jersey-server</artifactId> <groupId>com.sun.jersey</groupId> </exclusion> </exclusions> </dependency>

Another issue I came across is my web application is also a JAX-RS Service Application, therefore it requires JBoss RESTEasy. Unfortunately Jackson JSON Provider which is a dependency of Neo4j REST Client and Jersey JAX-RS Client conflicts with RESTEasy's Jackson Provider, with the following exception stacktrace message:

java.lang.RuntimeException: Unable to instantiate MessageBodyReader org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:760) org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:742) org.jboss.resteasy.spi.ResteasyDeployment.registerProvider(ResteasyDeployment.java:505) org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:305) org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:225) org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.init(ServletContainerDispatcher.java:67) org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.init(HttpServletDispatcher.java:36) org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139) org.jboss.as.web.NamingValve.invoke(NamingValve.java:57) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:897) org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2054) java.lang.Thread.run(Thread.java:722)

root cause

java.lang.RuntimeException: Illegal to inject a message body into a singleton into public org.codehaus.jackson.jaxrs.JacksonJsonProvider(org.codehaus.jackson.map.ObjectMapper,org.codehaus.jackson.jaxrs.Annotations[]) org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:209) org.jboss.resteasy.core.ConstructorInjectorImpl.injectableArguments(ConstructorInjectorImpl.java:63) org.jboss.resteasy.core.ConstructorInjectorImpl.construct(ConstructorInjectorImpl.java:129) org.jboss.resteasy.spi.ResteasyProviderFactory.getProviderInstance(ResteasyProviderFactory.java:1038)

I thought this was issue RESTEASY-503, because JBoss AS 7.0.2 happened to use the somewhat buggy RESTEasy 2.2.1.GA. But it turns out there is an easy fix to this problem, thanks to Configuring Module Classloading in JBoss AS 7.

Edit src/main/webapp/WEB-INF/jboss-deployment-structure.xml as follows:


<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">

<deployment>

<dependencies>

<module name="org.codehaus.jackson.jackson-jaxrs"/>

<module name="org.codehaus.jackson.jackson-core-asl"/>

<module name="org.codehaus.jackson.jackson-mapper-asl"/>

</dependencies>

</deployment>

</jboss-deployment-structure>

Now Spring Data Neo4j, Jersey Client with JSON Jackson Provider, and my JAX-RS Application served by RESTEasy, all can coexist in the same web application WAR. :-)

To learn more about Java Web Development using Java EE 6, I highly recommend The Java EE 6 Tutorial: Basic Concepts (4th Edition) (Java Series) by Eric Jendrock, Ian Evans, Devika Gollapudi and Kim Haase.

Categories: Programming Blogs

I don't "get" JSON Output in Pentaho Data Integration (PDI) / Kettle

Spring vs Java EE Web Development - Wed, 12/07/2011 - 17:23
I don't understand how to use the JSON Output step properly in Kettle aka Pentaho Data Integration (PDI).

With "Nr of rows in a bloc" set to 0 or 3, I got:

{
  "categories": [
    {
      "code": "WORKAHOLIC-CHIC"
    },
    {
      "name": "Workaholic Chic"
    },
    {
      "description": "Move ! Move ! move...!!\nLight Up Your Day... with a perfect match, \nPadanan busana kerja Professsional look, Powerfull & Fashionable,\nwhich got several design for different mood,  multifunction,\nMemorable style!\nLet’s be and stay Tuneeca...\n"
    }
  ]
}

which is basically only the last record.

With "Nr of rows in a bloc" set to 1, I got:

{
  "categories": [
    {
      "code": "AKSESORI-LIGHT-UP-YOUR-DAY"
    },
    {
      "name": "Aksesori Light Up Your Day"
    },
    {
      "description": "-"
    },
    {
      "code": "AKSESORIS-APRIL-2009"
    },
...

What I'm trying to get is:

{ "categories": [
  { "code": "AKSESORI-LIGHT-UP-YOUR-DAY",
     "name": "Aksesori Light Up Your Day"
     "description": "Very cool" },
  { "code": .........

Contrast this with the XML Output, which I get the following correct output right from first try:

<?xml version="1.0" encoding="UTF-8"?>
<categories>
  <category>
    <code>AKSESORI-LIGHT-UP-YOUR-DAY</code>
    <name>Aksesori Light Up Your Day</name>
    <description>-</description>
  </category>
  <category>
    <code>AKSESORIS-APRIL-2009</code>
...

An additional plus is that XML Output already performs a bit of output pretty formatting, which I appreciate very much. (JSON Output outputs everything in a single line)

Those two Output steps gets the same input data.

Any ideas ?

Categories: Programming Blogs

Pages

Subscribe to Business Software in the Cloud aggregator - Programming Blogs