本文整理汇总了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
}
}
开发者ID:wenkeyang,项目名称:finagle,代码行数:59,代码来源:IntegrationClient.scala
注:本文中的java.net.BindException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论