Initial commit of mishell. Mishell is a scripting environment and console for remote jmx management.
See README.txt for details.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@441834 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/mishell/src/main/resources/manifest.mf b/mishell/src/main/resources/manifest.mf
new file mode 100644
index 0000000..a2da53e
--- /dev/null
+++ b/mishell/src/main/resources/manifest.mf
@@ -0,0 +1 @@
+Main-Class: org.apache.felix.mishell.Main
\ No newline at end of file
diff --git a/mishell/src/main/resources/scripts/hello.js b/mishell/src/main/resources/scripts/hello.js
new file mode 100644
index 0000000..baef51f
--- /dev/null
+++ b/mishell/src/main/resources/scripts/hello.js
@@ -0,0 +1,6 @@
+/*
+ * This is sample JavaScript file that can be loaded into script console.
+ * This file prints "hello, world".
+ */
+
+echo("hello, world");
diff --git a/mishell/src/main/resources/scripts/invoke.js b/mishell/src/main/resources/scripts/invoke.js
new file mode 100644
index 0000000..20823a1
--- /dev/null
+++ b/mishell/src/main/resources/scripts/invoke.js
@@ -0,0 +1,18 @@
+/*
+ * This script demonstrates "invokeMBean" function. Instead
+ * of using MXBean proxy or script wrapper object returned by
+ * 'mbean' function, this file uses direct invoke on MBean.
+ *
+ * To use this particular script, load this script file in
+ * script console prompt and call resetPeakThreadCount().
+
+ */
+
+/**
+ * Resets the peak thread count to the current number of live threads.
+ *
+ */
+function resetPeakThreadCount() {
+ return invokeMBean("java.lang:type=Threading", "resetPeakThreadCount", [], "");
+}
+
diff --git a/mishell/src/main/resources/scripts/jtop.js b/mishell/src/main/resources/scripts/jtop.js
new file mode 100644
index 0000000..23e7531
--- /dev/null
+++ b/mishell/src/main/resources/scripts/jtop.js
@@ -0,0 +1,73 @@
+/*
+ * This code is "ported" from JTop demo. This file defines
+ * 'jtop' function. jtop prints threads sorting by CPU time.
+ * jtop can be called once or periodically from a timer thread.
+ * To call this once, just call 'jtop()' in script console prompt.
+ * To call jtop in a timer thread, you can use
+ *
+ * var t = setTimeout(function () { jtop(print); }, 2000);
+ *
+ * The above call prints threads in sorted order for every 2 seconds.
+ * The print output goes to OS console window from which jconsole was
+ * started. The timer can be cancelled later by clearTimeout() function
+ * as shown below:
+ *
+ * clearTimeout(t);
+ */
+
+/**
+ * This function returns a List of Map.Entry objects
+ * in which each entry maps cpu time to ThreadInfo.
+ */
+function getThreadList() {
+ var tmbean = newPlatformMXBeanProxy(
+ "java.lang:type=Threading",
+ java.lang.management.ThreadMXBean);
+
+ if (!tmbean.isThreadCpuTimeSupported()) {
+ return;
+ }
+
+ tmbean.setThreadCpuTimeEnabled(true);
+
+ var tids = tmbean.allThreadIds;
+ var tinfos = tmbean["getThreadInfo(long[])"](tids);
+
+ var map = new java.util.TreeMap();
+ for (var i in tids) {
+ var cpuTime = tmbean.getThreadCpuTime(tids[i]);
+ if (cpuTime != -1 && tinfos[i] != null) {
+ map.put(cpuTime, tinfos[i]);
+ }
+ }
+ var list = new java.util.ArrayList(map.entrySet());
+ java.util.Collections.reverse(list);
+ return list;
+}
+
+/**
+ * This function prints threads sorted by CPU time.
+ *
+ * @param printFunc function called back to print [optional]
+ *
+ * By default, it uses 'echo' function to print in screen.
+ * Other choices could be 'print' (prints in console), 'alert'
+ * to show message box. Or you can define a function that writes
+ * the output to a text file.
+ */
+function jtop(printFunc) {
+ if (printFunc == undefined) {
+ printFunc = echo;
+ }
+ var list = getThreadList();
+ var itr = list.iterator();
+ printFunc("time - state - name");
+ while (itr.hasNext()) {
+ var entry = itr.next();
+ // time is in nanoseconds - convert to seconds
+ var time = entry.key / 1.0e9;
+ var name = entry.value.threadName;
+ var state = entry.value.threadState;
+ printFunc(time + " - " + state + " - " + name);
+ }
+}
diff --git a/mishell/src/main/resources/scripts/verbose.js b/mishell/src/main/resources/scripts/verbose.js
new file mode 100644
index 0000000..dac17f8
--- /dev/null
+++ b/mishell/src/main/resources/scripts/verbose.js
@@ -0,0 +1,49 @@
+/*
+ * This script demonstrates "getMBeanAttribute"
+ * and "setMBeanAttribute" functions. Instead of using
+ * MXBean proxy or script wrapper object returned by
+ * 'mbean' function, this file uses direct get/set MBean
+ * attribute functions.
+ *
+ * To use this particular script, load this script file in
+ * script console prompt and call verboseGC or verboseClass
+ * functions. These functions based on events such as
+ * heap threshold crossing a given limit. i.e., A timer thread
+ * can keep checking for threshold event and then turn on
+ * verbose:gc or verbose:class based on expected event.
+
+ */
+
+/**
+ * Get or set verbose GC flag.
+ *
+ * @param flag verbose mode flag [optional]
+ *
+ * If flag is not passed verboseGC returns current
+ * flag value.
+ */
+function verboseGC(flag) {
+ if (flag == undefined) {
+ // no argument passed. interpret this as 'get'
+ return getMBeanAttribute("java.lang:type=Memory", "Verbose");
+ } else {
+ return setMBeanAttribute("java.lang:type=Memory", "Verbose", flag);
+ }
+}
+
+/**
+ * Get or set verbose class flag.
+ *
+ * @param flag verbose mode flag [optional]
+ *
+ * If flag is not passed verboseClass returns current
+ * flag value.
+ */
+function verboseClass(flag) {
+ if (flag == undefined) {
+ // no argument passed. interpret this as 'get'
+ return getMBeanAttribute("java.lang:type=ClassLoading", "Verbose");
+ } else {
+ return setMBeanAttribute("java.lang:type=ClassLoading", "Verbose", flag);
+ }
+}