Created
August 28, 2011 13:22
-
-
Save chrislewis/1176662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Real details omitted. */ | |
val ssh = Ssh(Host("localhost"), UsernameAndPassword("xx", "xx"), Some("/xx/.ssh/known_hosts")) | |
/* Replicate some block as a set of Callable[A]s */ | |
object Callable { | |
def replicate[A](count: Int)(block: => A) = | |
(1 to count).map(_ => new java.util.concurrent.Callable[A] { | |
def call() = block | |
}) | |
} | |
import Callable.replicate | |
/* Nasty, but these will do. */ | |
import scala.collection.JavaConversions._ | |
def grepFoo = ssh("foo" |: "grep foo" :| identity) | |
def grepBaz = ssh("foo\nbar\nbaz" |: "grep bar" :| identity) | |
def echo = ssh("echo \"hello\" $RANDOM" :| identity) | |
/* After this line we'll have 9 callables using the same ssh instance. */ | |
val sessionTasks = replicate(3)(grepFoo) ++ replicate(3)(grepBaz) ++ replicate(3)(echo) | |
val pool = java.util.concurrent.Executors.newFixedThreadPool(20) | |
pool.invokeAll(sessionTasks) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment