Last active
December 20, 2015 02:38
-
-
Save dacr/6057315 to your computer and use it in GitHub Desktop.
Check if a remote HTTP server is accessible or not (DNS resolution test only is not enough)
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
import scala.concurrent._ | |
import ExecutionContext.Implicits.global | |
val f = future { new java.net.URL("http://mvnrepository.com/artifact/com.jcraft/jsch").openConnection() } | |
.map { cnx => | |
cnx.setConnectTimeout(5000) | |
cnx.setReadTimeout(5000) | |
cnx.setAllowUserInteraction(false) | |
cnx.setUseCaches(false) | |
cnx } | |
.map { _.getInputStream } | |
.map { io.Source.fromInputStream(_) } | |
.collect { case x => println("then download latest release") } | |
.recover { case _ => println("then only use local backup") } | |
//Await.ready(f, duration.Duration.Inf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment