本文整理汇总了Scala中java.net.SocketTimeoutException类的典型用法代码示例。如果您正苦于以下问题:Scala SocketTimeoutException类的具体用法?Scala SocketTimeoutException怎么用?Scala SocketTimeoutException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SocketTimeoutException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: StdHttpExceptionHandler
//设置package包名称以及导入依赖的类
package handlers
import java.net.SocketTimeoutException
import com.google.inject.{Inject, Singleton}
import org.apache.http.{ConnectionClosedException, ExceptionLogger}
import org.slf4j.Logger
@Singleton
class StdHttpExceptionHandler @Inject()(logger: Logger) extends ExceptionLogger {
@Override
def log(ex :Exception): Unit = {
ex match {
case timeOutException: SocketTimeoutException => logger.error("Socket connection has timed out!")
case connectionClosedException: ConnectionClosedException => logger.error("Lost connection with base!")
case exception: Exception => logger.warn(exception.getMessage)
}
}
}
示例2: ShutdownServer
//设置package包名称以及导入依赖的类
package com.github.pheymann.mockit.network
import java.io.ObjectOutputStream
import java.net.{SocketTimeoutException, ServerSocket}
import com.github.pheymann.mockit.core.core._
import com.github.pheymann.mockit.core._
import com.github.pheymann.mockit.logging.Logger
class ShutdownServer(
val shutdown: ShutdownLatch
) extends Runnable
with Logger {
val server = new ServerSocket(MOCKIT_SD_PORT)
override def run(): Unit = {
server.setSoTimeout(SERVER_TIMEOUT)
this > s"[email protected]$MOCKIT_SD_PORT"
do {
try {
this >> "waiting for clients"
val client = server.accept
val outStream = new ObjectOutputStream(client.getOutputStream)
this >> "send 'keep alive' message"
outStream.writeBoolean(true)
outStream.flush()
client.close()
}
catch {
case e: SocketTimeoutException => this >> "server listening interruption occurred"
case e: Throwable => this error (null, e)
}
} while (shutdown.continue)
this > stop
server.close()
}
}
示例3: LogServer
//设置package包名称以及导入依赖的类
package com.github.pheymann.mockit.network
import java.io.ObjectInputStream
import java.net.{SocketTimeoutException, ServerSocket}
import scala.collection.mutable.ListBuffer
import com.github.pheymann.mockit.core.core._
import com.github.pheymann.mockit.logging.{Logger, LogEntry}
class LogServer(
val logs: ListBuffer[LogEntry],
val agentNumber: Int
) extends Runnable
with Logger {
val logServer = new ServerSocket(MOCKIT_LOG_PORT)
override def run(): Unit = {
var counter = 0
logServer.setSoTimeout(SERVER_TIMEOUT)
this > s"[email protected]$MOCKIT_LOG_PORT"
do {
try {
this >> "waiting for client"
val client = logServer.accept
val address = client.getInetAddress.getHostAddress
val logStream = new ObjectInputStream(client.getInputStream)
val size = logStream.readInt
this >> s"[$address]: collect all $size log entries"
for (i <- 0 until size)
logs += logStream.readObject.asInstanceOf[LogEntry]
client.close()
counter += 1
}
catch {
case e: SocketTimeoutException => this >> "server listening interruption occurred"
case e: Throwable => this error ("disregard of log protocol", e)
}
} while (counter < agentNumber)
this > stop
logServer.close()
}
}
示例4: MockItDaemonDummy
//设置package包名称以及导入依赖的类
package com.github.pheymann.mockit.util
import java.net.SocketTimeoutException
import com.github.pheymann.mockit.core.{UploadServerDownException, MockFactory}
import com.github.pheymann.mockit.core.{UploadServerDownException, MockFactory}
import com.github.pheymann.mockit.logging.Logger
import com.github.pheymann.mockit.network.ServerListener
class MockItDaemonDummy(
val repetitions: Int
) extends Runnable
with Logger {
override def run(): Unit = {
for (i <- 0 until repetitions) {
try {
val listener = new ServerListener
val address = listener.waitForInvitation
val (config, mockClass) = listener.load(address)
MockFactory.networkClient(config, mockClass)
}
catch {
case e @ (_: SocketTimeoutException | _: UploadServerDownException) =>
case e: Throwable => this error ("exception during MockIt test run", e)
}
}
}
}
示例5: main
//设置package包名称以及导入依赖的类
package com.github.pheymann.mockitdaemon
import java.io.ObjectInputStream
import java.net.{ServerSocket, SocketTimeoutException}
import com.github.pheymann.mockit.core._
import com.github.pheymann.mockit.core.core._
import com.github.pheymann.mockit.logging.Logger
import com.github.pheymann.mockit.network.ServerListener
def main(args: Array[String]): Unit = {
val log = new Logger {override lazy val name = "MockItDaemon"}
var continue = true
var daemon: Thread = null
val id = args(0).toInt
val server = new ServerSocket(MOCKIT_PORT + id)
server.setSoTimeout(SERVER_TIMEOUT)
log > s"start MockIt test client := $id"
do {
daemon = new Thread {
override def run(): Unit = action(log)
}
daemon.start()
try {
val client = server.accept
val inStream = new ObjectInputStream(client.getInputStream)
inStream.readObject match {
case ShutdownDaemon() => continue = false
case _ =>
}
client.getOutputStream.write(0)
client.getOutputStream.flush()
client.close()
if (!continue)
server.close()
}
catch {
case e: SocketTimeoutException =>
case e: Throwable => throw e
}
daemon.join()
} while (continue)
log > s"stop MockIt test client := $id"
}
}