@@ -15,10 +15,13 @@ case class RemoteFile(name: String, owner: String, permissions: String, modDate:
15
15
16
16
case class UnknownResponse (er : ExecuteResponse ) extends Exception
17
17
18
+
18
19
/**
19
20
* Provides a framework for interacting (running commands, uploading/downloading files, etc) with a generic remote machine.
20
21
*/
21
22
abstract class RemoteMachine {
23
+ self =>
24
+
22
25
/**
23
26
* The hostname that the ssh connection is established with
24
27
*/
@@ -69,6 +72,8 @@ abstract class RemoteMachine {
69
72
val logger = Logger ()
70
73
private var connection : Connection = null
71
74
75
+ implicit def toOption [A ](a : A ) = Option (a)
76
+
72
77
/**
73
78
* Provide an ssh connection to the server. If one is not already available or has been disconnected, create one.
74
79
*/
@@ -379,5 +384,21 @@ abstract class RemoteMachine {
379
384
}
380
385
}
381
386
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
+
382
403
override def toString (): String = " <RemoteMachine " + username + " @" + hostname + " >"
383
404
}
0 commit comments