本文整理汇总了Scala中java.net.ConnectException类的典型用法代码示例。如果您正苦于以下问题:Scala ConnectException类的具体用法?Scala ConnectException怎么用?Scala ConnectException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConnectException类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: RemoteServer
//设置package包名称以及导入依赖的类
package org.argus.jc.incremental.jawa
package remote
import java.net.{ConnectException, InetAddress, UnknownHostException}
import org.argus.jc.incremental.jawa.data.{CompilationData, CompilerData}
import org.jetbrains.jps.incremental.ModuleLevelBuilder.ExitCode
class RemoteServer(val address: InetAddress, val port: Int) extends Server with RemoteResourceOwner {
def compile(compilerData: CompilerData, compilationData: CompilationData, client: Client): ExitCode = {
val arguments = Arguments(compilerData, compilationData).asStrings
try {
send(serverAlias, arguments, client)
ExitCode.OK
} catch {
case e: ConnectException =>
val firstLine = s"Cannot connect to compile server at ${address.toString}:$port"
val secondLine = "Trying to compile without it"
val message = s"$firstLine\n$secondLine"
client.warning(message)
client.debug(s"$firstLine\n${e.toString}\n${e.getStackTrace.mkString("\n")}")
JawaBuilder.localServer.compile(compilerData, compilationData, client)
case e: UnknownHostException =>
val message = "Unknown IP address of compile server host: " + address.toString
client.error(message)
client.debug(s"$message\n${e.toString}\n${e.getStackTrace.mkString("\n")}")
ExitCode.ABORT
}
}
}
开发者ID:arguslab,项目名称:argus-cit-intellij,代码行数:33,代码来源:RemoteServer.scala
示例2: NotFoundException
//设置package包名称以及导入依赖的类
package info.armado.ausleihe.client.connection.exceptions
import javax.ws.rs.ProcessingException
import java.net.URI
import java.net.ConnectException
import info.armado.ausleihe.client.model.ConnectionProperties
import info.armado.ausleihe.client.model.Configuration
case class NotFoundException(val serverAddress: URI) extends Exception
case class BadRequestException(val serverAddress: URI) extends Exception
case class InternalServerErrorException(val serverAddress: URI) extends Exception
case class UnhandledStatusCodeException(val serverAddress: URI, val statusCode: Int) extends Exception
object ServerUnreachableException {
def unapply(connectException: ConnectException): Option[URI] = Some(new URI(Configuration.connectionProperties.baseURL))
}
object ProcessingExceptionWrapper {
def unapply(processException: ProcessingException): Option[Throwable] = Option(processException.getCause)
}
开发者ID:Spielekreis-Darmstadt,项目名称:lending,代码行数:21,代码来源:ClientExceptions.scala
示例3: MemcachedProxy
//设置package包名称以及导入依赖的类
package com.twitter.finagle.example.memcachedproxy
import com.twitter.finagle.memcached.protocol.text.Memcached
import com.twitter.finagle.memcached.protocol.{Command, Response}
import com.twitter.finagle.Service
import com.twitter.finagle.builder.{Server, ClientBuilder, ServerBuilder}
import java.net.{ConnectException, Socket, InetSocketAddress}
object MemcachedProxy {
def main(args: Array[String]) {
assertMemcachedRunning()
val client: Service[Command, Response] = ClientBuilder()
.codec(Memcached())
.hosts(new InetSocketAddress(11211))
.hostConnectionLimit(1)
.build()
val proxyService = new Service[Command, Response] {
def apply(request: Command) = client(request)
}
val server: Server = ServerBuilder()
.codec(Memcached())
.bindTo(new InetSocketAddress(8080))
.name("memcachedproxy")
.build(proxyService)
}
private[this] def assertMemcachedRunning() {
try {
new Socket("localhost", 11211)
} catch {
case e: ConnectException =>
println("Error: memcached must be running on port 11211")
System.exit(1)
}
}
}
开发者ID:wenkeyang,项目名称:finagle,代码行数:42,代码来源:MemcachedProxy.scala
示例4: CheckConnection
//设置package包名称以及导入依赖的类
package com.stulsoft.pkafka.scala
import java.net.{ConnectException, HttpURLConnection, SocketException, URL}
import org.slf4j.Logger
import org.slf4j.LoggerFactory
object CheckConnection {
val logger: Logger = LoggerFactory.getLogger(CheckConnection.getClass)
def checkConnection(): Boolean = {
var available: Boolean = false
val urlString: String = "http://localhost:9092"
try {
val url: URL = new URL(urlString)
val con: HttpURLConnection = url.openConnection.asInstanceOf[HttpURLConnection]
con.setRequestMethod("GET")
val responseCode: Int = con.getResponseCode
logger.debug("responseCode={}", responseCode)
}
catch {
case e: ConnectException => logger.error("No connection with Kafka server. Error: {}", e.getMessage)
case e: SocketException =>
logger.info("Kafka server is available. {}", e.getMessage)
available = true
case e: Exception => logger.error("Failure", e)
}
available
}
def main(args: Array[String]): Unit = {
logger.debug("==>CheckConnection")
logger.debug("Is Kafka server available: {}", checkConnection())
logger.debug("<==CheckConnection")
}
}
开发者ID:ysden123,项目名称:poc,代码行数:39,代码来源:CheckConnection.scala
示例5: Util
//设置package包名称以及导入依赖的类
package org.pgscala.embedded
import java.net.{ConnectException, Socket}
import java.security.MessageDigest
import java.util.Locale
import javax.xml.bind.DatatypeConverter
import com.typesafe.scalalogging.StrictLogging
object Util extends StrictLogging {
def bin2Hex(binary: Array[Byte]): String =
DatatypeConverter.printHexBinary(binary).toLowerCase(Locale.ROOT)
def digest(text: String): Array[Byte] = {
val md = MessageDigest.getInstance("SHA-256")
md.digest(text.getBytes("UTF-8"))
}
lazy val isWindows: Boolean = OS.Name.resolved match {
case Some(OS.Name.Windows) => true
case _ => false
}
lazy val isUnix: Boolean = OS.Name.resolved match {
case Some(OS.Name.Linux) | Some(OS.Name.OSX) => true
case _ => false
}
private[this] def socketIsFree(host: String, port: Int): Boolean =
try {
logger.trace(s"Checking if port $port is free...")
new Socket(host, port).close()
logger.debug(s"Port $port is free, choosing it for the cluster")
false
} catch {
case _: ConnectException =>
true
}
def findFreePort(host: String, portRange: Range): Int =
portRange.find(port => socketIsFree(host, port))
.getOrElse(sys.error(s"Could not find free port in range: [${portRange.head},${portRange.last}]"))
}
开发者ID:oradian,项目名称:pgscala-embedded,代码行数:44,代码来源:Util.scala
示例6: ConnectionErrorHandler
//设置package包名称以及导入依赖的类
package auth.http.util
import java.net.ConnectException
import com.google.inject.{Inject, Provider}
import play.api._
import play.api.http.{DefaultHttpErrorHandler, HttpErrorHandler}
import play.api.mvc.RequestHeader
import play.api.mvc._
import play.api.mvc.Results._
import play.api.routing.Router
import scala.concurrent.Future
class ConnectionErrorHandler @Inject()(env: Environment,
config: Configuration,
sourceMapper: OptionalSourceMapper,
router: Provider[Router])
extends DefaultHttpErrorHandler(env, config, sourceMapper, router) {
private val logger = Logger(this.getClass)
override def onServerError(request: RequestHeader, exception: Throwable): Future[Result] =
exception match {
case e: ConnectException ?
logger.error(
s"Connection failed for $request, transferring to ServiceUnavailable result", e)
Future.successful(ServiceUnavailable(exception.getMessage))
case e: Throwable ? super.onServerError(request, exception)
}
}
开发者ID:KadekM,项目名称:play-slick-silhouette-auth-api,代码行数:33,代码来源:ConnectionErrorHandler.scala
示例7: RemoraApp
//设置package包名称以及导入依赖的类
import java.io.IOException
import java.net.ConnectException
import java.util.concurrent.TimeoutException
import akka.actor.ActorSystem
import akka.stream.{ActorMaterializer, ActorMaterializerSettings, Supervision}
import com.codahale.metrics.jvm.{ThreadStatesGaugeSet, MemoryUsageGaugeSet, GarbageCollectorMetricSet}
import scala.util.control.NonFatal
object RemoraApp extends App with nl.grons.metrics.scala.DefaultInstrumented {
private val actorSystemName: String = "remora"
implicit val actorSystem = ActorSystem(actorSystemName)
metricRegistry.registerAll(new GarbageCollectorMetricSet)
metricRegistry.registerAll(new MemoryUsageGaugeSet)
metricRegistry.registerAll(new ThreadStatesGaugeSet)
lazy val decider: Supervision.Decider = {
case _: IOException | _: ConnectException | _: TimeoutException => Supervision.Restart
case NonFatal(err: Throwable) =>
actorSystem.log.error(err, "Unhandled Exception in Stream: {}", err.getMessage)
Supervision.Stop
}
implicit val materializer = ActorMaterializer(
ActorMaterializerSettings(actorSystem).withSupervisionStrategy(decider))(actorSystem)
implicit val executionContext = actorSystem.dispatchers.lookup("kafka-consumer-dispatcher")
val kafkaSettings = KafkaSettings(actorSystem.settings.config)
val consumer = new RemoraKafkaConsumerGroupService(kafkaSettings)
val kafkaClientActor = actorSystem.actorOf(KafkaClientActor.props(consumer), name = "kafka-client-actor")
Api(kafkaClientActor).start()
}
开发者ID:zalando-incubator,项目名称:remora,代码行数:38,代码来源:RemoraApp.scala
注:本文中的java.net.ConnectException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论