CRaSH the shell for the Java Virtual Machine
description
Transcript of CRaSH the shell for the Java Virtual Machine
w w w . c r a s h u b . o r g
CRaSH The shell for the JVM
w w w . c r a s h u b . o r g
Julien Viet exoplatform
w w w . c r a s h u b . o r g
All semicolons characters appearing in this work are fictitious. Any resemblance to real characters, living or dead, is purely coincidental.
Disclaimer
w w w . c r a s h u b . o r g
http://www.julienviet.com / @julienviet
10 years of portal development (you know Portlets…)
Working at eXoPlatform delivering enterprise social networks
> me --verbose
w w w . c r a s h u b . o r g
You can use @crashub or #crashub Try it online try.crashub.org/gists/
e61cb08d93746e576209 (pro tip follow @crashub)
About this talk
w w w . c r a s h u b . o r g
Once upon a time …
Why did I do that ? what is CRaSH
w w w . c r a s h u b . o r g
Latest 1.2.9 / 1.3.0-cr5
Java 6+ / Groovy 1.7+
Base commands : jdbc, jmx, thread, jpa, log, etc..
Extensions: mail, cron
CRaSH
w w w . c r a s h u b . o r g
Modes Standalone / attach (download / brew / gvm) Embedded
Connectors jvm (standalone & attach) ssh, telnet crash.js over websocket
Concepts
w w w . c r a s h u b . o r g
Standalone mode
w w w . c r a s h u b . o r g
Return "hello world"
Command script
w w w . c r a s h u b . o r g
class helloworld { @Command String main() { return "Hello World" } }
Command class
w w w . c r a s h u b . o r g
class hello { @Command String world() { return "Hello World" } }
Git style
w w w . c r a s h u b . o r g
Command pipelining
w w w . c r a s h u b . o r g
Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface.
- Ken Thompson
Unix philosophy
w w w . c r a s h u b . o r g
% thread ls | thread dump | mail -s "something you should look at" [email protected]
Pipeline example
w w w . c r a s h u b . o r g
<Void, Thread> is a producer
<Thread, Object> is a pipe <String, String> is a pipe
Pipeline example
w w w . c r a s h u b . o r g
class daemon { @Command Pipe<Thread, Thread> main() { [provide: { if (it.daemon) context.provide(it) }] as Pipe<Thread, Thread> } }
Pipe command
w w w . c r a s h u b . o r g
# log ls -f org.crsh.* | log send -m "hello"
# system propls | filter -p NAME:java.* | sort -f NAME
# jmx query -p java.lang:type=GarbageCollector,name=* | jmx get -a Name -a CollectionCount -a CollectionTime
Other examples
w w w . c r a s h u b . o r g
Read Eval Print Loop aka REPL
w w w . c r a s h u b . o r g
By default the script REPL parses CLI familiar for most CLI users
Script REPL
w w w . c r a s h u b . o r g
very much like groovysh evaluates Groovy expressions
DSL for creating CLI
compose pipes and closures
New Groovy REPL since 1.3
w w w . c r a s h u b . o r g
% (thread.ls | thread.dump | mail { S="something you should look at” "[email protected]" })()
Our command pipeline in Groovy
w w w . c r a s h u b . o r g
More cool stuff
w w w . c r a s h u b . o r g
Completers
Renderers
Keyboard: interruption / events
Screen: streaming / styling
More cool stuff
w w w . c r a s h u b . o r g
Attach mode
w w w . c r a s h u b . o r g
Embedding CRaSH
w w w . c r a s h u b . o r g
Bootstrap: programmatic / Spring / Servlet
Designed for embedding Lighweight : core jar about 600kb Modular : pay for what you need
Virtual File System integration
Embedding
w w w . c r a s h u b . o r g
Ecosystem
w w w . c r a s h u b . o r g
Created in Nov 2012 by Stephan Jaetzold
Contributions by Burt Beckwith
Recently updated to CRaSH 1.3 with additional features
Grails Plugin
w w w . c r a s h u b . o r g
And the story just begins
w w w . c r a s h u b . o r g
Multi facet, powerful and extensible tool for all of us
Join the community www.crashub.org @crashub [email protected]
Wrap up
w w w . c r a s h u b . o r g
Extra slides
w w w . c r a s h u b . o r g
new UIBuilder().table { header { label("key") label("value") } System.properties.each { k,v -> row { label(k).style(Color.red.fg()); label(v).style(Color.blue.fg()) } } }
Building more complex UI with a DSL