本文整理汇总了Scala中java.net.BindException类的典型用法代码示例。如果您正苦于以下问题:Scala BindException类的具体用法?Scala BindException怎么用?Scala BindException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BindException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: configureClient
//设置package包名称以及导入依赖的类
package com.twitter.finagle.mysql.integration
import com.twitter.finagle.Mysql
import com.twitter.finagle.mysql._
import com.twitter.util.NonFatal
import java.io.{File, FileInputStream}
import java.net.{ServerSocket, BindException}
import java.util.logging.{Level, Logger}
import java.util.Properties
trait IntegrationClient {
private val logger = Logger.getLogger("integration-client")
// Check if default mysql port is available.
val isPortAvailable = try {
val socket = new ServerSocket(3306)
socket.close()
true
} catch {
case e: BindException => false
}
val propFile = new File(System.getProperty("user.home") +
"/.finagle-mysql/integration-test.properties")
val p = new Properties
val propFileExists = try {
val fis = new FileInputStream(propFile)
p.load(fis)
fis.close()
true
} catch {
case NonFatal(e) =>
logger.log(Level.WARNING, "Error loading integration.properties, skipping integration test")
false
}
// It's likely that we can run this test
// if a mysql instance is running and a valid
// properties file is found which contains
// mysql credentials.
val isAvailable = !isPortAvailable && propFileExists
protected def configureClient(username: String, password: String, db: String) = Mysql.client
.withCredentials(username, password)
.withDatabase(db)
val client: Option[Client with Cursors] = if (isAvailable) {
logger.log(Level.INFO, "Attempting to connect to mysqld @ localhost:3306")
val username = p.getProperty("username", "<user>")
val password = p.getProperty("password", null)
val db = p.getProperty("db", "test")
Some(configureClient(username, password, db)
.newRichClient("localhost:3306"))
} else {
None
}
}