SlideShare uma empresa Scribd logo
1 de 56
Baixar para ler offline
An Introduction to Groovy
                          and the New Features in 1.6

                            Get started with Groovy and learn about
                             all the novelties in the latest release

                                                     Guillaume Laforge
                                                 Head of Groovy Development

Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Guillaume Laforge
  Groovy 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…



                                                                                                                     2
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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



                                                                                                                     3
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     4
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovy in a Nutshell
  Simplify the Life of Java Developers

         Groovy is a dynamic language for the JVM
   >

               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
         




                                                                                                                     5
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
• Are you a Groovy developer?




                                                                                                                     6
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
• Ok, so, are you a Java developer?




                                                                                                                     7
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
• Then, yes, you are a Groovy developer!

   •Any Java developer is a
    also a Groovy developer!




                                                                                                                     8
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
A Taste of Groovy — Take 1
  A 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 quot;Hello quot; + name;
                    }
                    public static void main(String[] args) {
                        HelloWorld helloWorld = new HelloWorld();
                        helloWorld.setName(quot;Groovyquot;);
                        System.out.println( helloWorld.greet() );
                    }
         }




                                                                                                                     9
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
A Taste of Groovy — Take 2
  A 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 quot;Hello quot; + name;
                    }
                    public static void main(String[] args) {
                        HelloWorld helloWorld = new HelloWorld();
                        helloWorld.setName(quot;Groovyquot;);
                        System.out.println( helloWorld.greet() );
                    }
         }




                                                                                                                     10
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
A Taste of Groovy — Take 3
  A Groovier Program!

         class HelloWorld {
   >

             String name
             String greet() { quot;Hello $namequot; }
         }

         def helloWorld = new HelloWorld(name: quot;Groovyquot;)
         println helloWorld.greet()




                                                                                                                     11
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Groovy Web Console
  A 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/
         




                                                                                                                     12
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
The Groovy Web Console
  A Screenshot




                                                                                                                     13
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Features at a Glance

               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



                                                                                                                     14
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Joint Compilation

   • Total Java interoperability
   • Concretely, what does it mean?


                                                             JInterface                                               GInterface


                                                                                                                     <<implements>>
                                                           <<implements>>


                                                                                                                        JClass
                                                               GClass




                                                                                                                        GClass
                                                                JClass




                                                                                                                                      15
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Native Syntax Constructs

   • Lists
           – def numbers = [1, 2, 3, 4, 5]

   • Maps
           – def map = [FR: ‘France’, BE: ‘Belgium’]

   • Ranges
           – def allowed = 18..65

   • Regular expressions
           – def whitespace = ~/s+?/
           – if (‘foo’ ==~ /o+/) { ... }


                                                                                                                     16
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
GStrings!

   • GStrings are... interpolated strings
           – Sorry, not really what you expected!
           – Placeholder variables are replaced
           – You can have multiline strings


   • def person = ‘John’
     def letter = “““${new Date()}
         Dear ${person},
         I hope you’re fine!
     ”””




                                                                                                                     17
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Closures

   • Closures are reusable and assignable code blocks or
     anonymous functions
           – No need to wait for Java 7/8/9 to get them!
           – def greet = { println “Hello ${it}” }
             greet(“Guillaume”)

   • You can pass parameters
           – def greet = { String name ->
                 println “Hello ${name}”
             }

   • You can passe closures around
           – def method(Closure c) { c(“Hello”) }
             method(greet)

                                                                                                                     18
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
BigDecimal Arithmetic

   • Main reason why financial institutions often decide
     to use Groovy for their business rules!
           – Although these days rounding issues are overrated!

   • Java vs Groovy for a simple interpolation equation

   • BigDecimal uMinusv = c.subtract(a);
     BigDecimal vMinusl = b.subtract(c);
     BigDecimal uMinusl = a.subtract(b);
     return e.multiply(uMinusv)
                 .add(d.multiply(vMinusl))
                 .divide(uMinusl, 10, BigDecimal.ROUND_HALF_UP);

   • (d * (b - c) + e * (c - a)) / (a - b)



                                                                                                                     19
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Groovy Builders

   • The Markup builder
           – Easy way for creating XML or HTML content

           – def mkp = new MarkupBuilder()
             mkp.html {
                 head {
                     title “Groovy in Action”
                 }
                 body {
                     div(width: ‘100’) {
                         p(class: ‘para’) {
                             span “Best book ever!”
                         }
                     }
                 }
             }
                                                                                                                     20
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Parsing XML

   • And it’s so easy to parser XML and navigate through
     the node graph!

   • def geocodingUrl = quot;http://...quot;.toURL()
     geocodingUrl.withInputStream { stream ->
         def node = new XmlSlurper().parse(stream)
         if (node.Response.Status.code == quot;200quot;) {
             def text = node.Response.Placemark.
                        Point.coordinates.text()
             def coord = text.tokenize(',').
                         collect{ Float.parseFloat(it) }
             (latitude, longitude) = coord[1..0]
         }
     }



                                                                                                                     21
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     22
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Performance Improvements
  Both Runtime & Compile-Time

         The Groovyc compiler is 3x to 5x faster
   >

               With a clever class lookup cache
         




         Certain online micro-benchmarks show
   >
         150% 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




                                                                                                                     23
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     24
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Multiple Assignment
  Assign Multiple Variables at Once

         Newly defined variables
   >
               def (a, b) = [1, 2]
         
               assert a == 1
               assert 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
   >


                                                                                                                     25
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
More Optional Return
  In 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(quot;fooquot;)
                       1
                   } catch(e) { 2 }
                   finally    {3}
               }
               assert method(false) == 1
               assert method(true) == 2



                                                                                                                     26
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Annotation Definition
  The 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…




                                                                                                                     27
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     28
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
         




                                                                                                                     29
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
AST Transformations in Groovy 1.6
  Implement 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!
   >




                                                                                                                     30
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
@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 {}
         


                                                                                                                     31
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
@Immutable
  The 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



                                                                                                                     32
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
@Lazy
  Not 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 = retriveFromSlowDB()
               }

         Groovy will handle the boiler-plate code for you
   >




                                                                                                                     33
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
@Delegate
  Not Just for Managers!

         You can delegate to fields of your class
   >

               Think multiple inheritance
         

               class Employee {
         

                   def doTheWork() { quot;donequot; }
               }

               class Manager {
                   @Delegate
                   Employee slave = new Employee()
               }
               def god = new Manager()
               assert god.doTheWork() == quot;donequot;


         Damn manager who will get all the praise…
   >



                                                                                                                     34
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     35
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Grab a Grape
  Groovy 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 , quot;/quot;, SESSIONS)
             ctx.resourceBase = quot;.quot;
             ctx.addServlet(GroovyServlet, quot;*.groovyquot;)
             srv.start()
         }


                                                                                                                     36
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     37
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
@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(quot;propquot;, this.prop, this.prop = prop);
                  }
           }


                                                                                                                     38
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
@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
   >




                                                                                                                     39
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Griffon
  The Swing MVC Framework


         Leverages Groovy’s SwingBuilder
   >
         and Grails’ infrastructure

               http://griffon.codehaus.org
         




                                                                                                                     40
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
   >




                                                                                                                     41
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
42
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >




                                                                                                                     43
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
ExpandoMetaClass DSL
  Less 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) }
               }



                                                                                                                     44
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Runtime Mixins
  Inject New Behavior to Types at Runtime

         class FlyingAbility {
   >

             def fly() { quot;I'm ${name} and I fly!quot; }
         }

         class JamesBondVehicle {
             String getName() { quot;James Bond's vehiclequot; }
         }

         JamesBondVehicle.mixin FlyingAbility

         assert new JamesBondVehicle().fly() ==
             quot;I'm James Bond's vehicle and I fly!quot;




                                                                                                                     45
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     46
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
javax.script.* Scripting APIs
  Groovy 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(quot;groovyquot;)
               assert engine.evaluate(quot;2 + 3quot;) == 5

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


                                                                                                                     47
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     48
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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

                                                                                                                     49
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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: quot;jmx.builder:type=Timerquot;,
               

                         event: quot;heartbeatquot;, period: quot;1squot;).start()

               JMX listener
          >

                     jmx.listener(event: quot;…quot;, from: quot;fooquot;,
               

                         call: { event -> …})

                                                                                                                     50
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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
                                                                               >


                                                                                                                     51
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
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




                                                                                                                     52
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Summary




Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Summary
  Just Remember that Groovy Rocks! :-)

         Any Java developer is a Groovy developer!
   >

         Great for admin tasks, extending apps, writing DSLs
   >



         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
         




                                                                                                                     54
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
GR8 Conference

                                                           • If you wish to learn more about
                                                             Groovy, Grails and Griffon, register
                                                             for the GR8 Conference
                                                           • A conference dedicated to Groovy,
                                                             Grails, Griffon and other Groovy
                                                             related technologies
                                                           • Co-organized by SpringSource and the
                                                             Danish JUG (Javagruppen)
                                                           • Takes place in Copenhagen,
                                                             Denmark, on May 18th and 19th
                                                           • Use the code SPRING to get a
                                                             discount ;-)
                                                                                                                     55
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
Questions & Answers




Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

Mais conteúdo relacionado

Semelhante a Introduction to Groovy and New Features in 1.6

Groovy and Grails in Google App Engine
Groovy and Grails in Google App EngineGroovy and Grails in Google App Engine
Groovy and Grails in Google App EngineGuillaume Laforge
 
Groovy Online 100
Groovy Online 100Groovy Online 100
Groovy Online 100reynolds
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Scripting Support in GFv3 Prelude - Full Version
Scripting Support in GFv3 Prelude - Full VersionScripting Support in GFv3 Prelude - Full Version
Scripting Support in GFv3 Prelude - Full VersionEduardo Pelegri-Llopart
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenThorsten Kamann
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicCristiano Costantini
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleySven Haiges
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails IntroductionEric Weimer
 
Magic with groovy & grails
Magic with groovy & grailsMagic with groovy & grails
Magic with groovy & grailsGeorge Platon
 
Scripting Support in GlassFish v3 Prelude
Scripting Support in GlassFish v3 PreludeScripting Support in GlassFish v3 Prelude
Scripting Support in GlassFish v3 PreludeEduardo Pelegri-Llopart
 
2009 Java One State Of The Open Web
2009 Java One State Of The Open Web2009 Java One State Of The Open Web
2009 Java One State Of The Open WebPatrick Chanezon
 
Jcconf2014 roo and_grails
Jcconf2014 roo and_grailsJcconf2014 roo and_grails
Jcconf2014 roo and_grailsShin-Jan Wu
 
Introduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeopleIntroduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeopleSpringPeople
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13Fred Sauer
 

Semelhante a Introduction to Groovy and New Features in 1.6 (20)

Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
Groovy and Grails in Google App Engine
Groovy and Grails in Google App EngineGroovy and Grails in Google App Engine
Groovy and Grails in Google App Engine
 
Whats New In Groovy 1.6?
Whats New In Groovy 1.6?Whats New In Groovy 1.6?
Whats New In Groovy 1.6?
 
Groovy Online 100
Groovy Online 100Groovy Online 100
Groovy Online 100
 
Groovy & Grails
Groovy & GrailsGroovy & Grails
Groovy & Grails
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
Scripting Support in GFv3 Prelude - Full Version
Scripting Support in GFv3 Prelude - Full VersionScripting Support in GFv3 Prelude - Full Version
Scripting Support in GFv3 Prelude - Full Version
 
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and MavenWebtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
Webtests Reloaded - Webtest with Selenium, TestNG, Groovy and Maven
 
Gwt Presentation
Gwt PresentationGwt Presentation
Gwt Presentation
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 Panic
 
Grails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon ValleyGrails @ Java User Group Silicon Valley
Grails @ Java User Group Silicon Valley
 
Groovy And Grails Introduction
Groovy And Grails IntroductionGroovy And Grails Introduction
Groovy And Grails Introduction
 
Magic with groovy & grails
Magic with groovy & grailsMagic with groovy & grails
Magic with groovy & grails
 
Scripting Support in GlassFish v3 Prelude
Scripting Support in GlassFish v3 PreludeScripting Support in GlassFish v3 Prelude
Scripting Support in GlassFish v3 Prelude
 
2009 Java One State Of The Open Web
2009 Java One State Of The Open Web2009 Java One State Of The Open Web
2009 Java One State Of The Open Web
 
Jcconf2014 roo and_grails
Jcconf2014 roo and_grailsJcconf2014 roo and_grails
Jcconf2014 roo and_grails
 
GlassFish v3 Prelude Aquarium Paris
GlassFish v3 Prelude Aquarium ParisGlassFish v3 Prelude Aquarium Paris
GlassFish v3 Prelude Aquarium Paris
 
Introduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeopleIntroduction To Groovy And Grails - SpringPeople
Introduction To Groovy And Grails - SpringPeople
 
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
 
Groovy Maven Builds
Groovy Maven BuildsGroovy Maven Builds
Groovy Maven Builds
 

Mais de Guillaume Laforge

Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Guillaume Laforge
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Guillaume Laforge
 
Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Guillaume Laforge
 
Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Guillaume Laforge
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Guillaume Laforge
 
Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Guillaume Laforge
 
Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Guillaume Laforge
 
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Guillaume Laforge
 
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGroovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGuillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Guillaume Laforge
 
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Guillaume Laforge
 
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGuillaume Laforge
 
Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Guillaume Laforge
 
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Guillaume Laforge
 
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Guillaume Laforge
 

Mais de Guillaume Laforge (20)

Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013Lift off with Groovy 2 at JavaOne 2013
Lift off with Groovy 2 at JavaOne 2013
 
Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013Groovy workshop à Mix-IT 2013
Groovy workshop à Mix-IT 2013
 
Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013Les nouveautés de Groovy 2 -- Mix-IT 2013
Les nouveautés de Groovy 2 -- Mix-IT 2013
 
Groovy 2 and beyond
Groovy 2 and beyondGroovy 2 and beyond
Groovy 2 and beyond
 
Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012Groovy 2.0 update at Devoxx 2012
Groovy 2.0 update at Devoxx 2012
 
Groovy 2.0 webinar
Groovy 2.0 webinarGroovy 2.0 webinar
Groovy 2.0 webinar
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012Groovy Domain Specific Languages - SpringOne2GX 2012
Groovy Domain Specific Languages - SpringOne2GX 2012
 
Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012Groovy update at SpringOne2GX 2012
Groovy update at SpringOne2GX 2012
 
JavaOne 2012 Groovy update
JavaOne 2012 Groovy updateJavaOne 2012 Groovy update
JavaOne 2012 Groovy update
 
Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012Groovy 1.8 et 2.0 au BreizhC@mp 2012
Groovy 1.8 et 2.0 au BreizhC@mp 2012
 
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012Groovy 1.8 and 2.0 at GR8Conf Europe 2012
Groovy 1.8 and 2.0 at GR8Conf Europe 2012
 
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume LaforgeGroovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
Groovy 2.0 update - Cloud Foundry Open Tour Moscow - Guillaume Laforge
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 
Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012Groovy 2.0 - Devoxx France 2012
Groovy 2.0 - Devoxx France 2012
 
Whats new in Groovy 2.0?
Whats new in Groovy 2.0?Whats new in Groovy 2.0?
Whats new in Groovy 2.0?
 
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
Groovy Update, new in 1.8 and beyond - Guillaume Laforge - Devoxx 2011
 
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume LaforgeGPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
GPars et PrettyTime - Paris JUG 2011 - Guillaume Laforge
 
Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011Groovy Update - Guillaume Laforge - Greach 2011
Groovy Update - Guillaume Laforge - Greach 2011
 
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
Gaelyk update - Guillaume Laforge - SpringOne2GX 2011
 
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
Groovy Update, what's new in Groovy 1.8 and beyond - Guillaume Laforge - Spri...
 

Último

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Último (20)

The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Introduction to Groovy and New Features in 1.6

  • 1. An Introduction to Groovy and the New Features in 1.6 Get started with Groovy and learn about all the novelties in the latest release Guillaume Laforge Head of Groovy Development Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 2. Guillaume Laforge Groovy 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… 2 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 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 3 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 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 > 4 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 5. Groovy in a Nutshell Simplify the Life of Java Developers Groovy is a dynamic language for the JVM > 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  5 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 6. • Are you a Groovy developer? 6 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 7. • Ok, so, are you a Java developer? 7 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 8. • Then, yes, you are a Groovy developer! •Any Java developer is a also a Groovy developer! 8 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 9. A Taste of Groovy — Take 1 A 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 quot;Hello quot; + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } 9 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 10. A Taste of Groovy — Take 2 A 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 quot;Hello quot; + name; } public static void main(String[] args) { HelloWorld helloWorld = new HelloWorld(); helloWorld.setName(quot;Groovyquot;); System.out.println( helloWorld.greet() ); } } 10 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 11. A Taste of Groovy — Take 3 A Groovier Program! class HelloWorld { > String name String greet() { quot;Hello $namequot; } } def helloWorld = new HelloWorld(name: quot;Groovyquot;) println helloWorld.greet() 11 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 12. The Groovy Web Console A 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/  12 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 13. The Groovy Web Console A Screenshot 13 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 14. Features at a Glance 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 14 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 15. Joint Compilation • Total Java interoperability • Concretely, what does it mean? JInterface GInterface <<implements>> <<implements>> JClass GClass GClass JClass 15 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 16. Native Syntax Constructs • Lists – def numbers = [1, 2, 3, 4, 5] • Maps – def map = [FR: ‘France’, BE: ‘Belgium’] • Ranges – def allowed = 18..65 • Regular expressions – def whitespace = ~/s+?/ – if (‘foo’ ==~ /o+/) { ... } 16 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 17. GStrings! • GStrings are... interpolated strings – Sorry, not really what you expected! – Placeholder variables are replaced – You can have multiline strings • def person = ‘John’ def letter = “““${new Date()} Dear ${person}, I hope you’re fine! ””” 17 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 18. Closures • Closures are reusable and assignable code blocks or anonymous functions – No need to wait for Java 7/8/9 to get them! – def greet = { println “Hello ${it}” } greet(“Guillaume”) • You can pass parameters – def greet = { String name -> println “Hello ${name}” } • You can passe closures around – def method(Closure c) { c(“Hello”) } method(greet) 18 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 19. BigDecimal Arithmetic • Main reason why financial institutions often decide to use Groovy for their business rules! – Although these days rounding issues are overrated! • Java vs Groovy for a simple interpolation equation • BigDecimal uMinusv = c.subtract(a); BigDecimal vMinusl = b.subtract(c); BigDecimal uMinusl = a.subtract(b); return e.multiply(uMinusv) .add(d.multiply(vMinusl)) .divide(uMinusl, 10, BigDecimal.ROUND_HALF_UP); • (d * (b - c) + e * (c - a)) / (a - b) 19 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 20. Groovy Builders • The Markup builder – Easy way for creating XML or HTML content – def mkp = new MarkupBuilder() mkp.html { head { title “Groovy in Action” } body { div(width: ‘100’) { p(class: ‘para’) { span “Best book ever!” } } } } 20 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 21. Parsing XML • And it’s so easy to parser XML and navigate through the node graph! • def geocodingUrl = quot;http://...quot;.toURL() geocodingUrl.withInputStream { stream -> def node = new XmlSlurper().parse(stream) if (node.Response.Status.code == quot;200quot;) { def text = node.Response.Placemark. Point.coordinates.text() def coord = text.tokenize(','). collect{ Float.parseFloat(it) } (latitude, longitude) = coord[1..0] } } 21 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 22. 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 > 22 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 23. Performance Improvements Both Runtime & Compile-Time The Groovyc compiler is 3x to 5x faster > With a clever class lookup cache  Certain online micro-benchmarks show > 150% 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 23 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 24. 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 > 24 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 25. Multiple Assignment Assign Multiple Variables at Once Newly defined variables > def (a, b) = [1, 2]  assert a == 1 assert 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 > 25 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 26. More Optional Return In 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(quot;fooquot;) 1 } catch(e) { 2 } finally {3} } assert method(false) == 1 assert method(true) == 2 26 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 27. Annotation Definition The 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… 27 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 28. 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 > 28 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 29. 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  29 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 30. AST Transformations in Groovy 1.6 Implement 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! > 30 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 31. @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 {}  31 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 32. @Immutable The 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 32 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 33. @Lazy Not 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 = retriveFromSlowDB() } Groovy will handle the boiler-plate code for you > 33 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 34. @Delegate Not Just for Managers! You can delegate to fields of your class > Think multiple inheritance  class Employee {  def doTheWork() { quot;donequot; } } class Manager { @Delegate Employee slave = new Employee() } def god = new Manager() assert god.doTheWork() == quot;donequot; Damn manager who will get all the praise… > 34 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 35. 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 > 35 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 36. Grab a Grape Groovy 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 , quot;/quot;, SESSIONS) ctx.resourceBase = quot;.quot; ctx.addServlet(GroovyServlet, quot;*.groovyquot;) srv.start() } 36 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 37. 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 > 37 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 38. @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(quot;propquot;, this.prop, this.prop = prop); } } 38 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 39. @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 > 39 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 40. Griffon The Swing MVC Framework Leverages Groovy’s SwingBuilder > and Grails’ infrastructure http://griffon.codehaus.org  40 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 41. 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 > 41 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 42. 42 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 43. 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 > 43 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 44. ExpandoMetaClass DSL Less 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) } } 44 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 45. Runtime Mixins Inject New Behavior to Types at Runtime class FlyingAbility { > def fly() { quot;I'm ${name} and I fly!quot; } } class JamesBondVehicle { String getName() { quot;James Bond's vehiclequot; } } JamesBondVehicle.mixin FlyingAbility assert new JamesBondVehicle().fly() == quot;I'm James Bond's vehicle and I fly!quot; 45 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 46. 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 > 46 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 47. javax.script.* Scripting APIs Groovy 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(quot;groovyquot;) assert engine.evaluate(quot;2 + 3quot;) == 5 To evaluate Groovy scripts at runtime in your > application, just drop the Groovy JAR in your classpath! 47 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 48. 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 > 48 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 49. 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 49 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 50. 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: quot;jmx.builder:type=Timerquot;,  event: quot;heartbeatquot;, period: quot;1squot;).start() JMX listener > jmx.listener(event: quot;…quot;, from: quot;fooquot;,  call: { event -> …}) 50 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 51. 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 > 51 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 52. 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 52 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 53. Summary Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 54. Summary Just Remember that Groovy Rocks! :-) Any Java developer is a Groovy developer! > Great for admin tasks, extending apps, writing DSLs > 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  54 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 55. GR8 Conference • If you wish to learn more about Groovy, Grails and Griffon, register for the GR8 Conference • A conference dedicated to Groovy, Grails, Griffon and other Groovy related technologies • Co-organized by SpringSource and the Danish JUG (Javagruppen) • Takes place in Copenhagen, Denmark, on May 18th and 19th • Use the code SPRING to get a discount ;-) 55 Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.
  • 56. Questions & Answers Copyright 2009 SpringSource. Copying, publishing or distributing without express written permission is prohibited.