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
It's all about choosing the right tool for the job and leveraging it correctly - Neal Ford
Scala
Jython
Clojure
DynJS
Rhino
Groovy
It is tempting, if the only tool you have is a hammer, to treat everything as if it were a nail - Abraham Maslow
You get true multithreading that can use all your computer’s cores from one process, plus a virtual machine that’s been tuned for a decade and a half.###### *Using JRuby - Bringing Ruby to Java*
Low memory footprint
Modular class loading
Fast startup time
EE6 compliant
The power of JBoss with the expressiveness of Ruby Jim Crossley - MagicRuby Conference
class BeersController < ApplicationController
caches_action :most_popular, :expires_in => 30.seconds
def most_popular
@popular_beers = Beer.most_popular(:limit => 25)
end
end
We write Java so you don't have to### Patches are always welcome :)
class TorqueBoxCommand < Thor
map "run" => "start"
method_option :clustered, :type => :boolean,
def start
setup_environment
TorqueBox::DeployUtils.run_server(:clustered => options.clustered,
:max_threads => options['max-threads'],
:bind_address => options['bind-address'])
end
end
module Beer
class Application < Rails::Application
config.cache_store = :torque_box_store
end
end
module Beer
class Application < Rails::Application
config.cache_store = :torque_box_store, {
:mode => replicated, :sync =>false
end
end
Ruby ruby = null;
try {
ruby = this.runtimePool.borrowRuntime( resolver.getComponentName());
JobComponent job = (JobComponent)resolver.resolve( ruby );
job.run(); //Call ruby method
} catch (Exception e) {
throw new JobExecutionException( e );
} finally {
if (ruby != null) {
this.runtimePool.returnRuntime( ruby );
}
}
class EmailerTask < TorqueBox::Messaging::Task def send_welcome(payload) to = "#{payload[:name]} <#{payload[:address]}>" # send welcome email to the user end end
class UserController < ApplicationController
def register
user = User.new(params[:user])
EmailerTask.async(:send_welcome, :address => user.email,
:name => user.name)
end
end
include TorqueBox::Messaging
class PrintHandler < MessageProcessor
def on_message(body)
puts "Processing #{body} of #{message}"
end
def configure(opts)
@color = opts['color']
end
end
include TorqueBox
req = Messaging::Queue.new '/queues/questions'
res = Messaging::Queue.new '/queues/answers'
Thread.new do
req.publish "What time is it?"
puts res.receive( :timeout => 1000 )
end
class EmailerTask
def send_welcome(payload)
to = "#{payload[:name]} <#{payload[:address]}>"
# long running task
end
end
class EmailerTask
include TorqueBox::Messaging::Backgroundable
always_background :send_welcome
def send_welcome(payload)
to = "#{payload[:name]} <#{payload[:address]}>"
# long running task
end
end
class BeerService
def initialize
@queue = Messaging::Queue.new(“beer”)
end
def start
@queue.publish “Buy me a beer”
end
def stop
# What happens when the service stops
end
end
services:
BeerService:
config:
singleton: true
package br.com.rockandrails;
@ApplicationScoped
public class Beer {
//gets e sets
public void say(String message) { // Some code here
### Jar deployment
app/
lib/beer.jar
models/
views/
controllers/
class BeerController < ApplicationController
include TorqueBox::Injectors
def create
beer = inject( Java::br.com.rockandrails.Beer )
beer.say “Inject my beer!”
end
end
class MyService
include TorqueBox::Injectors
def initialize opts={}
@factory = inject("java:comp/env/jdbc/myDB")
end
end
class MyService
include TorqueBox::Injectors
def initialize opts={}
@inbound = inject("/topic/beerpub")
@outbound = inject("/queue/beer")
end
end
require 'torquebox-stomp'
class BeerStomplet < TorqueBox::Stomp::JmsStomplet
def configure(options)
super
@queue = TorqueBox::Messaging::Queue.new( options['/queue/beer'] )
end
def on_subscribe(subscriber)
# session is available via subscriber.session
subscribe_to( subscriber, @queue )
end
end
var url = "ws://localhost:8675/stomp";
var client = Stomp.client(url);
client.connect(login, passcode, connect_callback);
connect_callback = function() {
// called back after the client is connected to the STOMP server
};
### Thanks @jmesnil!
[http://www.jmesnil.net/stomp-websocket/doc/](http://www.jmesnil.net/stomp-websocket/doc/)
auth:
default:
domain: torquebox
credentials:
homer: simpson
require 'torquebox'
require 'torquebox-security'
class LoginController < ApplicationController
def create
usuario = params[:usuario]
senha = params[:senha]
redirect_to login_path if usuario.blank? || senha.blank?
authenticator = TorqueBox::Authentication.default
if authenticator.authenticate(usuario, senha)
puts "Autenticado com sucesso"
redirect_to contatos_path
else
mensagem = "Nao autorizado"
redirect_to login_path
end
end
end