CRaSH is the open source shell for the JVM. The shell can be accessed by various ways, remotely using network protocols such as SSH, locally by attaching a shell to a running virtual machine or via a web interface. Commands are written Groovy and can be developed live making the extensibility of the shell easy with quick development cycles. Since the version 1.3, the REPL also speaks the Groovy language, allowing Groovy combination of command using pipes.
CRaSH comes with commands such as thread management, log management, database access and JMX. The session will begin with an introduction to the shell. The main part of the session will focus on showing CRaSH commands development with few examples, showing how easy and powerful the development is.
The audience will learn how to use CRaSH for their own needs: it can be a simple usage or more advanced like developing a command or embedding the shell in their own runtime like a web application or a Grails application.
10 Trends Likely to Shape Enterprise Technology in 2024
CRaSH the shell for the Java Virtual Machine
1. 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
2. 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
3. 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
4. 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
5. 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
6. 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
7. 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
9. w w w . c r a s h u b . o r g
Return "hello world"
Command script
10. w w w . c r a s h u b . o r g
class helloworld {
@Command
String main() {
return "Hello World"
}
}
Command class
11. w w w . c r a s h u b . o r g
class hello {
@Command
String world() {
return "Hello World"
}
}
Git style
12. w w w . c r a s h u b . o r g
Command pipelining
13. 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
14. w w w . c r a s h u b . o r g
% thread ls | thread dump | mail -s
"something you should look at"
julien@julienviet.com
Pipeline example
15. 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
16. 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
17. 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
18. w w w . c r a s h u b . o r g
Read Eval Print Loop aka REPL
19. 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
20. 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
21. w w w . c r a s h u b . o r g
% (thread.ls | thread.dump | mail {
S="something you should look at”
"admin@domain.com"
})()
Our command pipeline in Groovy
26. 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
28. 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
29. w w w . c r a s h u b . o r g
And the story just begins
30. 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
crash-users@googlegroups.com
Wrap up
32. 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