Skip to content

Commit 6d68c34

Browse files
committed
java debugging code for remote nodes.
1 parent 4124380 commit 6d68c34

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/scala/RemoteMachine.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ case class RemoteFile(name: String, owner: String, permissions: String, modDate:
1515

1616
case class UnknownResponse(er: ExecuteResponse) extends Exception
1717

18+
1819
/**
1920
* Provides a framework for interacting (running commands, uploading/downloading files, etc) with a generic remote machine.
2021
*/
2122
abstract class RemoteMachine {
23+
self =>
24+
2225
/**
2326
* The hostname that the ssh connection is established with
2427
*/
@@ -69,6 +72,8 @@ abstract class RemoteMachine {
6972
val logger = Logger()
7073
private var connection: Connection = null
7174

75+
implicit def toOption[A](a: A) = Option(a)
76+
7277
/**
7378
* Provide an ssh connection to the server. If one is not already available or has been disconnected, create one.
7479
*/
@@ -379,5 +384,21 @@ abstract class RemoteMachine {
379384
}
380385
}
381386

387+
case class RemoteJavaProcess(pid: Int, main: String) {
388+
def stack = self !? ("jstack " + pid)
389+
}
390+
391+
def jps: Seq[RemoteJavaProcess] = {
392+
val javaProcessRegEx = """(\d+) (\S+)""".r
393+
executeCommand("jps") match {
394+
case ExecuteResponse(Some(0), out, "") => {
395+
out.split("\n").map {
396+
case javaProcessRegEx(pid, main) => new RemoteJavaProcess(pid.toInt, main)
397+
}
398+
}
399+
case er => throw new UnknownResponse(er)
400+
}
401+
}
402+
382403
override def toString(): String = "<RemoteMachine " + username + "@" + hostname + ">"
383404
}

0 commit comments

Comments
 (0)