CRaSH the shell for the Java Virtual Machine

32
www. crashub .org CRaSH The shell for the JVM www. crashub .org Julien Viet exoplatform

description

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.

Transcript of CRaSH the shell for the Java Virtual Machine

Page 1: 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

Page 2: CRaSH the shell for the Java Virtual Machine

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

Page 3: CRaSH the shell for the Java Virtual Machine

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

Page 4: CRaSH the shell for the Java Virtual Machine

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

Page 5: CRaSH the shell for the Java Virtual Machine

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

Page 6: CRaSH the shell for the Java Virtual Machine

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

Page 7: CRaSH the shell for the Java Virtual Machine

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

Page 8: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Standalone mode

Page 9: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Return "hello world"

Command script

Page 10: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

class helloworld { @Command String main() { return "Hello World" } }

Command class

Page 11: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

class hello { @Command String world() { return "Hello World" } }

Git style

Page 12: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Command pipelining

Page 13: CRaSH the shell for the Java Virtual Machine

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

Page 14: CRaSH the shell for the Java Virtual Machine

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

Page 15: CRaSH the shell for the Java Virtual Machine

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

Page 16: CRaSH the shell for the Java Virtual Machine

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

Page 17: CRaSH the shell for the Java Virtual Machine

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

Page 18: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Read Eval Print Loop aka REPL

Page 19: CRaSH the shell for the Java Virtual Machine

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

Page 20: CRaSH the shell for the Java Virtual Machine

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

Page 21: CRaSH the shell for the Java Virtual Machine

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

Page 22: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

More cool stuff

Page 23: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Completers

Renderers

Keyboard: interruption / events

Screen: streaming / styling

More cool stuff

Page 24: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Attach mode

Page 25: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Embedding CRaSH

Page 26: CRaSH the shell for the Java Virtual Machine

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

Page 27: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Ecosystem

Page 28: CRaSH the shell for the Java Virtual Machine

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

Page 29: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

And the story just begins

Page 30: CRaSH the shell for the Java Virtual Machine

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

Page 31: CRaSH the shell for the Java Virtual Machine

w w w . c r a s h u b . o r g

Extra slides

Page 32: CRaSH the shell for the Java Virtual Machine

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