What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This...

45
QuickTime™ et un décompresseur sont requis pour visionner cette image. QuickTime™ et un décompresseur sont requis pour visionner cette image. What’s new in Groovy 1.6 Guillaume Laforge SpringSource Groovy Project Manager

Transcript of What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This...

Page 1: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTim e™ et undécom presseur

sont requis pour vis ionner cette im age.

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

What’s new in Groovy 1.6

Guillaume LaforgeSpringSourceGroovy Project Manager

Page 2: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 2

Guillaume LaforgeGroovy Project Manager — SpringSource> Working on Groovy since 2003> JSR-241 Spec Lead

> Initiator of the Grails web framework

> Co-author of Groovy in Action

> Speaker: JavaOne, QCon, JavaPolis/Devoxx, JavaZone, Sun Tech Days, SpringOne/The Spring Experience, JAX, DSL DevCon, and more…

QuickTim e™ et undécom pres s eur

s ont requis pour vis ionner cette im age.

Page 3: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 3

What’s new in Groovy 1.6?Article Published by InfoQ

> This presentation was prepared with the examples I’ve used in my article written for InfoQ

> http://www.infoq.com/articles/groovy-1-6

> Read this article for more detailed explanations of all the new features in Groovy 1.6

QuickT im e™ et undécom presseur

sont requis pour visionner cette im age.

Page 4: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 4

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 5: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 5

Groovy in a NutshellSimplify the Life of Java Developers> Groovy is a dynamic language for the Java

Virtual Machine With a Meta-Object Protocol Compiles down to bytecode

> Open Source Apache licensed project> Relaxed grammar derived from the Java 5

grammar Borrowed some good ideas from Smalltalk/Python/

Ruby Java 5 features out of the box: annotations,

generics, static imports, enums… Flat learning curve

Page 6: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 6

Features at a GlanceLots More Than This!> Fully Object-Oriented> Joint compiler: seamless Java integration> Closures: reusable blocks of code / anon functions> Properties: forget about getters and setters> Optional typing: your choice!> BigDecimal arithmetic by default for floating point> Handy APIs

XML, JDBC, JMX, template engine, Swing UIs> Strong ability for authoring Domain-Specific Languages

Syntax-level “builders” Adding properties to numbers: 10.dollars Operator overloading: 10.meters + 20.kilometers

Page 7: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 7

A Taste of Groovy — Take 1A Normal Java Program> public class HelloWorld { private String name;

public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println( helloWorld.greet() ); }}

Page 8: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 8

A Taste of Groovy — Take 2A Valid Groovy Program> public class HelloWorld { private String name;

public void setName(String name) { this.name = name; } public String getName() { return name; } public String greet() { return "Hello " + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName("Groovy"); System.out.println( helloWorld.greet() ); }}

Page 9: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age.

QuickTim e™ et undécom presseur

sont requis pour vis ionner cette im age.

9

A Taste of Groovy — Take 3A Groovier Program!

> class HelloWorld { String name String greet() { "Hello $name" }}def helloWorld = new HelloWorld(name: "Groovy")println helloWorld.greet()

Page 10: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 10

The Groovy Web ConsoleA Groovy Playground

> Groovy works nicely on Google App Engine You can also deploy Grails applications

> You can play with Groovy in the web console http://groovyconsole.appspot.com/

Page 11: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 11

The Groovy Web ConsoleA Screenshot

Page 12: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 12

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 13: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 13

Performance ImprovementsBoth Runtime & Compile-Time> The Groovyc compiler is 3x to 5x faster

With a clever class lookup cache

> Certain online micro-benchmarks show150% to 460% increase in performance compared to Groovy 1.5 Thanks to advanced call-site caching techniques Beware of micro-benchmarks!

> Makes Groovy one of the fastest dynamic languages available

Page 14: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 14

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 15: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 15

Multiple AssignmentAssign Multiple Variables at Once> Newly defined variables

def (a, b) = [1, 2]assert a == 1assert b == 2> Assign to existing variables

def lat, lng(lat, lng) = geocode(‘Paris’)> The classical swap case

(a, b) = [b, a]> Extra elements ⇒ not assigned to any variable> Less elements ⇒ null into extra variables

Page 16: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 16

More Optional ReturnIn if/else and try/catch Blocks> The return keyword is optional for the last expression of

a method body But if/else & try/catch didn’t return any value

> def method() { if (true) 1 else 0 }assert method() == 1> def method(bool) { try { if (bool) throw new Exception("foo") 1 } catch(e) { 2 } finally { 3 }} assert method(false) == 1assert method(true) == 2

Page 17: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 17

Annotation DefinitionThe Missing Bit of Java 5 Support

> Groovy support for Java 5 features is now complete with the missing annotation definition

> Nothing to show here, it’s just normal Java :-)

> Note that the sole dynamic language supporting annotation is… Groovy Opens the door to EJB3 / JPA / Spring

annotations / Guice / TestNG…

Page 18: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 18

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 19: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 19

Meta-What?Meta-Programming> The ability of a language to modify itself

> Groovy 1.6 introduces AST Transformations Abstract Syntax Tree

> Goodbye to a lot of boiler-plate technical code!

> Two kinds of transformations Global transformations Local transformations: triggered by annotations

Page 20: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 20

AST Transformations in Groovy 1.6Implement Patterns through Transformations> Several transformations finds their way

@Singleton — okay, not really a pattern ;-) @Immutable, @Lazy, @Delegate @Newify @Category and @Mixin @PackageScope Swing’s @Bindable and @Vetoable Grape’s @Grab

> Let’s have a look at some of them!

Page 21: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 21

@Singleton(Anti-)Pattern Revisited> The evil Java singleton

public class Evil { public static final Evil instance = new Evil (); private Evil () {} Evil getInstance() { return instance; } }

> In Groovy: @Singleton class Evil {}

> There’s also a « lazy » version @Singleton(lazy = true) class Evil {}

Page 22: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 22

@ImmutableThe Immutable… Boiler-Plate Code> To properly implement immutable classes

No mutators (state musn’t change) Private final fields Defensive copying of mutable components Proper equals() / hashCode() / toString() for

comparisons or for keys in maps, etc.

> In Groovy @Immutable final class Coordinates { Double lat, lng}def c1 = new Coordinates(lat: 48.8, lng: 2.5)def c2 = new Coordinates(48.8, 2.5)assert c1 == c2

Page 23: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 23

@LazyNot Just for Lazy Dudes!

> When you need to lazy evaluate / instantiate complex data structures for class fields, mark them as @Lazy class Dude { @Lazy pets = retrieveFromSlowDB()}

> Groovy will handle the boiler-plate code for you

Page 24: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 24

@DelegateNot Just for Managers! > You can delegate to fields of your class

Think multiple inheritance class Employee {

def doTheWork() { "done" }}class Manager { @Delegate Employee slave = new Employee()}def god = new Manager()assert god.doTheWork() == "done"

> Damn manager who will get all the praise…

Page 25: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 25

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 26: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette image.

26

Grab a GrapeGroovy Advanced Packaging Engine> Helps you distribute scripts without dependencies> Just declare your dependencies with @Grab

Will look for dependencies in Maven or Ivy repositories

> @Grab(group = 'org.mortbay.jetty', module = 'jetty-embedded', version = '6.1.0')def startServer() { def srv = new Server(8080) def ctx = new Context(srv , "/", SESSIONS); ctx.resourceBase = "." ctx.addServlet(GroovyServlet, "*.groovy") srv.start()}

Page 27: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 27

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 28: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 28

@Bindable (1/2)Event-Driven Made Easy> Speaking of boiler-plate code… property change listeners> import java.beans.PropertyChangeSupport;

import java.beans.PropertyChangeListener;public class MyBean { private String prop; PropertyChangeSupport pcs = new PropertyChangeSupport(this); public void addPropertyChangeListener(PropertyChangeListener l) { pcs.add(l); } public void removePropertyChangeListener(PropertyChangeListener l) { pcs.remove(l); }

public String getProp() { return prop;

} public void setProp(String prop) {

pcs.firePropertyChanged("prop", this.prop, this.prop = prop); }}

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

Page 29: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 29

@Bindable (2/2)Event-Driven Made Easy> Groovy’s solution

class MyBean { @Bindable String prop}

> Interesting in Griffon and Swing builder textField text: bind { myBean.prop }

> Also of interest: @Vetoable

Page 30: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 30

GriffonThe Swing MVC Framework

> Leverages Groovy’s SwingBuilder and Grails’ infrastructure http://griffon.codehaus.org

> Don’t miss the “Griffon in Depth” BOF-5189! Wednesday 8:45pm, Gateway 104

QuickTim e™ et undécompresseur

sont requis pour vis ionner cette im age.

Page 31: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 31

Swing Console Improvements

> The console can be run as an applet> Code indentation support> Script drag’n drop> Add JARs in the classpath from the GUI> Execution results visualization plugin> Clickable stacktraces and error messages

> Not intended to be a full-blown IDE, but handy

Page 32: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 32

QuickTim e™ et undécompresseur

sont requis pour vis ionner cette im age.

QuickTim e™ et undécom presseur

sont requis pour vis ionner cette im age.

Page 33: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 33

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 34: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 34

ExpandoMetaClass DSLLess Repetition> EMC is a way to change the behavior of types at runtime

> Before Number.metaClass.multiply = { Amount amount ->

amount.times(delegate) }Number.metaClass.div = { Amount amount -> amount.inverse().times(delegate) }

> Now in Groovy 1.6 Number.metaClass {

multiply { Amount amount -> amount.times(delegate) } div { Amount amount -> amount.inverse().times(delegate) }}

Page 35: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 35

Runtime MixinsInject New Behavior to Types at Runtime

> class FlyingAbility { def fly() { "I'm ${name} and I fly!" }}class JamesBondVehicle { String getName() { "James Bond's vehicle" }}JamesBondVehicle.mixin FlyingAbilityassert new JamesBondVehicle().fly() == "I'm James Bond's vehicle and I fly!"

Page 36: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 36

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 37: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 37

javax.script.* Scripting APIsGroovy Scripting Engine Built-In> In Groovy 1.6, the JSR-223 / javax.script.*

scripting engine for Groovy is bundled

import javax.script.*def manager = new ScriptEngineManager()def engine = manager.getEngineByName("groovy")assert engine.evaluate("2 + 3") == 5

> To evaluate Groovy scripts at runtime in your application, just drop the Groovy JAR in your classpath!

Page 38: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 38

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 39: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 39

JMX Builder (1/2)Domain-Specific Language for JMX> Simplify JMX handling with a Builder pattern approach> Declaratively expose Java/Groovy objects as MBeans> JMX's event model support

Inline closures to create event handler & broadcaster Closures for receiving event notifications

> Provides a flexible registration policy for MBean> Exposes attribute, constructors, operations, parameters,

and notifications> Simplified creation of connector servers & clients> Support for exporting JMX timers

> http://groovy.codehaus.org/Groovy+JmxBuilder

Page 40: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 40

JMX Builder (2/2)Examples> Create a connector server

def jmx = new JmxBuilder()jmx.connectorServer(port:9000).start()> Create a connector client

jmx.connectorClient(port:9000).connect()> Export a bean

jmx.export { bean new MyService() } > Defining a timer

jmx.timer(name: "jmx.builder:type=Timer", event: "heartbeat", period: "1s").start()

> JMX listener jmx.listener(event: "…", from: "foo",

call: { event -> …})

Page 41: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 41

Agenda> Groovy Overview> Performance Improvements> Syntax Enhancements> Compile-Time Metaprogramming> The Grape Module System> Swing-Related Improvements> Runtime Metaprogramming Additions> JSR-223 Scripting Engine Built-In> JMX Builder> OSGi Readiness

Page 42: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 42

OSGi Readiness

> The Groovy JAR contains OSGi metadata Can be reused in OSGi containers out-of-the-box

> Tutorials on Groovy and OSGi http://groovy.codehaus.org/OSGi+and+Groovy Will show you how to load Groovy as a service,

write, publish and consume Groovy services, and more

Page 43: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTim e™ et undécom presseur

sont requis pour vis ionner cette im age.

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

Summary

Page 44: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age.

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

44

SummaryJust Remember that Groovy Rocks! :-)> Groovy 1.6 provides

Important performance gains Efficient compile-time metaprogramming hooks New useful features (JMX, javax.script.*, etc.) A script dependencies system Various Swing-related improvements Several runtime metaprogramming additions

> Get it now! http://groovy.codehaus.org/Download

Page 45: What’s new in Groovy 1€¦ · What’s new in Groovy 1.6? Article Published by InfoQ > This presentation was prepared with the examples ... > Read this article for more detailed

QuickTime™ et undécompresseur

sont requis pour visionner cette image.

QuickTime™ et undécompresseur

sont requis pour vis ionner cette im age. 45

Guillaume [email protected]