JBoss Polyglot

Enterprise applications beyond Java

TDC 2012

@abstractj

DISCLAIMER

Java

~ Only 927 JSRs :)

Enterprise

WAR JAX-RPC Struts Spring JAAS EJB JNI EAR SOA JPQL CDI GWT JAX-WS JSF JavaFX JNDI RMI JMX JAXP JAXB JDO JAX-RS JAXR JSTL StAX JAF JDOM AWT Swing JEE JSE JCP JVM JME NIO JSP JRE POJO JavaBean EJBQL

Java

I <3 Java!

Java

  • Several APIs
  • IDE: Eclipse, NetBeans...
  • Ant, Maven
  • The prime JVM language

Customers don't care!

JVM

The land of languages

  • Same memory model,
  • GC, threading, JIT
  • Zero-compile installs
  • Static and dynamic languages

~ 200 JVM languages

  • JRuby
  • Clojure
  • Scala
  • Ceylon
  • Jython
  • Rhino
  • DynJS
  • Is Java dead?!

    Programming

    It's all about choosing the right tool for the job and leveraging it correctly - Neal Ford

    Polyglot programming

    Polyglotism is the worst idea I ever heard - B. Burke

    AS7

    • Low memory footprint
    • Modular class loading
    • Fast startup time
    • EE6 compliant

    AS7

    • HornetQ
    • Infinispan
    • Clustering
    • Transaction
    • Several years on JEE

    My friends

    JBoss Polyglot

    Why Polyglot?

    To be happy!

    JBoss Polyglot will Replace Java?

    NO! NO! NO!

    JRuby

    JAVA

    
    for(int i=10; i>=1; i--) {
        System.out.print(i + " - ");
    }
    

    Ruby

    10.downto(1) { |n| print n, " - " }
    

    Ruby & Java

    require 'java' 
    pdf = com.itextpdf.text.Document.new  
    para = com.itextpdf.text.Paragraph.new 'JRuby Chapter'  
    file = java.io.FileOutputStream.new 'pdf_demo.pdf' 
    com.itextpdf.text.pdf.PdfWriter.get_instance pdf, file 
    
    pdf.open  
    pdf.add para  
    pdf.close
    

    TorqueBox

    The power of JBoss with the expressiveness of Ruby - Jim Crossley

    TorqueBox

    Getting started

    TorqueBox 2.0

    http://vimeo.com/33299335

    NO WAR!

    WEB

    Rails, Rack & Sinatra support

    A new app

    torquebox rails new beer

    To already existing apps

    torquebox rails beer

    WEB

    class BeersController < ApplicationController 
      caches_action :most_popular, :expires_in => 30.seconds 
    
      def most_popular 
        @popular_beers = Beer.most_popular(:limit => 25) 
      end 
    end

    Scheduling

    Agendamento de Jobs

    ../app/jobs

    class JobDemo 
        def initialize 
            #Initialize any variable here
        end 
    
        def run 
            # Run some my job
        end 
    end 

    YAML FILE

    #torquebox.yml file
    jobs:
      sync_agenda:
        job:  JobDemo 
        cron: '0 0 12 * * ?'
    

    Async tasks

    Backgroundable

    class EmailerTask
      include TorqueBox::Messaging::Backgroundable
      always_background :send_welcome
    
      def send_welcome 
        # long running task 
      end 
    end
    

    CDI

    Dependency Injection

    Java

     /* A simple Java example */ 
    package br.com.tdc2012;
    @ApplicationScoped
    public class Beer {  
        //gets e sets 
        public void say(String message)  { // Execução do método }
    

    Ruby

    # Injecting Java class
    class BeerController < ApplicationController
        include TorqueBox::Injectors
        def create
            beer = inject( Java::br.com.tdc2012.Beer ) 
            beer.say "Ruby is for Java"
        end
    end

    Messaging

    JMS + HornetQ

    Messaging

    # Injecting queues
    class MyService 
      include TorqueBox::Injectors
      def initialize
        @inbound = inject("/topic/beerpub")
        @outbound = inject("/queue/beer") 
      end 
    end

    Messaging

    # Processing messages
    include TorqueBox::Messaging 
    class PrintHandler < MessageProcessor 
      def on_message(body) 
        #Do something with the message
      end 
    end

    Services

    class BeerService 
      def initialize 
        @queue = Messaging::Queue.new(“beer”)
      end
      def start 
        @queue.publish “Testing” 
      end 
      def stop # Do something here 
      end 
    end

    Configuration

    services:
      BeerService:
        singleton:  true 
    end 
    

    Clustering

    ➜ torquebox run --clustered

    Skipped

    • XA 2PC
    • WebSockets
    • Authentication
    • Infinispan (Cache 2nd level)

    Clojure

    • LISP for JVM
    • Funcional -> Immutability by default
    • Friendly Java integration
    • Software transactional memory(STM)

    Java

    for(int i=10; i>=1; i--) {
        System.out.print(i + " - ");
    }
    

    Clojure

    (clojure.string/join " - " (range 10 0 -1))

    Clojure & Java

    (import 'java.net.URL)
    (def tdc (URL. "http://www.thedevelopersconference.com.br"))
    (.getHost tdc)
    

    Immutant

    Yep! A flying frog!

    Immutant

    Immutant is an Application Server for Clojure being built on top of JBoss AS7 - T. Crawley

    Haters gonna hate!

    Leiningen

    Basics

    • lein deps
    • lein plugin install...
    • lein repl
    • lein test

    Installation

    ➜ lein plugin install lein-immutant LATEST
    ➜ lein immutant install LATEST

    Alternative

    Download from http://immutant.org/builds/

    ➜ unzip immutant-dist-bin.zip
    ➜ export IMMUTANT_HOME=/path/to/immutant-1.x.incremental

    NEW APP

    ➜ lein immutant new beer

    project.clj

    (defproject beer "1.0.0-SNAPSHOT"
      :description "FIXME: write description"
      :dependencies [[org.clojure/clojure "1.3.0"]])

    immutant.clj

    (ns beer.init
      ;(:use beer.core)
      (:require [immutant.messaging :as messaging]
                [immutant.web :as web]))
    

    Deploy

    ➜ cd beer
    ➜ lein immutant deploy
    

    WEB

    Noir support

    (ns beer.init
      (:use beer.core)
      (:require [immutant.web :as web]
                [noir.server :as server]
                [beer.core :as core]))
    
    (server/load-views (str (web/src-dir) "/beer/views"))
    (web/start "/" (server/gen-handler {:mode :dev :ns 'beer}))

    WEB

    Ring support

    (ns beer.init
      (:use beer.core)
      (:require [immutant.web :as web]
                [beer.core :as core]))
    ; Register a handler request
    (defn app [request])
    (web/start "/" app)

    Messaging

    
    (:require [immutant.messaging :as messaging])
        (def myqueue "/queue/myqueue")
        (msg/start myqueue)
        (msg/publish myqueue "This is polyglot love")
        (println(msg/receive myqueue))

    Daemons

    (ns beer.init
      (:use beer.core)
      (:require [immutant.daemons :as daemon]
                [immutant.messaging :as messaging]))
    
    (messaging/start "/queue/beers")
    (daemon/start "beerdaemon" #())
    

    Scheduling

    (ns beer.ns
      (:require [immutant.jobs :as jobs]))
    
    (jobs/schedule "beer-job" "*/2 * * * * ?" 
        #(println "Job was called!")
        :singleton false)

    Skipped

    • Caching with Infinispan
    • XA 2PC
    • Interactive development

    Present!

    Passionate OSS dev +


    + invokedynamic + idea + Braziljs 2011

    DynJS Compiler

    Passionate OSS dev +


    THE ANTLR guy


    ES3 Grammar!

    NO vaporware!

    DynJS development

    ASJS on JBW!

    ASJS

    JBoss + JavaScript

    on steroids

    What's next?!

    • DynJS 1.0
    • ASJS first release
    • Immutant improvements

    Community

    irc.freenode.net

    • TorqueBox, Immutant, dynjs, aerogear
    • http://immutant.org/
    • http://torquebox.org/
    • http://dynjs.org/
    • http://jboss.org/aerogear

    Thanks

    @abstractj